includes/sql_parse.php
changeset 1227 bdac73ed481e
parent 1081 745200a9cc2a
--- a/includes/sql_parse.php	Sun Mar 28 21:49:26 2010 -0400
+++ b/includes/sql_parse.php	Sun Mar 28 23:10:46 2010 -0400
@@ -22,134 +22,134 @@
 
 class SQL_Parser
 {
-  /**
-   * The SQL to be parsed.
-   * @var string
-   * @access private
-   */
-  
-  private $sql_string;
-  
-  /**
-   * Parsed SQL array
-   * @var array
-   * @access private
-   */
-  
-  private $sql_array;
-  
-  /**
-   * Template variables.
-   * @var array
-   * @access private
-   */
-  
-  private $tpl_strings;
-  
-  /**
-   * Constructor.
-   * @param string If this contains newlines, it will be treated as the target SQL. If not, will be treated as a filename.
-   * @param string If true, force as raw SQL, i.e. don't treat as a filename no matter what
-   */
-  
-  public function __construct($sql, $force_file = false)
-  {
-    if ( strpos($sql, "\n") || $force_file )
-    {
-      $this->sql_string = $sql;
-    }
-    else
-    {
-      if ( file_exists($sql) )
-      {
-        $this->sql_string = @file_get_contents($sql);
-        if ( empty($this->sql_string) )
-        {
-          throw new Exception('SQL file is blank or permissions are bad');
-        }
-      }
-      else
-      {
-        throw new Exception('SQL file doesn\'t exist');
-      }
-      
-    }
-    $this->sql_array = false;
-    $this->tpl_strings = array();
-    
-    // convert \r\n in the schema to \n, in case some FTP client or zip utility ran unix2dos for us
-    // thanks to InvisGhost for reporting this error
-    $this->sql_string = str_replace("\r\n", "\n", $this->sql_string);
-  }
-  
-  /**
-   * Sets template variables.
-   * @param array Associative array of template variables to assign
-   */
-  
-  public function assign_vars($vars)
-  {
-    if ( !is_array($vars) )
-      return false;
-    $this->tpl_strings = array_merge($this->tpl_strings, $vars);
-  }
-  
-  /**
-   * Internal function to parse the SQL.
-   * @access private
-   */
-  
-  private function parse_sql()
-  {
-    $this->sql_array = $this->sql_string;
-    foreach ( $this->tpl_strings as $key => $value )
-    {
-      $this->sql_array = str_replace("{{{$key}}}", $value, $this->sql_array);
-    }
-    
-    // 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 ( preg_match('/^(\#|--)/i', $t) )
-      {
-        unset($this->sql_array[$i]);
-        unset($query);
-      }
-    }
-    unset($query);
-    
-    $this->sql_array = array_values($this->sql_array);
-    $this->sql_array = implode("\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 .= ';';
-      }
-    }
-    unset($query);
-  }
-  
-  /**
-   * Returns the parsed array of SQL queries.
-   * @param bool Optional. Defaults to false. If true, a parse is performed even if it already happened.
-   * @return array
-   */
-  
-  public function parse($force_reparse = false)
-  {
-    if ( !$this->sql_array || $force_reparse )
-      $this->parse_sql();
-    return $this->sql_array;
-  }
+	/**
+ 	* The SQL to be parsed.
+ 	* @var string
+ 	* @access private
+ 	*/
+	
+	private $sql_string;
+	
+	/**
+ 	* Parsed SQL array
+ 	* @var array
+ 	* @access private
+ 	*/
+	
+	private $sql_array;
+	
+	/**
+ 	* Template variables.
+ 	* @var array
+ 	* @access private
+ 	*/
+	
+	private $tpl_strings;
+	
+	/**
+ 	* Constructor.
+ 	* @param string If this contains newlines, it will be treated as the target SQL. If not, will be treated as a filename.
+ 	* @param string If true, force as raw SQL, i.e. don't treat as a filename no matter what
+ 	*/
+	
+	public function __construct($sql, $force_file = false)
+	{
+		if ( strpos($sql, "\n") || $force_file )
+		{
+			$this->sql_string = $sql;
+		}
+		else
+		{
+			if ( file_exists($sql) )
+			{
+				$this->sql_string = @file_get_contents($sql);
+				if ( empty($this->sql_string) )
+				{
+					throw new Exception('SQL file is blank or permissions are bad');
+				}
+			}
+			else
+			{
+				throw new Exception('SQL file doesn\'t exist');
+			}
+			
+		}
+		$this->sql_array = false;
+		$this->tpl_strings = array();
+		
+		// convert \r\n in the schema to \n, in case some FTP client or zip utility ran unix2dos for us
+		// thanks to InvisGhost for reporting this error
+		$this->sql_string = str_replace("\r\n", "\n", $this->sql_string);
+	}
+	
+	/**
+ 	* Sets template variables.
+ 	* @param array Associative array of template variables to assign
+ 	*/
+	
+	public function assign_vars($vars)
+	{
+		if ( !is_array($vars) )
+			return false;
+		$this->tpl_strings = array_merge($this->tpl_strings, $vars);
+	}
+	
+	/**
+ 	* Internal function to parse the SQL.
+ 	* @access private
+ 	*/
+	
+	private function parse_sql()
+	{
+		$this->sql_array = $this->sql_string;
+		foreach ( $this->tpl_strings as $key => $value )
+		{
+			$this->sql_array = str_replace("{{{$key}}}", $value, $this->sql_array);
+		}
+		
+		// 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 ( preg_match('/^(\#|--)/i', $t) )
+			{
+				unset($this->sql_array[$i]);
+				unset($query);
+			}
+		}
+		unset($query);
+		
+		$this->sql_array = array_values($this->sql_array);
+		$this->sql_array = implode("\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 .= ';';
+			}
+		}
+		unset($query);
+	}
+	
+	/**
+ 	* Returns the parsed array of SQL queries.
+ 	* @param bool Optional. Defaults to false. If true, a parse is performed even if it already happened.
+ 	* @return array
+ 	*/
+	
+	public function parse($force_reparse = false)
+	{
+		if ( !$this->sql_array || $force_reparse )
+			$this->parse_sql();
+		return $this->sql_array;
+	}
 }
 
 ?>