iOSSQLiteDatabase.SQLExecute

From Xojo Documentation

Method

iOSSQLiteDatabase.SQLExecute(sqlstatement As Text, ParamArray values() As Auto)

Supported on Mobile (iOS).

Used to execute a SQL command. Use this for commands that do not return any data, such as CREATE TABLE or INSERT. You can optionally supply a list of values that will bind parameters (specified with "?") in sqlstatement.

Parameters

Value Description
sqlstatement The SQL statement to execute.
ParamArray values A list of values that will be bound to any parameters (usually specified using the "?" character) in sqlstatement.


Method

iOSSQLiteDatabase.SQLExecute(sqlstatement As Text, values() As Auto)

New in 2019r2

Supported on Mobile (iOS).

Used to execute a SQL command. Use this for commands that do not return any data, such as CREATE TABLE or INSERT. You can optionally supply an array of values that will bind parameters (specified with "?") in sqlstatement.

Parameters

Value Description
sqlstatement The SQL statement to execute.
values An array of values that will be bound to any parameters (usually specified using the "?" character) in sqlstatement.

Notes

Refer to the SQLSelect Notes for more information about prepared statements and parameter binding.

Sample Code

Creates a table in an iOSSQLiteDatabase:

Var sql As Text
sql = "CREATE TABLE Team (ID INTEGER, Name TEXT," + _
" Coach TEXT, City TEXT, PRIMARY KEY(ID));"

Try
DB.SQLExecute(sql) // DB is a previously created iOSSQLiteDatabase
Catch e As iOSSQLiteException
Var err As Text = e.Reason
End Try

Update data in a table:

Var sql As Text
sql = "UPDATE Team SET Name = ?1, Coach = ?2 WHERE ID = ?3;"

// Pass in values after sql instead of doing string replacement
Try
Var name As Text = "Mud Hens"
Var coach As Text = "Dave Roberts"
Var ID As Integer = 100 // Primary key for row
DB.SQLExecute(sql, firstName, lastName, ID)
Catch e As iOSSQLiteException
Var err As Text = e.Reason
End Try

Add data to a table:

Var sql As Text
sql = "INSERT INTO Team (Name, Coach, City) VALUES (?1, ?2, ?3);"

// Pass in values after sql instead of doing string replacement
Try
Var name As Text = "Flying Squirrels"
Var coach As Text = "Tim Roberts"
Var city As Text = "Springfield"
// ID is created automatically because it is a primary key
DB.SQLExecute(sql, name, coach, city)
Catch e As iOSSQLiteException
Var err As Text = e.Reason
End Try

Remove data from a table:

Var sql As Text
sql = "DELETE FROM Team WHERE ID = ?1;"

// Pass in values after sql instead of doing string replacement
Try
Var ID As Integer = 100 // Primary key for row
DB.SQLExecute(sql, ID) // Previously connected database
Catch e As iOSSQLiteException
Var err As Text = e.Reason
End Try