Comment on code

Ruslan Zasukhin sunshine at public.kherson.ua
Thu Dec 7 10:58:10 CST 2006


Hi Charles,

Your test project have this function.

-------------------------------------
Sub Action()
  dim connection as new VConnection("localhost", "sa", "sa")
  connection.Open
  dim db as new VDatabase(connection)
  db.Open new FolderItem("pastefforts")
  
  dim c as VCursor = db.SQLSelect("SELECT recID, * FROM Decisions WHERE
recid < 400", EVCursorLocation.kServerSide, EVLockType.kReadWrite,
EVCursorDirection.kRandom)
  
  if c.FirstRecord then
    do
      if not c.BlobField("notesStyleData").IsNull then
        dim styleData as String = c.BlobField("notesStyleData").ReadRawData
      end if
    loop until not c.NextRecord
  end if
  c = nil
  db.Close
  
exception oops
  break
---------------------------------------------------------


This code contains at least 2 not obvious mistakes.

1) connection is never closed and destroyed.

    so when I try reproduce your few-clicks issue,
    I simply get in server log that connections are eaten to zero,
    and then server refuse connection.

    actually IT IS STRANGE that connection object not dies
    on function exit. As I understand RB should kill connection object.
    right ?


2) this code is not safe from point of view of exception throw.
    look.

If in loop any method will throw exception, then you will go into last 2
lines of code. But lines

  c = nil
  db.Close
  connection.close
  connection = nil 

Never will be executed. You see?

SAFE code must have such finalization code in both
        
        normal branch
        exception branch

May be realbasic have like Java keyword:   'final' ?


-- 
Best regards,

Ruslan Zasukhin
VP Engineering and New Technology
Paradigma Software, Inc

Valentina - Joining Worlds of Information
http://www.paradigmasoft.com

[I feel the need: the need for speed]




More information about the Valentina mailing list