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 A list of values that will be bound to any parameters (usually specified using the "?" character) in the supplied SQL statement.

Notes

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

Sample Code

Creates a table in an iOSSQLiteDatabase:

Dim 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
Dim err As Text = e.Reason
End Try

Update data in a table:

Dim 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
Dim name As Text = "Mud Hens"
Dim coach As Text = "Dave Roberts"
Dim ID As Integer = 100 // Primary key for row
DB.SQLExecute(sql, firstName, lastName, ID)
Catch e As iOSSQLiteException
Dim err As Text = e.Reason
End Try

Add data to a table:

Dim 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
Dim name As Text = "Flying Squirrels"
Dim coach As Text = "Tim Roberts"
Dim city As Text = "Springfield"
// ID is created automatically because it is a primary key
DB.SQLExecute(sql, name, coach, city)
Catch e As iOSSQLiteException
Dim err As Text = e.Reason
End Try

Remove data from a table:

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

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