Actions

API15

JDatabase/splitSql

From Joomla! Documentation

< API15:JDatabase
Revision as of 08:58, 12 May 2013 by JoomlaWikiBot (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

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

<CodeExamplesForm />