phpBMS

Changeset 512 for trunk/phpbms/install

Show
Ignore:
Timestamp:
04/22/09 13:40:06 (3 years ago)
Author:
brieb
Message:
  • fixed db object's process sql file, and implemented it for instal/update procedures. This allows for a more leniency when creating the update/insters SQL files, with comments and such.
Location:
trunk/phpbms/install
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/phpbms/install/installajax.php

    r495 r512  
    8787 
    8888                //Run create table sql file ocreate the tables 
    89                 $tempReturn = $installer->createTables("createtables.sql"); 
     89                $tempReturn = $installer->processSQLFile("createtables.sql"); 
    9090 
    9191                if($tempReturn !== true) 
     
    319319 
    320320                //Run create table sql file ocreate the tables 
    321                 $tempReturn = $installer->createTables($this->pathToModule.$this->createTablesSQL); 
     321                $tempReturn = $installer->processSQLfile($this->pathToModule.$this->createTablesSQL); 
    322322 
    323323                if($tempReturn !== true) 
  • trunk/phpbms/install/install_include.php

    r485 r512  
    1111 
    1212 
    13                 function createTables($sqlfile){ 
     13                function processSQLfile($sqlfile){ 
    1414 
    15                         $sqlstatement=""; 
    16                         $thereturn = ""; 
    17                         $line = 1; 
     15                        $return = ""; 
    1816 
    19                         $filePointer = @ fopen($sqlfile,"r"); 
     17                        $fileReturn = $this->db->processSQLFile($sqlfile); 
    2018 
    21                         if(!$filePointer) 
    22                                 return "Could not open SQL file: ".$sqlfile; 
     19                        if(count($fileReturn->errors)){ 
    2320 
    24                         while(!feof($filePointer)) { 
     21                                foreach($fileReturn->errors as $error) 
     22                                        $return = "\n\n".$error; 
    2523 
    26                                 $createstatement .= @ fgets($filePointer,1024); 
     24                                $return = substr($return, 2); 
    2725 
    28                                 if(strpos($createstatement,";")){ 
     26                                return $return; 
    2927 
    30                                         $this->db->query(trim($createstatement)); 
    31  
    32                                         if($this->db->error) 
    33                                                 return "Error creating tables on line ".$line.": ".$this->db->error." SQL Statement: ".trim($createstatement); 
    34  
    35                                         $createstatement = ""; 
    36  
    37                                 }//end if; 
    38  
    39                                 $line++; 
    40  
    41                         }//end while 
    42  
    43                         return true; 
    44  
    45                 }//end function createTables 
    46  
    47  
    48                 function processSQLfile($filename){ 
    49  
    50                         $thefile = @ fopen($filename,"r"); 
    51                         $line = 1; 
    52                         $thereturn = ""; 
    53  
    54                         if(!$thefile) 
    55                                 return "Could not open the SQL file ".$filename; 
    56  
    57                         while(!feof($thefile)) { 
    58  
    59                                 $sqlstatement .= @ trim(fgets($thefile)); 
    60  
    61                                 // we look for the ; at the end of the line 
    62                                 // If it is not there, we keep adding to the sql statement 
    63                                 if(strrpos($sqlstatement,";") == strlen($sqlstatement)-1){ 
    64  
    65                                         $this->db->query(trim($sqlstatement)); 
    66                                         if($this->db->error) 
    67                                                 $thereturn .= "Error processing SQL file '".$filename."' on line ".$line.": ".$this->db->error." - SQL Statement: ".$sqlstatement."\n"; 
    68  
    69                                         $sqlstatement = ""; 
    70  
    71                                 }//end if; 
    72  
    73                                 $line++; 
    74  
    75                         }//end while 
    76  
    77                         if($thereturn) 
    78                                 return $thereturn; 
    79                         else 
     28                        } else 
    8029                                return true; 
    8130 
    82                 }//end function 
     31                }//end function processSQLfile 
    8332 
    8433        }//end class 
phpBMS vulnerability assesment provided by Orvant Inc. Copyright © 2010 Kreotek, LLC. All Rights reserved.