Switch to: V10V9V8V7V6V5

Methods of VSqliteDatabase Class

VSqliteDatabase.CreateDatabaseFileEx()

Declaration:

CreateDatabaseFileEx() as Boolean

Description:

1) Xojo SqliteDatabase class has a method CreateDatabaseFile(), which creates a new db on the disk if it does not exist, and opens it otherwise.

This is a strange logic, as for us. So we decided to provide our own method, which works similarly to Valentina DB and any OS system files.

CreateDatabaseFileEx() method creates a new db on the disk in any case. If database already exists it will be erased and a new fresh database will be created.

2) CreateDatabseFile() method works only for the local databases. Our extended method works also for the remote databases. Prefer using CreateDatabaseFileEx() because of this.

Example:

db.DatabaseFileName = GetFolder( "mydb.db" )
created = db.CreateDatabaseFileEx()

Example:

dim db as New VSqliteDatbase
 
db.Host = "127.0.0.1"
db.UserName = "sa"
db.Password = "sa"
db.DatabaseName = "mydb.db"
dim res as boolean = db.Connect()
 
if res = false then
   db.DatabaseName = "mydb.db"
   res = db.CreateDatabaseFileEx()
end if

VSqliteDatabase.Drop()

Declaration:

Drop()

Description:

Drop (remove) the specified database from the disk. Operation can not be undone. Be careful.

Database should be in the closed state.

Example:

if db.IsOpen then db.Close()
db.Drop()

VSqliteDatabase.OpenDatabaseFileEx()

Declaration:

OpenDatabaseFileEx() as Boolean

Description:

Opens the specified database. If database is not found it returns FALSE.

We provide this method, as well as CreateDatabaseFileEx() to have methods similar to Valentina DB and OS files, which have trio of methods: create(), close(), open().

Example:

db.DatabaseFileName = GetFolder( "mydb.db" )
opened = db.OpenDatabaseFileEx()

Example:

dim db as New VSqliteDatbase
 
db.Host = "127.0.0.1"
db.UserName = "sa"
db.Password = "sa"
db.DatabaseName = "mydb.db"
db.Connect() 
...
db.Close()
...
db.OpenDatabaseFile() // we can open it again using the same database object 'db'.
...

Example:

dim db as New VSqliteDatbase
 
db.Host = "127.0.0.1"
db.UserName = "sa"
db.Password = "sa"
db.Connect() // only connection established, because DatabaseName was not specified before connect()
...
db.DatabaseName = "mydb.db"
db.OpenDatabaseFile()
...
db.Close()
...
db.OpenDatabaseFile() // we can open it again using the same database object 'db'.
...

VSqliteDatabase.PrepareEx()

Declaration:

PrepareEx(inQuery as string ) As VSqlitePreparedStatement

Description:

PrepareEx() is an extended version of Database.Prepare() method of Xojo.

The difference is in the return type only. This method returns our VSqlitePreparedStatement class, so you can avoid type-casting.

Example:

// If we want to use additions of VSqlitePreparedStatement class, we should type caste to it, using Prepare() method.
//
dim db as VSqliteDatabase
...
dim stmp as VSqlitePreparedStatement = VSqlitePreparedStatement( db.Prepare( query ) )

Example:

// Using PrepareEx() we get simpler code.
//
dim db as VSqliteDatabase
...
dim stmp as VSqlitePreparedStatement = db.PrepareEx( query )

VSqliteDatabase.UseSSL()

Declaration:

UseSSL()

Description:

This method should be called BEFORE connection to a Valentina Server is established. It informs VCLIENT and VSERVER that they should use SSL port and establish a secure connection.

Make sure that you have to specify correct portSSL property if Valentina Server uses not default SSL port.

Example:

db.host = "127.0.0.1"
db.PortSSL = 15534  // optional if port is default
 
db.useSSL()
db.connect()

VSqliteDatabase.UseNotifications()

Declaration:

UseNotifications()

Description:

This method should be called BEFORE the connection to a Valentina Server is established. It informs VCLIENT and VSERVER that they should establish a more complex connection to support async notifications.

To work with Notifications you should use VNotificationCenter and VNotification classes.

Example:

mSqliteDb = new VSQLiteDatabase
mSqliteDb.Host = ValeUnitTests.mVServerHost
mSqliteDb.UserName = ValeUnitTests.mVServerUserName
mSqliteDb.Password = ValeUnitTests.mVServerPassword 
mSqliteDb.DatabaseName = "test_sqlite.db"
 
mSqliteDb.UseNotifications()
res = mSqliteDb.Connect()  // open connection
 
dim pConnection as VConnection = mSqliteDb.Connection
 
dim nc as new VNotificationCenter( pConnection )
// Now you can subscribe to channels, send and listen to notifications.

VSqliteDatabase.OpenBLOB()

Declaration:

OpenBLOB(inTableName as string, inFieldName as string, inRowID as Int64, inReadWrite as boolean ) As VSqliteBLOB

Description:

OpenBLOB() is an entry point to work with SQLite BLOBs.

Example:

dim db as VSqliteDatabase
...
dim blob as VSqliteBLOB = db.OpenBLOB( "t1", "f1", 1 false )
dim value as String = blob.Read( blob.Size, 0 )
...
blob.Position = 2
value = blob.Read( blob.Size, 0 )
...