OracleSQLPreparedStatement

From Xojo Documentation

Class (inherits from PreparedSQLStatement)


New in 2010r4

Used to create a PreparedSQLStatement for an Oracle Database.

Methods
Bind ExecuteSQL
BindType SelectSQL

Notes

fa-info-circle-32.png
The use of the prepared statement classes is rare because Database.SelectSQL and Database.ExecuteSQL utilize them automatically. See PreparedSQLStatement for information on cases where using prepared statement classes is appropriate.

Oracle prepared statements use the leading colons as markers in the prepared statement, i.e.:

SELECT * FROM Persons WHERE Name = :name

All parameters must have their type specified. These are the constants to use with the BindType method:

Constant
SQL_TYPE_CLOB
SQL_TYPE_DATE
SQL_TYPE_FLOAT
SQL_TYPE_INTEGER
SQL_TYPE_NULL
SQL_TYPE_STRING

Sample Code

This code shows how to use database binding.

// "db" is an OracleDatabase object
Var ps As OracleSQLPreparedStatement
ps = OracleSQLPreparedStatement(db.Prepare("SELECT * FROM Persons WHERE Name = :name AND Age >= :age"))

ps.BindType(0, OracleSQLPreparedStatement.SQL_TYPE_STRING)
ps.BindType(1, OracleSQLPreparedStatement.SQL_TYPE_INTEGER)

ps.Bind(0, "John")
ps.Bind(1, 20)

Try
Var rs As RecordSet = ps.SelectSQL
// Use RecordSet as usual
Catch error As DatabaseException
MessageBox(db.ErrorMessage)
Return
End Try

See Also

Database, OracleDatabase, PreparedSQLStatement classes.