Difference between revisions of "PreparedSQLStatement.Bind"

From Xojo Documentation

 
Line 52: Line 52:
 
    
 
    
 
   // perform the search
 
   // perform the search
   Dim rs As RowSet = stmt.SQLSelect
+
   Var rs As RowSet = stmt.SQLSelect
 
    
 
    
 
   ListBox1.RemoveAllRows
 
   ListBox1.RemoveAllRows

Latest revision as of 23:38, 29 July 2019

Method

PreparedSQLStatement.Bind(zeroBasedParam As Integer, value As Variant)

New in 2010r4

Supported for all project types and targets.

Binds a value for the prepared statement.


Method

PreparedSQLStatement.Bind(values() As Variant)

Supported for all project types and targets.

Binds multiple values for the prepared statement.


Method

PreparedSQLStatement.Bind(zeroBasedParam As Integer, value As Variant, type As Integer)

Supported for all project types and targets.

Binds a value and its type for the prepared statement.


Notes

Use Database.Prepare to set up the bind.

Example

This example creates a SQLite prepared statement to retrieve data from a Customers table. It then displays the data in a Listbox:

Var stmt As SQLitePreparedStatement

// note in a prepared statement you DO NOT put in the quotes
stmt = SQLitePreparedStatement(db.Prepare("SELECT * FROM Customers WHERE FirstName like ? "))

// have to tell sqlite what types the items being bound are so it does the right thing
stmt.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)
stmt.Bind(0, TextField1.Value)

// perform the search
Var rs As RowSet = stmt.SQLSelect

ListBox1.RemoveAllRows
ListBox1.ColumnCount = rs.ColumnCount
ListBox1.HasHeader = True

Var hasHeadings As Boolean

While rs.AfterLastRow <> True
ListBox1.AddRow("")

For i As Integer = 0 To rs.ColumnCount-1
If Not hasHeadings Then ListBox1.HeaderAt(i) = rs.ColumnAt(i+1).Name
ListBox1.CellValueAt(ListBox1.LastAddedRowIndex, i) = rs.ColumnAt(i+1).StringValue
Next

rs.MoveToNextRow
hasHeadings = True
Wend

See Also

SQLitePreparedStatement, PostgreSQLPreparedStatement, MSSQLServerPreparedStatement, MySQLPreparedStatement, ODBCPreparedStatement