New topic: 

BEGIN TRANSACTION

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

         Page 1 of 1
   [ 1 post ]                 Previous topic | Next topic          Author  
Message        suibaf          Post subject: BEGIN TRANSACTIONPosted: Fri Nov 
19, 2010 3:22 pm                         
Joined: Tue Dec 16, 2008 9:08 am
Posts: 201
Location: Lecce (Italy)                Hi,

i have the following code that work fine but it is very slow.

Code:  If db_conf.Connect() then
 
  rsParam = db_conf.SQLSelect( "select trend_minuto, trend_semiora, trend_ora, 
trend_giorno from tag_inq ORDER BY ROWID" )
 
  if db_conf.Error then
  //handle error
  MsgBox "Errore durante la lettura del Database di configurazione"
  Return
   
  end if
 
  if rsParam.BOF = True and rsParam.EOF = True then
   
  MsgBox "database Empty"
  rsParam.Close
  db_conf.Close
  Return
   
  end if
 
  for i = 1 to num_inq
   
  rsParam.Edit
  rsParam.Field("trend_minuto").BooleanValue = CkBx_Minuto(i-1).Value
  rsParam.Field("trend_semiora").BooleanValue =CkBx_Semiora(i-1).Value
  rsParam.Field("trend_ora").BooleanValue =CkBx_Ora(i-1).Value
  rsParam.Field("trend_giorno").BooleanValue =CkBx_Giorno(i-1).Value
   
  rsParam.Update
  db_conf.Commit
   
  if db_conf.error then
    //handle error
   
    Msgbox "Errore durante il salvataggio dei dati sul database di 
Configurazione: " + Str(db_conf.ErrorCode) + EndOfLine + _
    EndOfLine + db_conf.ErrorMessage
   
    Return
   
  end if
   
  rsParam.MoveNext
   
  next
 
  rsParam.Close
 
  else
  Beep
  MsgBox "Database Error: " + Str(db_conf.ErrorCode) + EndOfLine + _
  EndOfLine + db_conf.ErrorMessage
  end if




Now i have modified the code and it's become very fast:

Code:  If db_conf.Connect() then
  
  rsParam = db_conf.SQLSelect( "select trend_minuto, trend_semiora, trend_ora, 
trend_giorno from tag_inq ORDER BY ROWID" )
  
  if db_conf.Error then
  //handle error
  MsgBox "Errore durante la lettura del Database di configurazione"
  Return
  
  end if
  
  if rsParam.BOF = True and rsParam.EOF = True then
  
  MsgBox "database Empty"
  rsParam.Close
  db_conf.Close
  Return
  
  end if
  
  db_conf.SQLExecute("BEGIN TRANSACTION")
  
  for i = 1 to num_inq
  
  rsParam.Edit
  rsParam.Field("trend_minuto").BooleanValue = CkBx_Minuto(i-1).Value
  rsParam.Field("trend_semiora").BooleanValue =CkBx_Semiora(i-1).Value
  rsParam.Field("trend_ora").BooleanValue =CkBx_Ora(i-1).Value
  rsParam.Field("trend_giorno").BooleanValue =CkBx_Giorno(i-1).Value
  
  rsParam.Update
  'db_conf.Commit
  
  if db_conf.error then
    //handle error
    
    Msgbox "Errore durante il salvataggio dei dati sul database di 
Configurazione: " + Str(db_conf.ErrorCode) + EndOfLine + _
    EndOfLine + db_conf.ErrorMessage
    
    Return
    
  end if
  
  rsParam.MoveNext
  
  next
  
  db_conf.Commit
  rsParam.Close
  
  else
  Beep
  MsgBox "Database Error: " + Str(db_conf.ErrorCode) + EndOfLine + _
  EndOfLine + db_conf.ErrorMessage
  end if


I have added db_conf.SQLExecute("BEGIN TRANSACTION") and a i have moved 
db_conf.Commit at the end of For cycle.
Of course someone has suggested me this modified, but i don't understand why 
second solution work very very fine.

On the LR about ("BEGIN TRANSACTION") it say:Transactions can be started 
manually using the BEGIN command. Such transactions usually persist until the 
next COMMIT or ROLLBACK command. But a transaction will also ROLLBACK if the 
database is closed or if an error occurs and the ROLLBACK conflict resolution 
algorithm is specified

It's no clear for me. Can someone explain me why first solution work but it's 
very slow and second solution work ant it's very fast?

Thnak you.      
_________________
RB2009R5.1
My native language is Italian, I'll try to make my posts understandable for 
everybody.  
                             Top            Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 1 post ]      
-- 
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