Page 1 of 1

Create Table in SQLite

Posted: Wed Jul 23, 2014 10:49 pm
by sandyb
I'm trying this again after many strikeouts, by using the code in the SQLite Sampler. The code for open database and for close database works fine. but the code for create table always throws an error, even with slight changes in (s and )s and ,s. Always the same error on the same line. Appreciate any help. Here is code and error:

Code: Select all

local tSQL
local tTmp
on  mouseUp
   global gConID
   if  gConID = "" then
      answer information "No Database Connected"
      exit mouseUp
   end if
   put "CREATE TABLE places (placeID integer primary key, company text, address text)" into tSQL
   answer tSQL
   put revExecuteSQL gConID tSQL, tTmp *****error line*****

   handleRevDBerror tTmp
   if the result is not empty then
      answer warning the result
      exit mouseUp
   end if
   answer information "No of Tables Added: " & tTmp
end  mouseUp
error line:
button "Create Places Table":execution error at line 11 (Handler: can't find handler) near "gConID", char 8
That sounds to me like it can't find the rev function ExecuteSQL, but how could that be? Thanks in advance for any help.

Re: Create Table in SQLite

Posted: Wed Jul 23, 2014 10:53 pm
by FourthWorld
Functions differ from commands in that all arguments to functions must be enclosed within parentheses, e.g.:

put revExecuteSQL( gConID tSQL, tTmp )

Re: Create Table in SQLite

Posted: Thu Jul 24, 2014 2:50 am
by sandyb
Thanks. I tried that but it didn't work either. Here's the pertinent part of the code:

put "CREATE TABLE places (placeID integer primary key, company text, address text)" into tSQL
answer gConID
answer tSQL
revExecuteSQL(gConID, tSQL)
//put revExecuteSQL( gConID, tSQL) into tTmp

The two answer lines display the correct connection # and sql line.
In the sql sampler the commented out line put the function result into local tTmp. That didn't work either.
The revExecuteSQL(gConID,tSQL) line should, I think, actually create the table. But it didn't work either.
Surely this isn't the way LiveCode is supposed to act? I can create the table in SQLStudio or Valentino Studio and then access it, etc. What am I missing in LiveCode to do that? Thanks for any help.

Re: Create Table in SQLite

Posted: Thu Jul 24, 2014 4:13 am
by FourthWorld
My bad: I was trusting your earlier code rather than looking in the Dictionary. Had I done the latter I'd remembered that revExecuteSQL is indeed a command and not a function.

So the parens aren't needed, and your first example failed because it was being called with the "put" command.

If you remove the parens from your last snippet you should be fine.

When in doubt, consult the Dictionary.