API15

JDatabase/splitSql

From Joomla! Documentation

< API15:JDatabase

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

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[edit]

splitSql($queries)
Parameter Name Default Value Description
$queries The queries to split

Returns[edit]

array queries

Defined in[edit]

libraries/joomla/database/database.php

Importing[edit]

jimport( 'joomla.database.database' );

Source Body[edit]

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[edit]

Code Examples[edit]