Super class: Database
|Type||Topic||Plugin||Version||macOS||Windows||Linux||Console & Web||iOS|
|class||SQL||MBS SQL Plugin||9.3||Yes||Yes||Yes||Yes||No|
dim db as new SQLDatabaseMBS
// where is the library?
db.SetFileOption SQLConnectionMBS.kOptionLibrarySQLite, getfolderitem("/usr/lib/libsqlite3.0.dylib", folderitem.PathTypeShell)
// connect to database
// in this example it is SQLite,
// but can also be Sybase, Oracle, Informix, DB2, SQLServer, InterBase, MySQL, SQLBase and ODBC
dim path as string
if TargetMacOS then
path = "/tmp/test.db" // put the database in the temporary folder
path = "test.db" // for Windows and Linux in the current folder the application is inside.
db.DatabaseName = "sqlite:"+path
if db.Connect then
MsgBox "We are connected!"
// Disconnect is optional
// autodisconnect will ocur in destructor if needed
msgbox "We are disconnected!"
You can use the SQL plugin without using Xojo (Xojo) built in database classes if you use the SQLConnectionMBS and SQLCommandMBS classes.
Or you use the SQLDatabaseMBS class which is a subclass of the database class and can be used with Xojo's RecordSet class. The current implementation is not complete. You can connect with passing the database URL in the DatabaseName property of the SQLDatabaseMBS class. You prefix this URL with the database type you are using.
You can use Execute and Select to run SQL statements. Errors can be queries with the lasterror properties. For the RecordSet, you can get the column count, the column names and values and move to the next row. All the other methods like deleting a record or updating a value are not implemented and you need to use SQL commands to do this.
Supported databases: Centura SQLBase, DB2, Firebird, Informix, InterBase, MariaDB, Microsoft Access, Microsoft SQL Server, MySQL, ODBC, Oracle Database Server, PostgreSQL, SQL Anywhere, SQLite, SQLCipher and Sybase.
As field and table schema functions are not implemented, you can't use this database with the database browser features in the Xojo (Xojo) IDE.
The plugin does not provide RecordCount on RecordSet class. For that you need to make a extra SELECT count(*) query.
With Xojo 2013r1, you only need a database server license from Xojo, Inc. if you use the SQLDatabaseMBS class. The SQLConnectionMBS class does not require this license. But some features like getting a recordset do need the license as they refer to the SQLDatabaseMBS class.
Please free all RecordSets and SQLCommand objects before you close the SQLConnection or the SQLDatabase. The plugin keeps references from RecordSets and SQLCommand to prevent automatic destruction of the database connection. If you close a database connection while you have RecordSets and SQLCommand in use, things may go wrong.
The plugin can cache the recordset locally. To enable you can call SQLCommandMBS.Cache or use the Option("AutoCache") = "true" on either command or connection or database objects. The plugin will than fetch all records and store them in memory. After this you can walk over the recordset and use FetchPos, FetchFirst, FetchLast, FetchPrev and FetchNext to locate the rows you need. When you call Field() you always get last row, but to read from cached result set, please use Value() function. When using RecordSet, the values are read via Value() functions automatically.
You can use InternalPostgreSQLLibraryMBS or InternalSQLiteLibraryMBS if you like to use our built in SQLite or PostgreSQL database libraries.
Subclass of the Database class.
- 4 events
- 17 properties
- property AutoCommit as Integer
- property Client as Integer
- property ClientVersion as Integer
- Property Connection as SQLConnectionMBS
- property isAlive as boolean
- property isConnected as boolean
- property IsolationLevel as Integer
- property LastStatement as String
- property NativeAPI as Variant
- property Options as Dictionary
- property RaiseExceptions as Boolean
- property Scrollable as Boolean
- property ServerVersion as Integer
- property ServerVersionString as string
- property SQLiteEncryptionKey as String
- property Tag as Variant
- property Option(name as string) as string
- 37 methods
- method CancelAllCommands
- method Commands as SQLCommandMBS()
- method Connect as boolean
- method ConnectMT as Boolean
- method Constructor(globals as SQLGlobalsMBS = nil)
- method CubeSQLReceiveData(byref data as String, byref IsEndChunk as Boolean) as Boolean
- method CubeSQLSendData(data as MemoryBlock)
- method CubeSQLSendData(data as String)
- method CubeSQLSendEndData
- method InsertRecord(TableName as String, Record as Dictionary)
- method Listen
- method MySQLInsertID as Int64
- method Prepare(statement as string) as SQLPreparedStatementMBS
- method SetFileOption(name as string, file as folderitem)
- method SQLExecute(ExecuteString as string, CommandType as Integer)
- method SQLExecuteMT(ExecuteString as string, CommandType as Integer = 0)
- method SQLiteBackupFinish(Backup as SQLite3BackupMBS) as integer
- method SQLiteBackupInit(Dest as Variant, DestName as String, Source as Variant, SourceName as String) as SQLite3BackupMBS
- method SQLiteBackupPageCount(Backup as SQLite3BackupMBS) as integer
- method SQLiteBackupRemaining(Backup as SQLite3BackupMBS) as integer
- method SQLiteBackupStep(Backup as SQLite3BackupMBS, Pages as Integer) as integer
- method SQLiteEnableLoadExtension(OnOff as boolean)
- method SQLiteLastInsertRowID as Int64
- method SQLiteLibVersion as String
- method SQLiteLoadExtension(file as FolderItem, ByRef ErrorMessage as String) as Integer
- method SQLiteLoadExtension(path as String, ByRef ErrorMessage as String) as Integer
- method SQLiteMemoryHighwater(reset as boolean = false) as Int64
- method SQLiteMemoryUsed as Int64
- method SQLiteReKey(Key as String) as Integer
- method SQLiteSetBusyHandler(MaxAttempts as Integer = 5)
- method SQLiteSetBusyTimeout(TimeOutMS as Integer = 20)
- method SQLiteSetKey(Key as String) as Integer
- method SQLiteTableColumnMetaData(DBName as string, TableName as string, ColumnName as string, byref DataType as string, byref CollationSequence as string, byref NotNull as boolean, byref PrimaryKey as boolean, byref AutoIncrement as Boolean) as integer
- method SQLiteThreadsafe as integer
- method SQLSelect(SelectString as string, CommandType as Integer) as RecordSet
- method SQLSelectMT(SelectString as string, CommandType as Integer = 0) as RecordSet
- method UpdateRecord(TableName as String, Record as Dictionary, Keys as Dictionary)
- 48 constants
ANSI Level 0
ANSI Level 1
ANSI Level 2
ANSI Level 3
Values for autocommit property
Autocommit is off.
Autocommit is on.
Command is an SQL statement.
Command is an SQL statement that mustn't be interpreted by SQLAPI.
Command is a stored procedure or a function.
Used by default. Library detects command type automatically.
Bind variable not found.
Initialization failed for client.
Client not set.
Unsupported client type for this platform.
Library file is too old.
Field not found.
Failed to query library version.
Failed to load a library. For example path could be wrong or 32/64bit mismatch.
Out of memory.
Unknown column type.
Unknown data type.
Unknown parameter type.
Failed to convert a value, e.g. string to number.
Can't convert text to date.
Options to specify the library with SetFileOption
for MySQL. Library extension on Mac is ".dylib", on Linux ".so" and on Windows ".dll". You get this library with the MySQL download on their homepage.
for Postgre SQL.
for SQL Anywhere.
for SQLite. Can also be the spatialite or SQLcipher library.
Super class Database
- 7 properties
- 8 methods
This class has no sub classes.
Some examples which use this class:
- /SQL/Reporting From A Database/Reports Example with MBS
- /SQL/SQLDatabase Firebird Connect
- /SQL/SQLDatabaseMBS CubeSQL prepared statement
- /SQL/SQLDatabaseMBS CubeSQL select version
- /SQL/SQLDatabaseMBS Firebird Connect
- /SQL/SQLDatabaseMBS Microsoft Access Connect
- /SQL/SQLDatabaseMBS Microsoft SQL Connect
- /SQL/SQLDatabaseMBS Microsoft SQL Connect and query version
- /SQL/SQLDatabaseMBS Microsoft SQL cross platform
- /SQL/SQLDatabaseMBS Microsoft SQL Execute Stored Procedure
- /SQL/SQLDatabaseMBS Microsoft SQL Server Data Types
- /SQL/SQLDatabaseMBS Microsoft SQL Stored Procedure
- /SQL/SQLDatabaseMBS Microsoft SQL via ODBC
- /SQL/SQLDatabaseMBS Microsoft SQL via ODBC on Linux
- /SQL/SQLDatabaseMBS Microsoft SQL via ODBC on Mac
- /SQL/SQLDatabaseMBS MSSQL Connect
- /SQL/SQLDatabaseMBS MSSQL Execute
- /SQL/SQLDatabaseMBS MSSQL Fetch values
- /SQL/SQLDatabaseMBS MySQL Connect
- /SQL/SQLDatabaseMBS MySQL Dump
- /SQL/SQLDatabaseMBS MySQL Fetch blob
- New SQL Insert and Update functions for our Xojo Plugin
- Big SQLite Cache for 64-bit in Xojo
- MBS Xojo / Real Studio Plugins, version 16.1pr4
- MBS Xojo / Real Studio Plugins, version 14.3pr6
- MonkeyBread Software Releases the MBS Xojo / Real Studio plug-ins in version 14.1
- MBS Xojo / Real Studio Plugins, version 13.2pr7
- MBS Xojo / Real Studio Plugins, version 13.2pr6
- Multithreaded plugin functions can increase speed of Real Studio application
- MBS Real Studio Plugins, version 12.5pr7
- MBS REALbasic Plugins, version 10.5pr2
The items on this page are in the following plugins: MBS SQL Plugin.
MBS FileMaker Plugins