New db-code to Xojo 4.1??

Dim dbDatabase As REALSQLDatabase
  1. I use the code like this and the compiler suggest me to change to “SQLiteDatabase” instead. I notice this just now and I think it’s a feature of Xojo 4.1, since I didn’t notice earlier.

I wonder, is there more than just the name that differ!?
The code and the SQL commands are the same…?

I try to look in the documentation.

  1. http://documentation.xojo.com/index.php/SQLiteDatabase
    On this page, there is written:

Dim db As New SQLiteDatabase db.DatabaseFile = GetFolderItem("db.sqlite")

Maybe this is a silly question, but do I need to name the database, the file itself, like this?

Here is my current code:

[code] dbDatabase = New REALSQLDatabase
TargetFile = GetFolderItem(“database.rsd”)

dbDatabase.DatabaseFile = TargetFile[/code]

I know, I can try… but if all end up wrong, then there are so many errors that can be wrong and then I do not know what to look for!
Thank you!

You can name a variable almost anything you want.

OK, yes, I know. Maybe I write bad?
Let me explain: I wonder, the issue is only a new name or does the change actually involve some major (or minor) changing in the code as well?

I now mean, the difference between “REALSQLDatabase” and “SQLiteDatabase”?
What is the difference, other than the obvious, the text?

SQLiteDatabase was added with Xojo 2013 Release 1.

The database filename can be anything you want.

There are some changes to SQLiteDatabase (from RealSQLDatabase):

  • RowID is not injected into your SQL statements for you, which may affect RecordSet.Edit with SQL statements that did not select a primary key. In this case the solution is to make sure you include the primary key (or rowid) in the original SELECT statement.
  • SQL statements automatically commit after each command. If you want a transaction, use SQLExecute(“BEGIN TRANSACTION”) and then Commit manually at the end.
  • SQLiteDatabase uses a more recent version of SQLite.
  • SQLiteDatabase can use the backup API.
  1. RowID = I always do in my code… (I think!!)
  2. Maybe my code still will do the job. If not, then I know want to look for…!!

Life is full of surprises!!
Thank you for making these steps more obvious for me!!

I’ve used the code in previous versions of Xojo, but then the compiler didn’t care. But now, I get an error and I think, it’s better to act…!!
Thank you for great input!!

And to be clear, although RealSQLDatabase is deprecated it does not cause a compiler error. You can continue to use it if necessary. It does generate a compiler warning if you do Analyze Project/Item, however.

[quote=55403:@Jakob Krabbe]Dim dbDatabase As REALSQLDatabase
2. http://documentation.xojo.com/index.php/SQLiteDatabase
On this page, there is written:

Dim db As New SQLiteDatabase db.DatabaseFile = GetFolderItem("db.sqlite")

Maybe this is a silly question, but do I need to name the database, the file itself, like this?

Here is my current code:

[code] dbDatabase = New REALSQLDatabase
TargetFile = GetFolderItem(“database.rsd”)

dbDatabase.DatabaseFile = TargetFile[/code]

I know, I can try… but if all end up wrong, then there are so many errors that can be wrong and then I do not know what to look for!
Thank you![/quote]

Your way is fine. The call to GetFolderItem returns a FolderItem (duh!) and the dbDatabase.DatabaseFile property requires a FolderItem so all is well. Of course, don’t forget to do the appropriate error checking…

Thanks Dale!

Hmm… Maybe I just pressed that button for the first time assuming it was the same thing as the compiler, checking the code, but leaving the compiling part out…!!

So… Should I change the code and just leave it!?
In general… In the long run, I think I’m better off taking the time to change all code.

Definitely.

Here’s a good reason to change the code…what happens if the user cancels the GetFolderItem dialog? If you have the resultant folderitem assigned to TargetFile you can check for nil before trying to assign it to the database object.