SQLite and Parameters

General questions that have to do with plugins go here

SQLite and Parameters

Postby GMKai » Wed May 02, 2018 11:00 pm

Hello,
I try to pass parameters, to a dynamic sql, here the failing short example.
What am I doing wrong?
Code: Select all
@VERSION 7,0
@REQUIRE "sqlite3"

db = sqlite3:open_memory()
Local res = db:exec([[
  CREATE TABLE db_stadionblock
  (clubid INTEGER Not NULL, blockid STRING(1) Not NULL, size INTEGER,cond INTEGER,state VARCHAR(40));
   ]])
DebugPrint(res)
Local str$="INSERT INTO db_stadionblock VALUES (22,'A',12000,100,'-');"
DebugPrint(str$)
res = db:exec(str$)
DebugPrint(res)
;should work, now the defective statement:
DebugPrint("ERROR coming:")
Local str$ = "UPDATE db_stadionblock SET cond = cond - ? where clubid = ? and state = '-';"
stmt = db:prepare(str$)
Local res = stmt:bind(3,22)
DebugPrint(res)
stmt:dostep()
stmt:finalize()           



Gives the following output:
Code: Select all
0
INSERT INTO db_stadionblock VALUES (22,'A',12000,100,'-');
0
ERROR coming:
Work:Cubic IDE/Unbenannt.hws:18: Bind index out of range [1..%ld]!
GMKai
 
Posts: 61
Joined: Mon Feb 15, 2010 11:58 am

Re: SQLite and Parameters

Postby airsoftsoftwair » Sun May 06, 2018 12:09 am

Lazi? :)
User avatar
airsoftsoftwair
 
Posts: 2444
Joined: Fri Feb 12, 2010 3:33 pm
Location: Germany


Return to General plugin questions

Who is online

Users browsing this forum: No registered users and 2 guests

cron