Creating Table in SQL database

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
William Jamieson
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 212
Joined: Fri Feb 01, 2013 1:31 am
Location: Palo Alto, CA put williamdjamieso into tEmail / put n@gmail.com after tEmail/ revmail tEmail
Contact:

Creating Table in SQL database

Post by William Jamieson » Sat Mar 30, 2013 7:16 pm

So I have connected to my SQL database and the connection is confirmed by the answer script displaying: Connection ID = 6

Then I have a separate button to create the table (just for examination purposes) and this is the script I have

on mouseUp
global gConnectionID
if gConnectionID is not a number then
answer error "Please connect to the database first."
exit to top
end if
--the databaseCreateTable handler is on the card script
databaseCreateTable
end mouseUp

On the card:

on databaseCreateTable
## Add a contact_details table to the database
global gConnectionID
put gConnectionID into tDatabaseID
put "CREATE TABLE Table1 (firstName char(30), lastName char(30), birthDate INTEGER" into tSQL
revExecuteSQL tDatabaseID, tSQL
end databaseCreateTable

When I try to enter data into the table, it always replies an error with the reason being: Table alpha2.Table1 does not exist

I have already looked through the tutorials but there is nothing specific about adding a table to an SQL database. Just a general code of which I already followed and tweaked in many ways.

Is there a way that I can confirm that the table is created? Also, because it seems as though I have not done so already, how do I actually create the SQL table with Livecode?

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Creating Table in SQL database

Post by Thierry » Sat Mar 30, 2013 7:38 pm

William Jamieson wrote:So I have connected to my SQL database and the connection is confirmed by the answer script displaying: Connection ID = 6

Then I have a separate button to create the table (just for examination purposes) and this is the script I have

On the card:

on databaseCreateTable
## Add a contact_details table to the database
global gConnectionID
put gConnectionID into tDatabaseID
put "CREATE TABLE Table1 (firstName char(30), lastName char(30), birthDate INTEGER" into tSQL
revExecuteSQL tDatabaseID, tSQL
end databaseCreateTable

When I try to enter data into the table, it always replies an error with the reason being: Table alpha2.Table1 does not exist

Is there a way that I can confirm that the table is created? Also, because it seems as though I have not done so already, how do I actually create the SQL table with Livecode?
Hi William,

1st, why are you not testing "the result" after revExecuteSQL when creating the table?
It will tell you if the sql command was successful or not.

2nd: except if it is a typo in your message, the first '(' is not closed in the sql command!
Could be the culprit.


HTH,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

William Jamieson
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 212
Joined: Fri Feb 01, 2013 1:31 am
Location: Palo Alto, CA put williamdjamieso into tEmail / put n@gmail.com after tEmail/ revmail tEmail
Contact:

Re: Creating Table in SQL database

Post by William Jamieson » Sat Mar 30, 2013 8:24 pm

Yes, what would be the code to test whether the field was successfully created?

I believe if I could test it, then I could figure it out very simply.

Thank you for your reply Thierry!

William Jamieson
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 212
Joined: Fri Feb 01, 2013 1:31 am
Location: Palo Alto, CA put williamdjamieso into tEmail / put n@gmail.com after tEmail/ revmail tEmail
Contact:

Re: Creating Table in SQL database

Post by William Jamieson » Sat Mar 30, 2013 10:13 pm

Ok nevermind, I figured it out. Thank you!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”