Skip to content

Commit 0a37bec

Browse files
committed
CompiledStatement returns a library-independent prepared statement.
1 parent 297d854 commit 0a37bec

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/CompiledStatement.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,36 @@ public function addToken( string $repr ) : void {
5353
$this->tpl .= ' ';
5454
}
5555

56+
/**
57+
* Get a (compiled) prepared statement.
58+
*
59+
* The prepared statement was compiled from AST with one string and two arrays:
60+
* - string query: the template SQL query with ? as parameters,
61+
* - array args: the parameters of the template SQL query,
62+
* - array types: the types of the parameters.
63+
*
64+
* The returned array has two keys:
65+
* - template: a string representing the template SQL query,
66+
* - parameters: an array whose each value is [ (string) $type, (string) $arg ]:
67+
* - type: is a letter in [ 's', 'i', 'd', 'b' ] for the type of the parameter,
68+
* - arg: is a string for the parameter.
69+
*
70+
* @return array
71+
*/
72+
public function getPreparedStatement() : array {
73+
74+
$n = count( $this->args );
75+
$parameters = [];
76+
for( $i = 0; $i < $n; $i++ ) {
77+
$parameters[] = [ $this->types[$i], $this->args[$i] ];
78+
}
79+
80+
return [
81+
'template' => $this->getTpl(),
82+
'parameters' => $parameters,
83+
];
84+
}
85+
5686
/**
5787
* Get a (compiled) prepared statement.
5888
*

0 commit comments

Comments
 (0)