SQL parse: fix improper mid-query newline handling
authorDan
Sat, 14 Mar 2009 15:26:19 -0400
changeset 863 195920655c6c
parent 862 8356381e8d1e
child 864 09c3ba4f6fbf
SQL parse: fix improper mid-query newline handling
includes/sql_parse.php
--- a/includes/sql_parse.php	Sat Mar 14 15:25:55 2009 -0400
+++ b/includes/sql_parse.php	Sat Mar 14 15:26:19 2009 -0400
@@ -108,14 +108,14 @@
       $this->sql_array = str_replace("{{{$key}}}", $value, $this->sql_array);
     }
     
-    // Build an array of queries
+    // Strip out comments
     $this->sql_array = explode("\n", $this->sql_array);
     
     foreach ( $this->sql_array as $i => $sql )
     {
       $query =& $this->sql_array[$i];
       $t = trim($query);
-      if ( empty($t) || preg_match('/^(\#|--)/i', $t) )
+      if ( preg_match('/^(\#|--)/i', $t) )
       {
         unset($this->sql_array[$i]);
         unset($query);
@@ -125,11 +125,12 @@
     
     $this->sql_array = array_values($this->sql_array);
     $this->sql_array = implode("\n", $this->sql_array);
-    $this->sql_array = explode(";\n", $this->sql_array);
+    $this->sql_array = explode(";\n", trim($this->sql_array));
     
     foreach ( $this->sql_array as $i => $sql )
     {
       $query =& $this->sql_array[$i];
+      $query = trim($query);
       if ( substr($query, ( strlen($query) - 1 ), 1 ) != ';' )
       {
         $query .= ';';