sqlite_bind_value

mIRC SQLite

sqlite_bind_value
Binds a value as a parameter for prepared statement.
Syntax
$sqlite_bind_value ( statement, param, value [, datatype ] )
/sqlite_bind_value statement param value [ datatype ]
Parameters
statement
The prepared statement identifier.
param
The parameter to bind to. Must exist in the prepared query.
value
The value to bind to.
datatype
Optional. Tells what datatype value is. See remarks.
Return Value
1 on success, or $null if there was an error.
Remarks
$sqlite_bind_value can be used to bind a value to a parameter.

The param parameter can either be a numerical index, specified with a ? in the query, or a named parameter specified with a :name in the query. If binding a named parameter, you should also include the colon in the name.

If datatype is specified, it must be one of the $SQLITE_INTEGER, $SQLITE_FLOAT, $SQLITE_TEXT, $SQLITE_BLOB and $SQLITE_NULL. The datatype tells what datatype value is. If omitted, mSQLite will attempt to deduce the datatype of the value. You should specify datatype when you want a numerical value to act as a text for example.

Note that if you want to bind a text value with more than one word, you must use the first form of syntax. If you don't care about the return value, you can use the built-in mIRC command /noop

For more information about parameter binding, see Prepared Statements.
Example
; Open a temporary db
var %db = $sqlite_open()

; Binds one numerical and one named parameter
var %sql = SELECT ?, :test
var %stmt = $sqlite_prepare(%db, %sql)
if (%stmt) {
  ; Binds 'Hello world' as first parameter and 100 as second parameter as float.
  ; We must use the $sqlite_bind_param syntax here, because the value contains more than one word.
  noop $sqlite_bind_value(%stmt, 1, Hello world)
  ; If datatype isn't specified 100 would be considered an integer by mSQLite.
  sqlite_bind_value %stmt :test 100 $SQLITE_FLOAT

  ; Execute the query and show the results
  var %result = $sqlite_query(%stmt)
  if ($sqlite_fetch_row(%result, row, $SQLITE_NUM)) {
    echo -a 1st: $hget(row, 1)
    echo -a 2nd: $hget(row, 2)
  }

  sqlite_free %result
  sqlite_free %stmt
}
else {
  echo -a Error preparing query: %sqlite_errstr
}

sqlite_close %db

; Output:
; 1st: Hello world
; 2nd: 100.0