Table of Contents
Xojo: Migration to Valentina SQLite Server
On this page we will show how easy it really is to switch an existed Xojo project, that uses built-in SQLite database to Valentina SQLite Server.
This tutorial exists as video on yuotube.
We will use example “Xojo/Example Projects/Database/SQLite/SQLiteExample.xojo_binary_project” to modify it. Let`s copy it, for example, to the Desktop and open in Xojo.
Add Init/Shutdown Valentina
To start working with Valentina plugin we should add one or few of its initialization methods:
- Valentina.Init() to use local Valentina DB engine.
- Valentina.InitReports() to use local Valentina Reports engine.
- Valentina.InitClient() to access Valentina Server (never mind what you are going to use: Valentina DB, SQLite DB, Reports).
In this example, we are going to access Valentina Server as SQLite Server. So let's add in Application class a new event handler Open().
Also we should shutdown Valentina plugin using one of 3 shutdown methods. Let's add into Application class a new event handler Close().
Add flag 'gClientMode'
We will make application to be able to work in both modes Local and Client. To choose a mode let's add into the Application class gClientMode property with default value = False
SQLiteWindow to see it.
Double click button “Create SQLite DB” to see its method, which creates local SQLite db.
Change mDB to VSQLiteDatabase
In the above method we can see that original code uses
mDB = new SQLiteDatabase
Instead we should use VSQLiteDatabase class from V4RB plugin. For this click property mDB
and change its type in the inspector
Run Application in the LOCAL Mode
At this point you can try to RUN this modified project in LOCAL mode, to see that it still works using built-in SQLite engine of Xojo.
Run Application in the CLIENT Mode
To run the project in the CLIENT mode, change the default value of gClientMode to TRUE.
Open the folder of Valentina Server to see that database will be created in the folder 'databases_sqlite'. You can use prefs panel Valentina Servers to open it. Or just go directly to Vserver folder. On Mac OS this is '/Library/VServer_x64'. On Windows '\Program Files\Paradigma Software\VServer'.
Now let's start application again, and click all 4 buttons. You will see that application still works, and you see the correct results
Again let's look into Valentina Server folder. This time you will see new folder 'databases_sqlite' with database 'example.sqlite'.
We was need only
- 2 events in App
- about 10-12 lines of code
to convert EXISTING SQLite Example of Xojo to Valentina SQLite Server.
The same amount of job you will need for projects of any size, because you only need correct db create/open/connect code.
- Xojo Database API in the V4RB plugin - Describes how to use Valentina and SQLite with RBDB API of Xojo/REALbasic.