Page 1 of 1

Creating Table in SQL database

Posted: Sat Mar 30, 2013 7:16 pm
by William Jamieson
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?

Re: Creating Table in SQL database

Posted: Sat Mar 30, 2013 7:38 pm
by Thierry
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

Re: Creating Table in SQL database

Posted: Sat Mar 30, 2013 8:24 pm
by William Jamieson
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!

Re: Creating Table in SQL database

Posted: Sat Mar 30, 2013 10:13 pm
by William Jamieson
Ok nevermind, I figured it out. Thank you!