Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

Database.Close
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method SQL MBS SQL Plugin 1.0 Yes Yes Yes Yes No
Function: Closes or disconnects the database.
Notes:
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.

Feedback, Comments & Corrections

Database.Commit
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method SQL MBS SQL Plugin 1.0 Yes Yes Yes Yes No
Function: Commits an open transaction. This permanently saves changes to the database.
Notes:
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")

Feedback, Comments & Corrections

Database.Connect as boolean
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method SQL MBS SQL Plugin 1.0 Yes Yes Yes Yes No
Function: Connects to the database so that you can begin using it.
Notes:
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.

Feedback, Comments & Corrections

Database.InsertRecord(TableName as String, Data as DatabaseRecord)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method SQL MBS SQL Plugin 1.0 Yes Yes Yes Yes No
Function: Inserts Data (a populated DatabaseRecord) as a new row in TableName.
Notes: Always check the Error property to verity that the data was added.

Feedback, Comments & Corrections

Database.Prepare(statement as String) as PreparedSQLStatement
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method SQL MBS SQL Plugin 1.0 Yes Yes Yes Yes No
Function: Creates a PreparedSQLStatement using the SQL statement for use with the various database prepared statement classes.
Notes: 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.

Feedback, Comments & Corrections

Database.Rollback
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method SQL MBS SQL Plugin 1.0 Yes Yes Yes Yes No
Function: Cancels an open transaction restoring the database to the state it was in before the transaction began.
Notes:
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")

Feedback, Comments & Corrections

Database.SQLExecute(ExecuteString as string)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method SQL MBS SQL Plugin 1.0 Yes Yes Yes Yes No
Function: 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.
Notes: To avoid SQL Injection, be sure to use Prepared SQL Statements.

Feedback, Comments & Corrections

Database.SQLSelect(SelectString as string) as RecordSet
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method SQL MBS SQL Plugin 1.0 Yes Yes Yes Yes No
Function: This is an SQL statement that returns a RecordSet.
Notes:
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.

Feedback, Comments & Corrections

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




Links
MBS Xojo PDF Plugins