Value? mark in sqlite

What does the character mean ?in this SQL query?

$res = $dbConn->fetchPairs('SELECT name FROM tree where parent = ?',$key);
+3
source share
4 answers

This is a parameterized query.? is a placeholder for the actual value stored in $ key.

+3
source

This is a query parameter . The value is not known at compile time - it is determined at run time using the contents of the $ key variable.

There are other notations for indicating parameters:

 ? NNN A question mark followed by a number NNN holds a spot for the NNN-th
         parameter. NNN must be between 1 and SQLITE_MAX_VARIABLE_NUMBER.
    ?    A question mark that is not followed by a number holds a spot for the
         next unused parameter.
:AAAA    A colon followed by an identifier name holds a spot for a named
         parameter with the name AAAA. Named parameters are also numbered. The
         number assigned is the next unused number. To avoid confusion, it is
         best to avoid mixing named and numbered parameters.
@AAAA    An "at" sign works exactly like a colon.
$AAAA    A dollar-sign followed by an identifier name also holds a spot for a
         named parameter with the name AAAA. The identifier name in this case
         can include one or more occurances of "::" and a suffix enclosed in
         "(...)" containing any text at all. This syntax is the form of a
         variable name in the Tcl programming language. The presence of this
         syntax results from the fact that SQLite is really a Tcl extension
         that has escaped into the wild.
+5

Commonly used in what is called. stored procedures or prepared statements

+2
source

I think this is a replacement, as in printf, they use% 1,% 2, etc .; replaces the key $.

+1
source

Source: https://habr.com/ru/post/1733980/


All Articles