Example #1
0
 public function testTransactionCommit()
 {
     $this->createTable();
     $this->connection->beginTransaction();
     $this->connection->query("INSERT INTO cat (name, colour) VALUES (?, ?)", array('Nennek', 'black'));
     $this->connection->commit();
     $statement = $this->connection->query("SELECT count(*) AS c FROM cat");
     $row = $this->connection->fetch($statement);
     $count = array_shift($row);
     $this->assertEquals(3, $count);
 }
 /**
  * Tests explicit commit function.
  */
 public function testCommit()
 {
     // by default auto-commit is TRUE.
     $exch = DriverTestManager::getExchange('RecordCount');
     $count_sql = $exch->getSql();
     $rs = $this->conn->executeQuery($count_sql, ResultSet::FETCHMODE_NUM);
     $rs->next();
     $total = $rs->getInt(1);
     // $this->assertEquals((int) $exch->getResult(), $total);
     // now begin a transaction
     $this->conn->setAutoCommit(false);
     $exch = DriverTestManager::getExchange('ConnectionTest.setAutoCommit.DELTRAN1');
     $deleted1 = $this->conn->executeUpdate($exch->getSql());
     $exch = DriverTestManager::getExchange('ConnectionTest.setAutoCommit.DELTRAN2');
     $deleted2 = $this->conn->executeUpdate($exch->getSql());
     $total_should_be = $total - ($deleted1 + $deleted2);
     $this->conn->commit();
     // compare the actual total w/ what we expect
     $rs = $this->conn->executeQuery($count_sql, ResultSet::FETCHMODE_NUM);
     $rs->next();
     $new_actual_total = $rs->getInt(1);
     $this->assertEquals($total_should_be, $new_actual_total, 0, "Failed to find correct num of records after explicit transaction commit.");
     $this->conn->setAutoCommit(true);
 }
 /**
  * Commit a transaction.  This method takes care of releasing the
  * connection after the commit.  In databases that do not support
  * transactions, it only returns the connection.
  *
  * @param Connection $con The Connection for the transaction.
  * @return void
  * @throws PropelException
  */
 public static function commit($con)
 {
     if ($con === null) {
         throw new PropelException(
                 "Connection object was null. "
                 . "This could be due to a misconfiguration. "
                 . "Check the logs and Propel properties "
                 . "to better determine the cause.");
     }
     try {
         if ($con->getAutoCommit() === false) {
             $con->commit();
             $con->setAutoCommit(true);
         }
     } catch (SQLException $e) {
         throw new PropelException($e);
     }
 }
 /**
  * Unlocks the specified table.
  *
  * @param      Connection $con The Creole connection to use.
  * @param      string $table The name of the table to unlock.
  * @throws     SQLException No Statement could be created or executed.
  */
 public function unlockTable(Connection $con, $table)
 {
     // Tables in Sybase are unlocked when a commit is issued.  The
     // user may have issued a commit but do it here to be sure.
     $con->commit();
 }
Example #5
0
}
$conn = new Connection();
?>

<?php 
if (isset($_POST["btnSubmit"]) && $_POST["token"] == $_SESSION["token"]) {
    $judul = $_POST['judul'];
    $isi = $_POST['isi'];
    $idSekolah = null;
    if ($_SESSION["level"] == "admin_sekolah") {
        $idSekolah = $conn->isExistSekolah($_SESSION["idSekolah"]);
    }
    $idUser = $_SESSION['id'];
    $conn->beginTransaction();
    $conn->insertArtikel($judul, $isi, $idSekolah, $idUser);
    $conn->commit();
}
if (isset($_POST["btnSimpan"]) && $_POST["token"] == $_SESSION["token"]) {
    $idArtikel = $_POST['id'];
    $judul = $_POST['judul'];
    $isi = $_POST['isi'];
    $conn->beginTransaction();
    $conn->updateArtikelData($idArtikel, $judul, $isi);
    $conn->commit();
}
if (isset($_POST["btnDelete"]) && $_POST["token"] == $_SESSION["token"]) {
    $idArtikel = $_POST['id'];
    $conn->beginTransaction();
    $conn->deleteArtikel($idArtikel);
    $conn->commit();
}
 /**
  * @see Connection::commit()
  */
 public function commit()
 {
     $this->log("Committing transaction.");
     return $this->childConnection->commit();
 }
Example #7
0
File: SQL.php Project: renq/ML-Lib
	/**
	 * Commit transaction.
	 */
	public function commit() {
		$this->connection->commit();
	}
Example #8
0
 /**
  * Execute this migration version up or down and and return the SQL.
  *
  * @param string $direction   The direction to execute the migration.
  * @param string $dryRun      Whether to not actually execute the migration SQL and just do a dry run.
  * @return array $sql
  * @throws Exception when migration fails
  */
 public function execute($direction, $dryRun = false)
 {
     $this->_sql = array();
     $this->_connection->beginTransaction();
     try {
         $start = microtime(true);
         $this->_state = self::STATE_PRE;
         $fromSchema = $this->_sm->createSchema();
         $this->_migration->{'pre' . ucfirst($direction)}($fromSchema);
         if ($direction === 'up') {
             $this->_outputWriter->write("\n" . sprintf('  <info>++</info> migrating <comment>%s</comment>', $this->_version) . "\n");
         } else {
             $this->_outputWriter->write("\n" . sprintf('  <info>--</info> reverting <comment>%s</comment>', $this->_version) . "\n");
         }
         $this->_state = self::STATE_EXEC;
         $toSchema = clone $fromSchema;
         $this->_migration->{$direction}($toSchema);
         $this->addSql($fromSchema->getMigrateToSql($toSchema, $this->_platform));
         if ($dryRun === false) {
             if ($this->_sql) {
                 $count = count($this->_sql);
                 foreach ($this->_sql as $query) {
                     $this->_outputWriter->write('     <comment>-></comment> ' . $query);
                     $this->_connection->executeQuery($query);
                 }
             } else {
                 $this->_outputWriter->write(sprintf('<error>Migration %s was executed but did not result in any SQL statements.</error>', $this->_version));
             }
             if ($direction === 'up') {
                 $this->markMigrated();
             } else {
                 $this->markNotMigrated();
             }
         } else {
             foreach ($this->_sql as $query) {
                 $this->_outputWriter->write('     <comment>-></comment> ' . $query);
             }
         }
         $this->_state = self::STATE_POST;
         $this->_migration->{'post' . ucfirst($direction)}($toSchema);
         $end = microtime(true);
         $this->_time = round($end - $start, 2);
         if ($direction === 'up') {
             $this->_outputWriter->write(sprintf("\n  <info>++</info> migrated (%ss)", $this->_time));
         } else {
             $this->_outputWriter->write(sprintf("\n  <info>--</info> reverted (%ss)", $this->_time));
         }
         $this->_connection->commit();
         return $this->_sql;
     } catch (SkipMigrationException $e) {
         $this->_connection->rollback();
         // now mark it as migrated
         if ($direction === 'up') {
             $this->markMigrated();
         } else {
             $this->markNotMigrated();
         }
         $this->_outputWriter->write(sprintf("\n  <info>SS</info> skipped (Reason: %s)", $e->getMessage()));
     } catch (\Exception $e) {
         $this->_outputWriter->write(sprintf('<error>Migration %s failed during %s. Error %s</error>', $this->_version, $this->getExecutionState(), $e->getMessage()));
         $this->_connection->rollback();
         $this->_state = self::STATE_NONE;
         throw $e;
     }
     $this->_state = self::STATE_NONE;
 }
Example #9
0
 public function commit()
 {
     if ($this->_connection) {
         $this->_connection->commit();
     }
 }
 /**
  * @see Connection::commit()
  */
 public function commit()
 {
     krumo('DBArrayConnection commit ');
     die;
     $this->log("Committing transaction.");
     return $this->childConnection->commit();
 }
Example #11
0
function importDataGuru($inputFileName, $idSekolah)
{
    try {
        /**  Identify the type of $inputFileName  **/
        $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
        /**  Create a new Reader of the type that has been identified  **/
        $objReader = PHPExcel_IOFactory::createReader($inputFileType);
        /**  Load $inputFileName to a PHPExcel Object  **/
        $objReader->setReadDataOnly(true);
        $objPHPExcel = $objReader->load($inputFileName);
    } catch (Exception $e) {
        die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
    }
    $worksheets;
    $conn;
    $nameSheet;
    $noRow = 0;
    try {
        $conn = new Connection();
        $conn->beginTransaction();
        $worksheets = $objPHPExcel->getAllSheets();
        $idGuru;
        foreach ($worksheets as $worksheet) {
            $nameSheet = $worksheet->getTitle();
            //guru
            $noRow = 2;
            while (true) {
                $username = $worksheet->getCell('B' . $noRow)->getCalculatedValue();
                $password = $worksheet->getCell('C' . $noRow)->getCalculatedValue();
                $nip = $worksheet->getCell('D' . $noRow)->getCalculatedValue();
                $nama = $worksheet->getCell('E' . $noRow)->getCalculatedValue();
                if ($username == null) {
                    break;
                }
                $idGuru = $conn->setGuru($nip, $nama, null, null, null, null, null, null, null, $username, $password, $idSekolah, null);
                //$idGuru=$conn->setGuru($nip, $nama, $tempatLahir, $tglLahir, $jk, $alamat, $telp, $hp, $email, $username, $password, $idSekolah, $foto);
                $noRow++;
            }
        }
        $conn->commit();
        echo 'Data import succesfully';
    } catch (Exception $e) {
        $conn->rollback();
        die('Error in Sheet ' . $nameSheet . ' row ' . $noRow . ' : ' . $e->getMessage());
    }
}