PreparedSQLStatement.Bind

From Xojo Documentation

Revision as of 19:40, 6 April 2018 by PLefebvre (talk | contribs)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!
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:

Dim 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.Text)

// perform the search
Dim rs As RecordSet = stmt.SQLSelect

ListBox1.DeleteAllRows
ListBox1.ColumnCount = rs.FieldCount
ListBox1.HasHeading = True

Dim hasHeadings As Boolean

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

For i As Integer = 0 To rs.FieldCount-1
If Not hasHeadings Then ListBox1.Heading(i) = rs.IdxField(i+1).Name
ListBox1.Cell(ListBox1.LastIndex, i) = rs.idxField(i+1).StringValue
Next

rs.MoveNext
hasHeadings = True
Wend

See Also

SQLitePreparedStatement, PostgreSQLPreparedStatement, MSSQLServerPreparedStatement, MySQLPreparedStatement, ODBCPreparedStatement