Platforms to show: All Mac Windows Linux Cross-Platform
SQLConnectionMBS class
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
class | SQL | MBS SQL Plugin | 9.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | All |
Supported databases: CubeSQL, Centura SQLBase, DB2, DuckDB, Firebird, Informix, InterBase, MariaDB, Microsoft Access, Microsoft SQL Server, MySQL, ODBC, Oracle Database Server, PostgreSQL, SQL Anywhere, SQLite, SQLCipher and Sybase.
Connect to Microsoft Access, FileMaker Server (or Pro), Microsoft Visual FoxPro and others via ODBC.
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.
see also
https://www.sqlapi.com/ApiDoc/class_s_a_connection.html
The class pings the database every minute by checking whether it's alive and to avoid server dropping connection. This can be disabled by setting Option("Ping") = "false". Ping is not used for SQLite.
MBS Database connections are implemented via SQLConnectionMBS and SQLCommandMBS classes. We provide a thin layer on top with SQLDatabaseMBS class to make it compatible to the Xojo database class. And when you use SQLDatabaseMBS, you can always get the matching SQLConnectionMBS objet via Connection property. Instead of SQLCommandMBS class, you may just use SelectSQL/ExecuteSQL or older SQLSelect/SQLExecute functions.
We have a collection of library files here:
https://www.monkeybreadsoftware.de/xojo/download/plugin/Libs/
- 5 events
- event DidConnect
- event PostgresNotification(NotificationName as string, PID as Integer, Extras as String)
- event Trace(traceInfo as Integer, SQL as string, Command as SQLCommandMBS)
- event WillConnect
- event Working
- 20 properties
- Property AutoCommit as Integer
- Property Client as Integer
- Property ClientVersion as Integer
- Property Error as Boolean
- Property ErrorCode as Integer
- Property ErrorMessage as string
- Property isAlive as boolean
- Property isConnected as boolean
- Property IsolationLevel as Integer
- property LastStatement as String
- property Options as Dictionary
- property RaiseExceptions as Boolean
- property RowsAffected as Integer
- 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
- 2 shared properties
- shared property ConnectionCount as Integer
- shared property VariantsKeepSQLObjects as Boolean
- 45 methods
- method BeginTransaction
- method CancelAllCommands
- method Commands as SQLCommandMBS()
- method Commit
- method Connect(DBString as string, UserID as string, Password as string, client as Integer = 0)
- method ConnectMT(DBString as string, UserID as string, Password as string, client as Integer = 0)
- method CubeSQLLastInsertID as Int64
- 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 Disconnect
- method InsertRecord(TableName as String, Record as Dictionary)
- method Listen
- method MySQLInsertID as Int64
- method Rollback
- method SetFileOption(name as string, file as folderitem)
- method SQLExecute(command as string, CommandType as Integer = 0)
- method SQLExecuteMT(command 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 SQLiteConnectionHandle as Ptr
- 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(command as string, CommandType as Integer = 0) as string
- method SQLSelectAsRecordSet(command as string, CommandType as Integer = 0) as RecordSet
- method SQLSelectAsRecordSetMT(command as string, CommandType as Integer = 0) as RecordSet
- method SQLSelectAsRowSet(command as string, CommandType as integer = 0) as RowSet
- method SQLSelectAsRowSetMT(command as string, CommandType as integer = 0) as RowSet
- method SQLSelectMT(command as string, CommandType as Integer = 0) as string
- method UpdateRecord(TableName as String, Record as Dictionary, Keys as Dictionary)
- shared method kOptionLibrarySeparator as String
- 65 constants
This class has no sub classes.
Some methods using this class:
- SQLCommandMBS.Constructor(connection as SQLConnectionMBS, SQLCommand as String, CommandType as Integer = 0)
Some properties using for this class:
- SQLCommandMBS.Connection as SQLConnectionMBS
- SQLDatabaseMBS.Connection as SQLConnectionMBS
Some events using this class:
- SQLGlobalsMBS.Trace(traceInfo as Integer, SQL as string, Connection as SQLConnectionMBS, Command as SQLCommandMBS)
Some examples using this class:
- /SQL/Microsoft SQL via ODBC on Mac
- /SQL/MySQL Query Version
- /SQL/Reporting From A Database/Reports Example with MBS
- /SQL/SQLDatabaseMBS PostgreSQL
- /SQL/SQLDatabaseMBS SQLite Fetch values threaded
- /SQL/SQLDatabaseMBS SQLite insert record with transaction
- /SQL/SQLite Connect in Memory Database
- /SQL/SQLite Encryption Fetch values
- /SQL/SQLite Fetch rows bulk
- /SQL/SQLite Fetch values
Blog Entries
- MBS Xojo Plugins, version 24.5pr4
- MBS Xojo Plugins, version 24.2pr4
- MonkeyBread Software Releases the MBS Xojo Plugins in version 23.5
- News from the MBS Xojo Plugins Version 22.2
- RowSet in MBS Xojo SQL Plugin
- 10th birthday of MBS SQL Plugin
- Call stored procedures with output parameters
- Big SQLite Cache for 64-bit in Xojo
- MySQL with SSL in MBS Xojo SQL Plugin
- SQLite in memory databases
Xojo Developer Magazine
- 22.1, page 9: News
- 16.1, page 10: News
- 14.1, pages 24 to 30: The MBS SQL Plugin, An alternative way to connect to databases by Christian Schmitz
- 12.4, page 9: News
Videos
Release notes
- Version 24.5
- Added MYSQL_OPT_LOCAL_INFILE option for SQLConnectionMBS and SQLDatabaseMBS classes for MySQL connections.
- Version 24.2
- Improved thread safety for SQLConnectionMBS class.
- Version 24.1
- Changed kOptionLibrarySeparator in SQLConnectionMBS class to be a shared method to return ";" on Windows and ":" on macOS/Linux.
- Version 24.0
- Fixed a possible crash in SQLConnectionMBS destructor.
- Version 23.5
- Added RowsAffected property to SQLConnectionMBS and SQLDatabaseMBS classes.
- Changed SQLConnectionMBS class, so you can load Actual Tech ODBC drivers directly without using iODBC.
- Version 22.3
- Added kMariaDBClient constant for SQLConnectionMBS class.
- Version 22.2
- Added option for SQLDatabaseMBS and SQLConnectionMBS to enable quotes around automatic generated INSERT statements: db.Option("Quotes") = "yes".
- Added SQLiteConnectionHandle method to SQLConnectionMBS and SQLDatabaseMBS classes.
- Version 21.3
- Fixed a memory leak with trace event in SQLConnectionMBS class.
- Version 21.2
- Added kSnapshot constants for SQLDatabaseMBS and SQLConnectionMBS classes.
The items on this page are in the following plugins: MBS SQL Plugin.
SQLCommandMBS - SQLDatabaseMBS