MySQL: Problem with writing to database

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
edljr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 56
Joined: Sun Oct 26, 2008 6:47 am
Contact:

MySQL: Problem with writing to database

Post by edljr » Sun Jul 05, 2009 10:24 pm

Hi all,

I have an application which is nearly complete except for one critical part -- saving data to the MySQL database. I have had great success in opening, reading, and closing the database. After scouring this forum, and trying many different iterations, I would now like to ask for help.

The line of code below works perfectly fine, but is not helpful:

Code: Select all

revExecuteSQL dbID, "INSERT INTO k1 VALUES(NULL, 'task', '0002', '222,333', 'Get a life dude')"
This next block of code does not work, nor does it give me an error:

Code: Select all

# Update Database Records
      repeat with x =1 to lastPostIt
         put empty into dbRecord
         put "INSERT INTO " & dbTable & " VALUES(:1,:2,:3,:4,:5)" into dbSQL
         put dbArray[x,1] into dbRecord[1]
         put dbArray[x,2] into dbRecord[2]
         put dbArray[x,3] into dbRecord[3]
         put dbArray[x,4] into dbRecord[4]
         put dbArray[x,5] into dbRecord[5]
         revExecuteSQL dbID, dbSQL, "dbRecord"
      end repeat
Notes on the code:
(1) "lastPostIt" is a global variable indicating how many objects there are (one record per object).
(2) dbTable is a global variable.
(3) dbArray is global and its contents are based on what was read from the db -- the contents are valid (tested).

Any help would be greatly appreciated. I am not sure if it matters, but I am using Rev Studio 3.5.0 (Build 860) and MySQL 5.0.67-community (on the iRev server.

Thanks much,
Ed

chris9610
Posts: 79
Joined: Fri Mar 20, 2009 4:38 pm

Post by chris9610 » Mon Jul 06, 2009 2:28 am

You might try this:

Code: Select all

         put dbArray[x,1] into tcol1
         put dbArray[x,2] into tcol2
         put dbArray[x,3] into tcol3
         put dbArray[x,4] into tcol4
         put dbArray[x,5] into tcol5
         revExecuteSQL (dbID, dbSQL, tcol1,tcol2,tcol3,tcol4,tcol5)
I was not aware you could use an array variable for the row data to insert.

But I am new to RunREv
Developing with Windows XP & Revolution 4.5

edljr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 56
Joined: Sun Oct 26, 2008 6:47 am
Contact:

MySQL: Problem with writing to database

Post by edljr » Mon Jul 06, 2009 2:47 am

Chris,

Thanks for the post. Unfortunately, that code does not work either. I previously tried with individual variables as well as the array. Both should work, I just do not know why they do not.

Since I am not getting a syntax error, I wonder if it has something to do with the data I am trying to pass. I played around with double/single quotes, but no combination worked. The only time I was able to write to the db using the revExecuteSQL statement was without using variables.

Code: Select all

revExecuteSQL dbID, "INSERT INTO k1 VALUES(NULL, 'task', '0002', '222,333', 'Get a life dude')"
If only I would have purchased Enterprise instead of Studio, I could have used one of the silver support incidents.

Ed

AndyP
Posts: 634
Joined: Wed Aug 27, 2008 12:57 pm
Contact:

Post by AndyP » Mon Jul 06, 2009 9:00 am

Andy .... LC CLASSIC ROCKS!

edljr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 56
Joined: Sun Oct 26, 2008 6:47 am
Contact:

MySQL: Problem with writing to database

Post by edljr » Mon Jul 06, 2009 4:51 pm

Andy,

Thanks for the link. My error was the lack of quotes around the array name.

Code: Select all

revExecuteSQL dbID, dbSQL, "dbData"
It is unbelievable how simple some errors are...the little ones cause the biggest headaches.

Thanks again,
Ed
:D = very happy

chris9610
Posts: 79
Joined: Fri Mar 20, 2009 4:38 pm

Post by chris9610 » Tue Jul 07, 2009 1:09 am

That is correct

This also works:

Code: Select all


         put dbArray[x,1] into tcol1
         put dbArray[x,2] into tcol2
         put dbArray[x,3] into tcol3
         put dbArray[x,4] into tcol4
         put dbArray[x,5] into tcol5
         revExecuteSQL "dbID", "dbSQL", "tcol1","tcol2","tcol3","tcol4","tcol5"

Life is good
Developing with Windows XP & Revolution 4.5

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Tue Jul 07, 2009 8:26 am

Hi edljr,

From your original post:

revExecuteSQL dbID, dbSQL, "dbRecord"

I see that the array name includes quotes. Are you sure that the quotes were the problem?

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

edljr
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 56
Joined: Sun Oct 26, 2008 6:47 am
Contact:

MySQL: Problem with writing to database

Post by edljr » Tue Jul 07, 2009 3:58 pm

Hi Mark,

I was trying so many different things, I guess I cannot be completely sure. Having not touched SQL for so many years, that could have been the source of my problem just as easily as Transcript syntax.

Thanks,
Ed

Post Reply