API15

JDatabase/splitSql: Difference between revisions

From Joomla! Documentation

m removing red link to edit, no existant pages
m preparing for archive only
 
Line 74: Line 74:


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=splitSql
  category=splitSql
  category=JDatabase
  category=JDatabase
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*

Latest revision as of 00:27, 25 March 2017

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