コード例 #1
0
 /**
  * @dataProvider explodeIntoStatementsDataProvider
  */
 public function testExplodeIntoStatements($input, $output)
 {
     $parser = new PropelSQLParser();
     $parser->setSQL($input);
     $this->assertEquals($output, $parser->explodeIntoStatements());
 }
コード例 #2
0
 /**
  * Execute SQL statements, and apply callback to result.
  * 
  * @param string $sql
  * @param bool $abortOnError
  * @param callback|null $stmtCallback
  */
 public static function runStatements($sql, $abortOnError = true, $stmtCallback = null)
 {
     $connection = Propel::getConnection();
     $parser = new PropelSQLParser();
     $parser->setSQL($sql);
     $parser->convertLineFeedsToUnixStyle();
     $parser->stripSQLCommentLines();
     $statements = $parser->explodeIntoStatements();
     foreach ($statements as $statement) {
         try {
             $stmt = $connection->prepare($statement);
             if (!$stmt) {
                 throw new Exception('Failed to create statement');
             }
             $stmt->execute();
             if ($stmtCallback) {
                 call_user_func($stmtCallback, $stmt, $statement);
             }
         } catch (Exception $e) {
             if ($abortOnError) {
                 throw new Curry_Exception('Unable to execute statement: ' . $statement);
             } else {
                 if ($stmtCallback) {
                     call_user_func($stmtCallback, null, $statement);
                 }
             }
         }
     }
 }