includes/sql_parse.php
changeset 863 195920655c6c
parent 801 eb8b23f11744
child 1081 745200a9cc2a
equal deleted inserted replaced
862:8356381e8d1e 863:195920655c6c
   106     foreach ( $this->tpl_strings as $key => $value )
   106     foreach ( $this->tpl_strings as $key => $value )
   107     {
   107     {
   108       $this->sql_array = str_replace("{{{$key}}}", $value, $this->sql_array);
   108       $this->sql_array = str_replace("{{{$key}}}", $value, $this->sql_array);
   109     }
   109     }
   110     
   110     
   111     // Build an array of queries
   111     // Strip out comments
   112     $this->sql_array = explode("\n", $this->sql_array);
   112     $this->sql_array = explode("\n", $this->sql_array);
   113     
   113     
   114     foreach ( $this->sql_array as $i => $sql )
   114     foreach ( $this->sql_array as $i => $sql )
   115     {
   115     {
   116       $query =& $this->sql_array[$i];
   116       $query =& $this->sql_array[$i];
   117       $t = trim($query);
   117       $t = trim($query);
   118       if ( empty($t) || preg_match('/^(\#|--)/i', $t) )
   118       if ( preg_match('/^(\#|--)/i', $t) )
   119       {
   119       {
   120         unset($this->sql_array[$i]);
   120         unset($this->sql_array[$i]);
   121         unset($query);
   121         unset($query);
   122       }
   122       }
   123     }
   123     }
   124     unset($query);
   124     unset($query);
   125     
   125     
   126     $this->sql_array = array_values($this->sql_array);
   126     $this->sql_array = array_values($this->sql_array);
   127     $this->sql_array = implode("\n", $this->sql_array);
   127     $this->sql_array = implode("\n", $this->sql_array);
   128     $this->sql_array = explode(";\n", $this->sql_array);
   128     $this->sql_array = explode(";\n", trim($this->sql_array));
   129     
   129     
   130     foreach ( $this->sql_array as $i => $sql )
   130     foreach ( $this->sql_array as $i => $sql )
   131     {
   131     {
   132       $query =& $this->sql_array[$i];
   132       $query =& $this->sql_array[$i];
       
   133       $query = trim($query);
   133       if ( substr($query, ( strlen($query) - 1 ), 1 ) != ';' )
   134       if ( substr($query, ( strlen($query) - 1 ), 1 ) != ';' )
   134       {
   135       {
   135         $query .= ';';
   136         $query .= ';';
   136       }
   137       }
   137     }
   138     }