New topic: 

Can't update remote mySQL database?

<http://forums.realsoftware.com/viewtopic.php?t=35581>

         Page 1 of 1
   [ 5 posts ]                 Previous topic | Next topic          Author  
Message        dpaanlka          Post subject: Can't update remote mySQL 
database?Posted: Fri Sep 24, 2010 11:13 am                                 
Joined: Sun Mar 23, 2008 3:30 pm
Posts: 54                My apologies, this is my first database app in Real 
Studio and I'm trying to wrap my head around it. I have a project with a 
database named motoringimage that I setup using Real Studio's built-in tools to 
connect to a remote mySQL database. In my app I can retrieve information from 
the database just fine. The problems I'm experience involve writing to the 
database.

I've created a simple window with a text field named FieldTitle and a button 
with the following action code. ArticleID is a string property of the window 
that matches a field in the database.

Code:  dim theSQL as String
  
  theSQL = "SELECT Title FROM Articles WHERE ID = '" + ArticleID + "'"
  
  dim theRS As RecordSet = motoringimage.SQLSelect(theSQL)
  
  theRS.edit
  
  theRS.field("Title").StringValue = trim(FieldTitle.Text)
  
  theRS.Update
  
  motoringimage.Commit
  
  theRS.Close

I expected this to update that field to whatever the user types in the text 
field. When I click the button the app pauses momentarily and then continues 
on, without error, as if it did something. However when I check the database 
nothing has changed.

What am I doing wrong?   
                             Top                 elChupete          Post 
subject: Re: Can't update remote mySQL database?Posted: Fri Sep 24, 2010 11:36 
am                                 
Joined: Fri Jun 05, 2009 11:50 am
Posts: 158
Location: Hamburg, Germany                As always...

One need to do errorchecking when executing database transactions.

See the sticky thread on top of the database forum.

There are also many threads regarding errorchecking      
_________________
Best regards

Stefan

Mac OSX 10.6.4 / RB Professional 2010 Release 3.1  
                             Top                dpaanlka          Post subject: 
Re: Can't update remote mySQL database?Posted: Fri Sep 24, 2010 12:01 pm        
                         
Joined: Sun Mar 23, 2008 3:30 pm
Posts: 54                The database motoringimage does not return any errors 
after my commit statement. Also, if I call up some message boxes to display the 
contents of the Title field of theRS both before and after the Update command, 
they display the changes exactly as I would expect.

I can't conceive, in my limited knowledge perhaps, of how else to check for an 
error here?

Code with error-checks:

Code:  dim theSQL as String
  
  theSQL = "SELECT Title FROM Articles WHERE ID = '" + ArticleID + "'"
  
  dim theRS As RecordSet = motoringimage.SQLSelect(theSQL)
  
  MsgBox theRS.field("Title").StringValue
  
  theRS.edit
  
  theRS.field("Title").StringValue = trim(FieldTitle.Text)
  
  theRS.Update
  
  MsgBox theRS.field("Title").StringValue
  
  motoringimage.Commit
  
  If motoringimage.Error Then
  MsgBox motoringimage.Errormessage
  End If
  
  theRS.Close

Again, builds fine, runs without errors, and displays contents of the Title 
field as expected. Remote database remains unchanged when I check it outside 
the app.

EDIT: And remains unchanged even inside the app afterwards (like if I press 
this button again, the existing content of the Title field is the same as it 
was originally.   
                             Top                 timhare          Post subject: 
Re: Can't update remote mySQL database?Posted: Fri Sep 24, 2010 12:26 pm        
                 
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 8354
Location: Portland, OR  USA                You must check for errors 
immediately after Update. Commit clears the error thrown by Update.  You will 
probably find that you don't have enough data in your recordset to be able to 
update the database.  Namely, you must have the primary key value for the 
record for Update to be able to function.   
                             Top                dpaanlka          Post subject: 
Re: Can't update remote mySQL database?Posted: Fri Sep 24, 2010 12:30 pm        
                         
Joined: Sun Mar 23, 2008 3:30 pm
Posts: 54                Aha! Now at least I'm getting an error:

Quote:The RecordSet cannot be edited because the uniqueness of its rows cannot 
be verified.

What does that mean?   
                             Top            Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 5 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

rbforumnotifier@monkeybreadsoftware.de

Reply via email to