/** * @dataProvider stripSqlCommentsDataProvider */ public function testStripSQLComments($input, $output) { $parser = new PropelSQLParser(); $parser->setSQL($input); $parser->stripSQLCommentLines(); $this->assertEquals($output, $parser->getSQL()); }
/** * 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); } } } } }