CubeSQLDatabase
super: Database
CubeSQL is an object-relational database management system based on sqlite.
Events
-
Load() This event is called when the object becames available in the current runtime system.
-
DidConnect() Handle this event if you want to perform some operations when database is connected.
-
DidDisconnect() Handle this event if you want to perform some operations when database is disconnected.
-
Unload() This event is called when the object has been removed from the current runtime system (but not yet deallocated).
Properties
-
var username: String Username required for access to the database.
-
var password: String Password that is required for access to the database.
-
var hostname: String Database host name or IP address of the database server.
-
var port: Int The port to use to connect to the database server.
-
var password: String Database password.
-
var database: String Database name.
-
var url: String Database url.
-
var affectedRows: Int Returns the number of rows modified, inserted or deleted by the most recently completed INSERT, UPDATE or DELETE statement. Executing any other type of SQL statement does not modify the value returned by this function. (read-only)
-
var lastInsertedRowID: Int Returns the rowid of the most recent successful INSERT into a rowid table. (read-only)
-
var errorCode: Int Returns a numeric error code if the latest sql operation failed. (read-only)
-
var encryption: Int Use this property to set an encryption database connection.
-
var isError: Bool Check if latest operation failed. (read-only)
-
var errorMessage: String Returns an error message if the latest sql operation failed. (read-only)
-
var isConnected: Bool A flag that checks if database is connected. (read-only)
-
var useSchema: Bool A flag to check if current database engines supports schemas. (read-only)
-
var objectName: String The name of the object.
Methods
-
func connect(onSuccess: Closure = null, onError: Closure = null): Bool Connect to the specified database. The optional
onSuccess
andonError
closures can be used to execute the statement in a background thread so that the app remains responsive. TheonSuccess
closure, if set, is executed when the connection ends without errors. TheonError
closure, if set, is executed when the connection fails. The Database object is passed as the only argument in both closures. If at least one of the closures is set then the connection is executed in the UI thread (not recommended for time-consuming tasks) and this method immediately returnsfalse
; otherwise, the statement is executed in the UI thread (not recommended for time-consuming tasks) and the method returnstrue
in case of success,false
in case of failure. -
func select(sql: String, onSuccess: Closure = null, onError: Closure = null): CubeSQLRecordSet Perform a SQL query. The optional
onSuccess
andonError
closures can be used to perform the query in a background thread so that the app remains responsive. TheonSuccess
closure, if set, is executed when the query ends without errors; this closure is invoked with two arguments: the Database itself and the produced RecordSet. TheonError
closure, if set, is executed when the query fails and the Database object is passed as the only argument. If at least one of the closures is set then the query is executed in a background thread and this method immediately returns anull
value; otherwise, the query is executed in the UI thread (not recommended for time-consuming tasks) and the method returns the produced RecordSet in case of success,null
in case of failure. The query fails if the Database is not connected. -
func execute(sql: String, onSuccess: Closure = null, onError: Closure = null): Bool Execute a INSERT, UPDATE, DELETE SQL statement. The optional
onSuccess
andonError
closures can be used to execute the statement in a background thread so that the app remains responsive. TheonSuccess
closure, if set, is executed when the statement ends without errors. TheonError
closure, if set, is executed when the statement fails. The Database object is passed as the only argument in both closures. If at least one of the closures is set then the statement is executed in a background thread and this method immediately returnsfalse
; otherwise, the statement is executed in the UI thread (not recommended for time-consuming tasks) and the method returnstrue
in case of success,false
in case of failure. The execution of the statement fails if the Database is not connected. -
func schemas(onSuccess: Closure = null, onError: Closure = null): CubeSQLRecordSet Retrieve a list of database schemas. The optional
onSuccess
andonError
closures can be used to execute the request in a background thread so that the app remains responsive. TheonSuccess
closure, if set, is executed when list of schemas is retrieved without errors; this closure is invoked with two arguments: the Database itself and the produced RecordSet. TheonError
closure, if set, is executed when the operation fails and the Database object is passed as the only argument of the closure. If at least one of the closures is set then the request is executed in a background thread and this method immediately returns anull
value; otherwise, the statement is executed in the UI thread (not recommended for time-consuming tasks) and the method returns the produced RecordSet in case of success,null
in case of failure. The request fails if the Database is not connected. -
func tables(onSuccess: Closure = null, onError: Closure = null): CubeSQLRecordSet Retrieve a list of database tables. The optional
onSuccess
andonError
closures can be used to execute the request in a background thread so that the app remains responsive. TheonSuccess
closure, if set, is executed when list of schemas is retrieved without errors; this closure is invoked with two arguments: the Database itself and the produced RecordSet. TheonError
closure, if set, is executed when the operation fails and the Database object is passed as the only argument of the closure. If at least one of the closures is set then the request is executed in a background thread and this method immediately returns anull
value; otherwise, the statement is executed in the UI thread (not recommended for time-consuming tasks) and the method returns the produced RecordSet in case of success,null
in case of failure. The request fails if the Database is not connected. -
func tablesWithSchema(schema: String, onSuccess: Closure = null, onError: Closure = null): CubeSQLRecordSet Retrieve a list of database tables within the specified schema. The optional
onSuccess
andonError
closures can be used to execute the request in a background thread so that the app remains responsive. TheonSuccess
closure, if set, is executed when list of schemas is retrieved without errors; this closure is invoked with two arguments: the Database itself and the produced RecordSet. TheonError
closure, if set, is executed when the operation fails and the Database object is passed as the only argument of the closure. If at least one of the closures is set then the request is executed in a background thread and this method immediately returns anull
value; otherwise, the statement is executed in the UI thread (not recommended for time-consuming tasks) and the method returns the produced RecordSet in case of success,null
in case of failure. The request fails if the Database is not connected. -
func columnsForTableAndSchema(table: String, schema: String, extended: Bool, onSuccess: Closure = null, onError: Closure = null): CubeSQLRecordSet Retrieve information about a given table in the specified schema. The optional
onSuccess
andonError
closures can be used to execute the request in a background thread so that the app remains responsive. TheonSuccess
closure, if set, is executed when list of schemas is retrieved without errors; this closure is invoked with two arguments: the Database itself and the produced RecordSet. TheonError
closure, if set, is executed when the operation fails and the Database object is passed as the only argument of the closure. If at least one of the closures is set then the request is executed in a background thread and this method immediately returns anull
value; otherwise, the statement is executed in the UI thread (not recommended for time-consuming tasks) and the method returns the produced RecordSet in case of success,null
in case of failure. The request fails if the Database is not connected. -
func addRecord(databaseRecord: DatabaseRecord, table: String, onSuccess: Closure = null, onError: Closure = null): Bool Add DatabaseRecord to the current Database. The optional
onSuccess
andonError
closures can be used to perform the query in a background thread so that the app remains responsive. -
func updateRecord(databaseRecord: DatabaseRecord, table: String, whereClause: String, onSuccess: Closure = null, onError: Closure = null): Bool Update current Database using values from DatabaseRecord class. The whereClause String parameter is used to determine which rows will be affacted bu the UPDATE statement. If all rows need to be update then pass "1". The optional
onSuccess
andonError
closures can be used to perform the query in a background thread so that the app remains responsive. -
func close() Close connection to the database.
-
func escape(identifier: String): String Escape an identifier.