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?
Creating Table in SQL database
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- 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
Hi William,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?
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.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
-
- 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
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!
I believe if I could test it, then I could figure it out very simply.
Thank you for your reply Thierry!
-
- 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
Ok nevermind, I figured it out. Thank you!