Create Table in SQLite

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
sandyb
Posts: 2
Joined: Sat Oct 29, 2011 4:16 pm

Create Table in SQLite

Post by sandyb » Wed Jul 23, 2014 10:49 pm

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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10053
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Create Table in SQLite

Post by FourthWorld » Wed Jul 23, 2014 10:53 pm

Functions differ from commands in that all arguments to functions must be enclosed within parentheses, e.g.:

put revExecuteSQL( gConID tSQL, tTmp )
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

sandyb
Posts: 2
Joined: Sat Oct 29, 2011 4:16 pm

Re: Create Table in SQLite

Post by sandyb » Thu Jul 24, 2014 2:50 am

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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10053
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Create Table in SQLite

Post by FourthWorld » Thu Jul 24, 2014 4:13 am

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply