Page 1 of 1

SQLite and Parameters

Posted: Wed May 02, 2018 11:00 pm
by GMKai
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]!

Re: SQLite and Parameters

Posted: Sun May 06, 2018 12:09 am
by airsoftsoftwair
Lazi? :)