API15:JDatabase/splitSql
From Joomla! Documentation
Description
Splits a string of queries into an array of individual queries
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
splitSql($queries)
| Parameter Name | Default Value | Description |
|---|---|---|
| $queries | The queries to split |
Returns
array queries
Defined in
libraries/joomla/database/database.php
Importing
jimport( 'joomla.database.database' );
Source Body
function splitSql( $queries )
{
$start = 0;
$open = false;
$open_char = '';
$end = strlen($queries);
$query_split = array();
for($i=0;$i<$end;$i++) {
$current = substr($queries,$i,1);
if(($current == '"' || $current == '\'')) {
$n = 2;
while(substr($queries,$i - $n + 1, 1) == '\\' && $n < $i) {
$n ++;
}
if($n%2==0) {
if ($open) {
if($current == $open_char) {
$open = false;
$open_char = '';
}
} else {
$open = true;
$open_char = $current;
}
}
}
if(($current == ';' && !$open)|| $i == $end - 1) {
$query_split[] = substr($queries, $start, ($i - $start + 1));
$start = $i + 1;
}
}
return $query_split;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
Code Examples