New topic: 

Recordset Update

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

       Page 1 of 1
   [ 4 posts ]                 Previous topic | Next topic         Author  
Message       Paul Burnside           Post subject: Recordset UpdatePosted: Sat 
Oct 24, 2009 6:44 pm                        
Joined: Mon May 08, 2006 8:50 pm
Posts: 508              Back in June I posted this problem and got conflicting 
answers. So, I did a workaround and moved on. Now, I'm on a new project and 
this little problem presented itself again. Seems to me there should be some 
definitive answer to the question.

I popuplate TextFields from a recordset. I use the following code example to 
UPDATE the recordset & database when changes are made to the TextFields.
Code:rs.edit
rs.idxField(x).stringvalue = TextField(x).text
rs.update
db.commit



After UPDATING the recordset/database I move to another record then back again 
to the record that had been changed. THE RECORDSET DIDN'T REFLECT THE CHANGES. 
If, however, I reload the recordset then the changes are present.

This shouldn't be the case and I'm concerned that there is some little secret 
I'm missing here. Seems to me that once the EDIT/UPDATE/COMMIT statements are 
used the changes to the recordset should persist.


Any ideas would be helpful.


Windows Vista using RB-9r4   
                            Top                timhare           Post subject: 
Re: Recordset UpdatePosted: Sat Oct 24, 2009 6:59 pm                        
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 6614
Location: Portland, OR  USA              RB's recordset is probably just a 
front for the dataset returned and managed by the DB.  It wouldn't make sense 
to duplicate that entire structure.  When you MoveTo a record, RB is requesting 
that record from the result set held by the DB.  The result set that the DB 
holds is static - it's a snapshot of the data from the database; it has to be 
so you don't get a dirty result set due to the data changing underneath you.

You won't see your updates until you refresh the result set in the DB - by 
issuing another SELECT statement.  I don't think there's much RB can do about 
that.

Tim   
                            Top               Paul Burnside           Post 
subject: Re: Recordset UpdatePosted: Sat Oct 24, 2009 7:13 pm                   
     
Joined: Mon May 08, 2006 8:50 pm
Posts: 508              Thanks Tim,

Your explanation is understandable. Reloading the recordset is, of course, the 
"workaround" I used last June. I guess that's what we're stuck with.

Thanks again   
                            Top                Phil M           Post subject: 
Re: Recordset UpdatePosted: Sat Oct 24, 2009 7:55 pm                        
Joined: Fri Sep 30, 2005 12:18 pm
Posts: 208              I don't know about SQLite, but in other databases you 
can LOCK a record to prevent editing... which means updates to that locked 
record will fail and the static record currently being viewed is still valid. 
Ah... was reading up a bit on SQLite and it seems it locks the entire database 
file and not individual records.

However, you could use a messaging system if the DB and your app is a closed 
system.  If any DB UPDATE or DELETE command is issued (also INSERT if you 
want), then you can send a message that a particular table has been modified.  
If your DB and App is local computer only, the your messaging system can just 
be a inner-app thing.  If you are making a network app with a shared DB between 
the clients, then just send a UDP message with the table name (and possibly 
record_ids).  To intercept updates to the table, you can Extend the Database 
class and add something like BuddySQLExecute, where it passes the message to 
SQLExecute and sends the message.  The details in the message will depend on 
how you write the function, or if you are willing to parse the SQL statement 
for table / record_id, or if you want to just send a global DB updated message 
without specifying what was modified.

Then your window registers itself with the messaging system saying that it 
would like to receive DB changes.  You do this by making a Class Interface 
called something like DBModificationReceiver, and defining a method such as 
DBModifiedHandler or ProcessChangeToDB.  Then you select the class interface 
when for your class or window when you are in the Project tab.  I HIGHLY 
recommend that you use WeakRefs to register the receivers mostly to prevent 
objects from going out of scope because a reference is still being held by your 
Passive messaging system.  Here is an example of a my register receivers code 
(as WeakRefs).
Code:Protected Sub RegisterAppLogReceiver(requestor As Object)
  //===============================================================
  '
  '  RegisterAppLogReceiver( ) will register any class that implements the 
AppLogReceiver
  '  class interface to receive log message updates when they are available.
  '
  '  Using WeakRef links to receivers so that AppLog does not prevent objects 
from being
  '  released.  At each message, all receivers are checked for Nil, and will be 
removed if the
  '  object pointed to by the WeakRef no longer exists.
  '
  //===============================================================
  
  Dim alreadyRegistered As Boolean = False
  
  If Not ( requestor Is Nil ) And ( requestor IsA AppLogReceiver ) Then
  // first make sure WeakRef objects that are registered still exist (and 
remove if not)
  For k As Integer = Receivers.Ubound DownTo 0
  If ( Receivers( k ) Is Nil ) Or ( Receivers( k ).Value Is Nil ) Then  // 
WeakRef object doesn't exist
    Receivers.Remove( k )
  Elseif ( Receivers( k ).Value Is requestor ) Then  // objects are the same
    alreadyRegistered = True  // only register once, so ignore multiple 
registrations
  End If
  Next
  If Not ( alreadyRegistered ) Then
  Receivers.Append( New WeakRef( requestor ))
  AppLogReceiver( requestor ).ProcessNewLogElements( LogList )
  End If
  End If
End Sub

Protected Sub ReleaseAppLogReceiver(requestor As Object)
  //===============================================================
  '
  '  ReleaseAppLogReceiver( ) will remove any class that implements the 
AppLogReceiver
  '  class interface from the list -- and will no longer have updated messages 
sent to it.
  '
  '  See note in RegisterAppLogReceiver( ) for more information.
  '
  //===============================================================
  
  If Not ( requestor Is Nil ) And ( requestor IsA AppLogReceiver ) Then
  // reverse normal order to avoid loop skip errors while removing array 
elements
  For k As Integer = Receivers.Ubound DownTo 0
  If ( Receivers( k ) Is Nil ) Or ( Receivers( k ).Value Is Nil ) Then  // 
WeakRef object doesn't exist
    Receivers.Remove( k )
  Elseif ( Receivers( k ).Value Is requestor ) Then  // objects are the same
    Receivers.Remove( k )
  End If
  Next
  End If
End Sub
   
                            Top           Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 4 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

[email protected]

Reply via email to