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.
- Project of this tutorial ready for use can be found in V4RB/Examples/BRDB_way/SqliteExampleModified folder.
- 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 checkbox 'ClientMode'
We will make this application to be able to work in both modes Local and Client!
To choose a mode let's add checkbox ClientMode on the top of window with default value = False
Please notice, that in real life app, you will use, most probably, some boolean flag instead visual checkbox.
Method Create SQLite DB
Double click button “Create SQLite DB” to see its method, which creates local SQLite db in the original example of Xojo.
Change App.DB to VSQLiteDatabase
In the above method we can see that original code uses
App.DB = new SQLiteDatabase
Instead we should use VSQLiteDatabase class from V4RB plugin. For this click property DB in the App class
and change its type in the inspector to VSQLiteDatabase:
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
Let's open the folder of Valentina Server to see later 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. But at first click checkbox 'ClientMode' and then 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.