Platforms to show: All Mac Windows Linux Cross-Platform

Back to Database class.

Database.AddRow(TableName as String, row as DatabaseRow)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 20.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Inserts Data (a populated DatabaseRow) as a new row in TableName.

Database.BeginTransaction

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 20.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a new transaction.

Changes to the database made after this call can be saved with CommitTransaction or undone with RollbackTransaction.

Database.Close

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 1.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Closes or disconnects the database.

Calling Close does not issue a Commit, but some databases will automatically Commit changes in a transaction when you Close the connection and some database will automatically Rollback changes in a transaction when the connection is closed. Refer to the documentation for your database to check what its behavior is.

For desktop applications, you will often Connect to the database when the app starts and Close it when the app quits.

For web applications, you usually Connect to the database when the Session starts and Close it when the Session quits.

Database.Commit

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 1.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Commits an open transaction. This permanently saves changes to the database.

You have to have an open transaction to be able to use Commit. On SQLite (and other databases), you can start a transaction with this command:

BEGIN TRANSACTION

It can be sent using SQLExecute:

DB.SQLExecute("BEGIN TRANSACTION")

Database.CommitTransaction

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 20.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Commits an open transaction. This permanently saves changes to the database.

Database.Connect

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 20.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Connects to the database so that you can begin using it.

See also:

Database.Connect as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 1.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Connects to the database so that you can begin using it.

Before proceeding with database operations, test to be sure that Connect returns True.
If Connect returns False, you should also check the ErrorCode and ErrorMessage.

See Option() for various options you can set before connecting.
e.g. c.Option("SQLiteVFSFlags") = "1" for SQLite for read only access.

See also:

Database.ExecuteSQL(sql As String, ParamArray values As Variant)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 20.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Used to execute an SQL command.

Use this for commands that do not return any data, such as CREATE TABLE or INSERT.

See also:

Database.ExecuteSQL(sql As String, values() As Variant)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 20.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Used to execute an SQL command.

Use this for commands that do not return any data, such as CREATE TABLE or INSERT.

See also:

Database.InsertRecord(TableName as String, Data as DatabaseRecord)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 1.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Inserts Data (a populated DatabaseRecord) as a new row in TableName.

Always check the Error property to verity that the data was added.

Database.Prepare(statement as String) as PreparedSQLStatement

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 1.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Creates a PreparedSQLStatement using the SQL statement for use with the various database prepared statement classes.

A prepared statement is an SQL statement with parameters that has been pre-processed by the database so that it can be executed more quickly if it is re-used with different parameters. Prepared statements also mitigate the risk of SQL injection in web apps.

Database.Rollback

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 1.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Cancels an open transaction restoring the database to the state it was in before the transaction began.

You will generally want to rollback database changes if a database error occurs within the transaction.
You have to have an open transaction to be able to use Rollback. On SQLite (and other databases), you can start a transaction with this command:

BEGIN TRANSACTION

It can be sent using SQLExecute:

DB.SQLExecute("BEGIN TRANSACTION")

Database.RollbackTransaction

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 20.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Cancels an open transaction restoring the database to the state it was in before the transaction began.

Database.SelectSQL(sql As String, ParamArray values As Variant) as RowSet

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 20.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Executes a SQL SELECT statement and returns the results in a RowSet.

See also:

Database.SelectSQL(sql As String, values() As Variant) as RowSet

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 20.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Executes a SQL SELECT statement and returns the results in a RowSet.

See also:

Database.SQLExecute(ExecuteString as string)

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 1.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
Used to execute an SQL command. Use this for commands that do not return any data, such as CREATE TABLE or INSERT. ExecuteString contains the SQL statement.

To avoid SQL Injection, be sure to use Prepared SQL Statements.

Database.SQLSelect(SelectString as string) as RecordSet

Type Topic Plugin Version macOS Windows Linux iOS Targets
method SQL MBS SQL Plugin 1.0 ✅ Yes ✅ Yes ✅ Yes ✅ Yes All
This is an SQL statement that returns a RecordSet.

SelectString contains the SQL statement.

Typically only SQL SELECT statements return a RecordSet, but some databases return a RecordSet for SQL commands such as INSERT, UPDATE or stored procedures.

If the SQL does not return data then Nil is returned. Nil is also usually returned if there is an error in the SQL statement, but you should instead check Database.Error to check if an error occurred.

To avoid SQL Injection, be sure to use Prepared SQL Statements.

The items on this page are in the following plugins: MBS SQL Plugin.


The biggest plugin in space...