On 14/02/2006, at 10:22 PM, Marco Bambini wrote:

Hi Jeff,

the best solution is to attach the file based db to the in memory db and then do a cross insert/select, like:
INSERT INTO fileDB.test1 select * from test1

This is a fully working example (RB2006 syntax):

  Dim memDB As new REALSQLDatabase
  Dim db As new REALSQLDatabase
  Dim f As FolderItem = GetFolderItem("").Child("test.rsd")
Dim createTableSQL As String = "CREATE TABLE test1 (field1 text, field2 text, field3 text)"

  // Create in memory db
  if not memDB.Connect then
    MsgBox "Error while creating in memory db"
    return
  end if

  // Create in memorty table
  memDB.SQLExecute(createTableSQL)
  if (memDB.Error) then
    MsgBox memDB.ErrorMessage
    Return
  end if

  // Insert some dummy values
memDB.SQLExecute("INSERT INTO test1 (field1, field2, field3) VALUES ('test1', 'test2', 'test3')") memDB.SQLExecute("INSERT INTO test1 (field1, field2, field3) VALUES ('test1', 'test2', 'test3')") memDB.SQLExecute("INSERT INTO test1 (field1, field2, field3) VALUES ('test1', 'test2', 'test3')") memDB.SQLExecute("INSERT INTO test1 (field1, field2, field3) VALUES ('test1', 'test2', 'test3')") memDB.SQLExecute("INSERT INTO test1 (field1, field2, field3) VALUES ('test1', 'test2', 'test3')")

  // Create file based db
  db.DatabaseFile = f
  if (not db.CreateDatabaseFile) then
    MsgBox "Error while creating file db"
    return
  end if

  // Create file based table
  db.SQLExecute(createTableSQL)
  if (db.Error) then
    MsgBox db.ErrorMessage
    Return
  end if

  // Close all pending transactions or attach fails
  db.Commit
  memDB.Commit
  if not memDB.AttachDatabase(f, "fileDB") then
    MsgBox memDB.ErrorMessage
    return
  end if

  // Dump all records from memory to disk
  memDB.SQLExecute("BEGIN TRANSACTION")
  memDB.SQLExecute("INSERT INTO fileDB.test1 select * from test1")
  memDB.Commit
  memDB.DetachDatabase("myFileDB")

  // Close db(s)
  memDB.Close
  db.Close

---

Hi Marco,

Firstly, a HUGE thanks for the effort you went to in preparing the code above. I really appreciate it and I'm sure many others on the list will benefit as well.

You have really blown me away here - I knew there would be an elegant way of doing this and wow what a great piece of code.

I'll get to work now and translate this into my code - I'll let you know how I go.

Cheers


Jeff



_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to