function sql_transaction($status = 'begin')
 {
     switch ($status) {
         case 'begin':
             $result = @odbc_autocommit($this->db_connect_id, false);
             $this->transaction = true;
             break;
         case 'commit':
             $result = @odbc_commit($this->db_connect_id);
             @odbc_autocommit($this->db_connect_id, true);
             $this->transaction = false;
             if (!$result) {
                 @odbc_rollback($this->db_connect_id);
                 @odbc_autocommit($this->db_connect_id, true);
             }
             break;
         case 'rollback':
             $result = @odbc_rollback($this->db_connect_id);
             @odbc_autocommit($this->db_connect_id, true);
             $this->transaction = false;
             break;
         default:
             $result = true;
     }
     return $result;
 }
示例#2
0
 function Commit()
 {
     $this->DoConnect();
     odbc_commit($this->db_Conn);
     //$this->Query("commit", false, "FILE: ".__FILE__."<br> LINE: ".__LINE__);
     odbc_autocommit($this->db_Conn, true);
 }
示例#3
0
 /**
  * commit the sql transaction
  *
  */
 protected function commitTransaction()
 {
     if (self::$transactionStarted[$this->datastore] == true) {
         if (!odbc_commit($this->con)) {
             throw new Exception('unable to commit transaction: ' . odbc_errormsg($this->con));
         }
         self::$transactionStarted[$this->datastore] = false;
     }
 }
示例#4
0
 /**
  * SQL Transaction
  * @access: private
  */
 function _sql_transaction($status = 'begin')
 {
     switch ($status) {
         case 'begin':
             return @odbc_autocommit($this->db_connect_id, false);
             break;
         case 'commit':
             $result = @odbc_commit($this->db_connect_id);
             @odbc_autocommit($this->db_connect_id, true);
             return $result;
             break;
         case 'rollback':
             $result = @odbc_rollback($this->db_connect_id);
             @odbc_autocommit($this->db_connect_id, true);
             return $result;
             break;
     }
     return true;
 }
示例#5
0
文件: db2.php 项目: nmpetkov/ZphpBB2
 function sql_query($query = "", $transaction = FALSE)
 {
     //
     // Remove any pre-existing queries
     //
     unset($this->query_result);
     unset($this->row);
     if ($query != "") {
         $this->num_queries++;
         if (!eregi("^INSERT ", $query)) {
             if (eregi("LIMIT", $query)) {
                 preg_match("/^(.*)LIMIT ([0-9]+)[, ]*([0-9]+)*/s", $query, $limits);
                 $query = $limits[1];
                 if ($limits[3]) {
                     $row_offset = $limits[2];
                     $num_rows = $limits[3];
                 } else {
                     $row_offset = 0;
                     $num_rows = $limits[2];
                 }
                 $query .= " FETCH FIRST " . ($row_offset + $num_rows) . " ROWS ONLY OPTIMIZE FOR " . ($row_offset + $num_rows) . " ROWS";
                 $this->query_result = odbc_exec($this->db_connect_id, $query);
                 $query_limit_offset = $row_offset;
                 $this->result_numrows[$this->query_result] = $num_rows;
             } else {
                 $this->query_result = odbc_exec($this->db_connect_id, $query);
                 $row_offset = 0;
                 $this->result_numrows[$this->query_result] = 5000000.0;
             }
             $result_id = $this->query_result;
             if ($this->query_result && eregi("^SELECT", $query)) {
                 for ($i = 1; $i < odbc_num_fields($result_id) + 1; $i++) {
                     $this->result_field_names[$result_id][] = odbc_field_name($result_id, $i);
                 }
                 $i = $row_offset + 1;
                 $k = 0;
                 while (odbc_fetch_row($result_id, $i) && $k < $this->result_numrows[$result_id]) {
                     for ($j = 1; $j < count($this->result_field_names[$result_id]) + 1; $j++) {
                         $this->result_rowset[$result_id][$k][$this->result_field_names[$result_id][$j - 1]] = odbc_result($result_id, $j);
                     }
                     $i++;
                     $k++;
                 }
                 $this->result_numrows[$result_id] = $k;
                 $this->row_index[$result_id] = 0;
             } else {
                 $this->result_numrows[$result_id] = @odbc_num_rows($result_id);
                 $this->row_index[$result_id] = 0;
             }
         } else {
             if (eregi("^(INSERT|UPDATE) ", $query)) {
                 $query = preg_replace("/\\\\'/s", "''", $query);
             }
             $this->query_result = odbc_exec($this->db_connect_id, $query);
             if ($this->query_result) {
                 $sql_id = "VALUES(IDENTITY_VAL_LOCAL())";
                 $id_result = odbc_exec($this->db_connect_id, $sql_id);
                 if ($id_result) {
                     $row_result = odbc_fetch_row($id_result);
                     if ($row_result) {
                         $this->next_id[$this->query_result] = odbc_result($id_result, 1);
                     }
                 }
             }
             odbc_commit($this->db_connect_id);
             $this->query_limit_offset[$this->query_result] = 0;
             $this->result_numrows[$this->query_result] = 0;
         }
         return $this->query_result;
     } else {
         return false;
     }
 }
示例#6
0
 /**
  * Commit a transaction
  *
  * @param unknown_type $model
  * @return boolean True on success, false on fail
  * (i.e. if the database/model does not support transactions,
  * or a transaction has not started).
  */
 function commit(&$model)
 {
     if (parent::commit($model)) {
         if (odbc_commit($this->connection)) {
             $this->_transactionStarted = false;
             return true;
         }
     }
     return false;
 }
示例#7
0
 function commit()
 {
     odbc_commit($this->conneection);
     odbc_autocommit($this->connection, true);
 }
示例#8
0
 function CommitTrans($ok = true)
 {
     if ($this->transOff) {
         return true;
     }
     if (!$ok) {
         return $this->RollbackTrans();
     }
     if ($this->transCnt) {
         $this->transCnt -= 1;
     }
     $this->_autocommit = true;
     $ret = odbc_commit($this->_connectionID);
     odbc_autocommit($this->_connectionID, true);
     return $ret;
 }
示例#9
0
 /**
  * Commit Transaction
  *
  * @return	bool
  */
 protected function _trans_commit()
 {
     if (odbc_commit($this->conn_id)) {
         odbc_autocommit($this->conn_id, TRUE);
         return TRUE;
     }
     return FALSE;
 }
示例#10
0
 public function transCommit()
 {
     $commit = odbc_commit($this->connect);
     odbc_autocommit($this->connect, true);
     return $commit;
 }
示例#11
0
 /**
  * Makes sure each database and extension handles BEGIN, COMMIT and ROLLBACK 
  * 
  * @param  string &$sql          The SQL to check for a transaction query
  * @param  string $result_class  The type of result object to create
  * @return mixed  `FALSE` if normal processing should continue, otherwise an object of the type $result_class
  */
 private function handleTransactionQueries(&$sql, $result_class)
 {
     // SQL Server supports transactions, but starts then with BEGIN TRANSACTION
     if ($this->type == 'mssql' && preg_match('#^\\s*(begin|start(\\s+transaction)?)\\s*#i', $sql)) {
         $sql = 'BEGIN TRANSACTION';
     }
     $begin = FALSE;
     $commit = FALSE;
     $rollback = FALSE;
     // Track transactions since most databases don't support nesting
     if (preg_match('#^\\s*(begin|start)(\\s+(transaction|work))?\\s*$#iD', $sql)) {
         if ($this->inside_transaction) {
             throw new fProgrammerException('A transaction is already in progress');
         }
         $this->inside_transaction = TRUE;
         $begin = TRUE;
     } elseif (preg_match('#^\\s*(commit)(\\s+(transaction|work))?\\s*$#iD', $sql)) {
         if (!$this->inside_transaction) {
             throw new fProgrammerException('There is no transaction in progress');
         }
         $this->inside_transaction = FALSE;
         $commit = TRUE;
     } elseif (preg_match('#^\\s*(rollback)(\\s+(transaction|work))?\\s*$#iD', $sql)) {
         if (!$this->inside_transaction) {
             throw new fProgrammerException('There is no transaction in progress');
         }
         $this->inside_transaction = FALSE;
         $rollback = TRUE;
     }
     if (!$begin && !$commit && !$rollback) {
         return FALSE;
     }
     // The PDO, OCI8, ODBC and SQLSRV extensions require special handling through methods and functions
     $is_pdo = $this->extension == 'pdo';
     $is_oci = $this->extension == 'oci8';
     $is_odbc = $this->extension == 'odbc';
     $is_sqlsrv = $this->extension == 'sqlsrv';
     if (!$is_pdo && !$is_oci && !$is_odbc && !$is_sqlsrv) {
         return FALSE;
     }
     // PDO seems to act weird if you try to start transactions through a normal query call
     if ($is_pdo) {
         try {
             $is_mssql = $this->type == 'mssql' && substr($this->database, 0, 4) != 'dsn:';
             $is_oracle = $this->type == 'oracle' && substr($this->database, 0, 4) != 'dsn:';
             if ($begin) {
                 // The SQL Server PDO object hasn't implemented transactions
                 if ($is_mssql) {
                     $this->connection->exec('BEGIN TRANSACTION');
                 } elseif ($is_oracle) {
                     $this->connection->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE);
                 } else {
                     $this->connection->beginTransaction();
                 }
             } elseif ($commit) {
                 if ($is_mssql) {
                     $this->connection->exec('COMMIT');
                 } elseif ($is_oracle) {
                     $this->connection->exec('COMMIT');
                     $this->connection->setAttribute(PDO::ATTR_AUTOCOMMIT, TRUE);
                 } else {
                     $this->connection->commit();
                 }
             } elseif ($rollback) {
                 if ($is_mssql) {
                     $this->connection->exec('ROLLBACK');
                 } elseif ($is_oracle) {
                     $this->connection->exec('ROLLBACK');
                     $this->connection->setAttribute(PDO::ATTR_AUTOCOMMIT, TRUE);
                 } else {
                     $this->connection->rollBack();
                 }
             }
         } catch (Exception $e) {
             $db_type_map = array('mssql' => 'MSSQL', 'mysql' => 'MySQL', 'oracle' => 'Oracle', 'postgresql' => 'PostgreSQL', 'sqlite' => 'SQLite');
             throw new fSQLException('%1$s error (%2$s) in %3$s', $db_type_map[$this->type], $e->getMessage(), $sql);
         }
     } elseif ($is_oci) {
         if ($commit) {
             oci_commit($this->connection);
         } elseif ($rollback) {
             oci_rollback($this->connection);
         }
     } elseif ($is_odbc) {
         if ($begin) {
             odbc_autocommit($this->connection, FALSE);
         } elseif ($commit) {
             odbc_commit($this->connection);
             odbc_autocommit($this->connection, TRUE);
         } elseif ($rollback) {
             odbc_rollback($this->connection);
             odbc_autocommit($this->connection, TRUE);
         }
     } elseif ($is_sqlsrv) {
         if ($begin) {
             sqlsrv_begin_transaction($this->connection);
         } elseif ($commit) {
             sqlsrv_commit($this->connection);
         } elseif ($rollback) {
             sqlsrv_rollback($this->connection);
         }
     }
     $result = new $result_class($this);
     $result->setSQL($sql);
     $result->setResult(TRUE);
     return $result;
 }
示例#12
0
 /**
  * Commit Transaction.
  *
  * @return bool
  */
 protected function _trans_commit()
 {
     if (odbc_commit($this->conn_id)) {
         odbc_autocommit($this->conn_id, true);
         return true;
     }
     return false;
 }
示例#13
0
 function CommitTransaction()
 {
     if ($this->auto_commit) {
         return $this->SetError("Commit transaction", "transaction changes are being auto commited");
     }
     if (!odbc_commit($this->connection)) {
         return $this->SetODBCError("Commit transaction", "Could not commit the current transaction", $php_errormsg);
     }
     return 1;
 }
 /**
  * Commit transaction and re-enable autocommit mode
  *
  * @throws VerticaException
  * @author Sergii Katrych <*****@*****.**>
  */
 public function commit()
 {
     $result = odbc_commit($this->getConnection());
     if (false === $result) {
         throw new VerticaException("Failed to commit transaction due to " . odbc_errormsg($this->getConnection()), odbc_error($this->getConnection()));
     }
     $result = odbc_autocommit($this->getConnection(), true);
     if (false === $result) {
         throw new VerticaException("Failed to re-enable autocommit to get out of transactions mode. " . odbc_errormsg($this->getConnection()), odbc_error($this->getConnection()));
     }
 }
示例#15
0
文件: odbc.php 项目: startsevsa/cash
 public function commit()
 {
     odbc_commit($this->_con);
 }
示例#16
0
 /**
  * Commit queries without ending the transaction
  */
 public function commit()
 {
     switch ($this->mode) {
         case "mysql":
             $result = $this->server->commit();
             break;
         case "postgres":
         case "redshift":
             $result = $this->query("COMMIT");
             break;
         case "odbc":
             $result = odbc_commit($this->server);
             break;
         default:
             throw new \Exception("commit() not supported in this mode (" . $this->mode . ")");
     }
     if (!$result) {
         $this->error();
     }
     return true;
 }
示例#17
0
 function CommitTrans()
 {
     $ret = odbc_commit($this->_connectionID);
     odbc_autocommit($this->_connectionID, true);
     return $ret;
 }
示例#18
0
 /**
  * Commit the current transaction.
  * @throws SQLException
  * @return void
  */
 protected function commitTrans()
 {
     if ($this->adapter->supportsTransactions()) {
         $result = @odbc_commit($this->dblink);
         if (!$result) {
             throw new SQLException('Could not commit transaction', $this->nativeError());
         }
         @odbc_autocommit($this->dblink, true);
         if (odbc_error($this->dblink) == 'S1C00') {
             throw new SQLException('Could not commit transaction (autocommit failed)', $this->nativeError());
         }
     }
 }
示例#19
0
odbc_rollback($r);
$rh = odbc_exec($r, "SELECT * FROM innotable");
if ($rh == NULL) {
    echo odbc_errormsg($r);
    exit(1);
}
// fetch
while ($rr = odbc_fetch_array($rh)) {
    var_dump($rr);
}
$rh = odbc_exec($r, "INSERT INTO innotable SET idx=700");
if ($rh == NULL) {
    echo odbc_errormsg($r);
    exit(1);
}
odbc_commit($r);
$rh = odbc_exec($r, "SELECT * FROM innotable");
if ($rh == NULL) {
    echo odbc_errormsg($r);
    exit(1);
}
// fetch
while ($rr = odbc_fetch_array($rh)) {
    var_dump($rr);
}
$rh = odbc_exec($r, "DROP TABLE innotable");
if ($rh == NULL) {
    echo odbc_errormsg($r);
    exit(1);
}
echo odbc_close($r);
示例#20
0
 /**
  * Commits statements in a transaction.
  * @return void
  * @throws DibiDriverException
  */
 public function commit()
 {
     if (!odbc_commit($this->connection)) {
         $this->throwException();
     }
     odbc_autocommit($this->connection, TRUE);
 }
示例#21
0
# annoying "cursor updatability" warnings.
$rv = odbc_execute($stmt, array(2, 'two'));
if ($rv != 1) {
    exit("2nd Insertion failed with  value {$rv}\n");
}
$rv = odbc_execute($stmt, array(3, 'three'));
if ($rv != 1) {
    exit("3rd Insertion failed with  value {$rv}\n");
}
$rv = odbc_execute($stmt, array(4, 'four'));
if ($rv != 1) {
    exit("4th Insertion failed with  value {$rv}\n");
}
$rv = odbc_execute($stmt, array(5, 'five'));
if ($rv != 1) {
    exit("5th Insertion failed with  value {$rv}\n");
}
odbc_commit($conn_id);
# A non-parameterized query
$rs = odbc_exec($conn_id, "SELECT * FROM tsttbl WHERE id < 3");
if (!$rs) {
    exit("Error in SQL\n");
}
$rownum = 0;
while (odbc_fetch_row($rs)) {
    $rownum++;
    echo "{$rownum}: " . odbc_result($rs, "id") . '|' . odbc_result($rs, "vc") . '|' . odbc_result($rs, "entrytime") . "\n";
}
# You need to use the PDO_ODBC extension to parameterize queries (selects).
# If you want an example of this, just ask.
odbc_close($conn_id);
示例#22
0
 function unlock()
 {
     $this->connect();
     if ($this->Transaction_Status) {
         $query = "COMMIT TRANSACTION";
         $res = @odbc_do($this->Link_ID, $query);
         $this->Transaction_Status = 0;
         if (!$res) {
             $this->halt("transaction commit failed.");
             return 0;
         }
     } else {
         $res = @odbc_commit($this->Link_ID);
         /* do not give error if commit does not work...
          * some db-drivers do not support odbc_commit
          */
     }
     return $res;
 }
示例#23
0
 /**
  * Close the database connections. We don't really need to close them (will close at exit), just disassociate so we can refresh them.
  */
 function db_close_connections()
 {
     global $CACHE_DB;
     foreach ($CACHE_DB as $db) {
         foreach ($db as $_db) {
             odbc_commit($_db);
         }
     }
 }
示例#24
0
 /**
  * Commit Transaction
  *
  * @return	bool
  */
 public function trans_commit()
 {
     // When transactions are nested we only begin/commit/rollback the outermost ones
     if (!$this->trans_enabled or $this->_trans_depth > 0) {
         return TRUE;
     }
     $ret = odbc_commit($this->conn_id);
     odbc_autocommit($this->conn_id, TRUE);
     return $ret;
 }
示例#25
0
 function sql_query($query = "", $transaction = FALSE)
 {
     if ($query != "") {
         $this->num_queries++;
         if ($transaction == BEGIN_TRANSACTION && !$this->in_transaction) {
             if (!odbc_autocommit($this->db_connect_id, false)) {
                 return false;
             }
             $this->in_transaction = TRUE;
         }
         if (preg_match("/^SELECT(.*?)(LIMIT ([0-9]+)[, ]*([0-9]+)*)?\$/s", $query, $limits)) {
             $query = $limits[1];
             if (!empty($limits[2])) {
                 $row_offset = $limits[4] ? $limits[3] : "";
                 $num_rows = $limits[4] ? $limits[4] : $limits[3];
                 $query = "TOP " . ($row_offset + $num_rows) . $query;
             }
             $this->result = odbc_exec($this->db_connect_id, "SELECT {$query}");
             if ($this->result) {
                 if (empty($this->field_names[$this->result])) {
                     for ($i = 1; $i < odbc_num_fields($this->result) + 1; $i++) {
                         $this->field_names[$this->result][] = odbc_field_name($this->result, $i);
                         $this->field_types[$this->result][] = odbc_field_type($this->result, $i);
                     }
                 }
                 $this->current_row[$this->result] = 0;
                 $this->result_rowset[$this->result] = array();
                 $row_outer = isset($row_offset) ? $row_offset + 1 : 1;
                 $row_outer_max = isset($num_rows) ? $row_offset + $num_rows + 1 : 1000000000.0;
                 $row_inner = 0;
                 while (odbc_fetch_row($this->result, $row_outer) && $row_outer < $row_outer_max) {
                     for ($j = 0; $j < count($this->field_names[$this->result]); $j++) {
                         $this->result_rowset[$this->result][$row_inner][$this->field_names[$this->result][$j]] = stripslashes(odbc_result($this->result, $j + 1));
                     }
                     $row_outer++;
                     $row_inner++;
                 }
                 $this->num_rows[$this->result] = count($this->result_rowset[$this->result]);
             }
         } else {
             if (eregi("^INSERT ", $query)) {
                 $this->result = odbc_exec($this->db_connect_id, $query);
                 if ($this->result) {
                     $result_id = odbc_exec($this->db_connect_id, "SELECT @@IDENTITY");
                     if ($result_id) {
                         if (odbc_fetch_row($result_id)) {
                             $this->next_id[$this->db_connect_id] = odbc_result($result_id, 1);
                             $this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result);
                         }
                     }
                 }
             } else {
                 $this->result = odbc_exec($this->db_connect_id, $query);
                 if ($this->result) {
                     $this->affected_rows[$this->db_connect_id] = odbc_num_rows($this->result);
                 }
             }
         }
         if (!$this->result) {
             if ($this->in_transaction) {
                 odbc_rollback($this->db_connect_id);
                 odbc_autocommit($this->db_connect_id, true);
                 $this->in_transaction = FALSE;
             }
             return false;
         }
         if ($transaction == END_TRANSACTION && $this->in_transaction) {
             $this->in_transaction = FALSE;
             if (!odbc_commit($this->db_connect_id)) {
                 odbc_rollback($this->db_connect_id);
                 odbc_autocommit($this->db_connect_id, true);
                 return false;
             }
             odbc_autocommit($this->db_connect_id, true);
         }
         odbc_free_result($this->result);
         return $this->result;
     } else {
         if ($transaction == END_TRANSACTION && $this->in_transaction) {
             $this->in_transaction = FALSE;
             if (!@odbc_commit($this->db_connect_id)) {
                 odbc_rollback($this->db_connect_id);
                 odbc_autocommit($this->db_connect_id, true);
                 return false;
             }
             odbc_autocommit($this->db_connect_id, true);
         }
         return true;
     }
 }
示例#26
0
 /**
  * Commit Transaction
  *
  * @access    public
  * @return    bool
  */
 function trans_commit()
 {
     if (!$this->trans_enabled) {
         return true;
     }
     // When transactions are nested we only begin/commit/rollback the outermost ones
     if ($this->_trans_depth > 0) {
         return true;
     }
     $ret = odbc_commit($this->conn_id);
     odbc_autocommit($this->conn_id, true);
     return $ret;
 }
示例#27
0
 function commit()
 {
     if (!@odbc_commit($this->connection)) {
         return $this->odbcRaiseError();
     }
     return DB_OK;
 }
示例#28
0
 function commit()
 {
     return odbc_commit($this->_LINK);
 }
示例#29
0
 /**
  * Commits statements in a transaction.
  * @param  string  optinal savepoint name
  * @return void
  * @throws DibiDriverException
  */
 public function commit($savepoint = NULL)
 {
     if (!odbc_commit($this->connection)) {
         throw new DibiDriverException(odbc_errormsg($this->connection) . ' ' . odbc_error($this->connection));
     }
     odbc_autocommit($this->connection, TRUE);
 }
示例#30
0
 /**
  * Executes given SQL statement.
  *
  * @param string $sql SQL statement
  * @return resource Result resource identifier
  * @access protected
  */
 function _execute($sql)
 {
     switch ($sql) {
         case 'BEGIN':
             return odbc_autocommit($this->connection, false);
         case 'COMMIT':
             return odbc_commit($this->connection);
         case 'ROLLBACK':
             return odbc_rollback($this->connection);
     }
     // TODO: should flags be set? possible requirement:  SQL_CURSOR_STATIC
     return odbc_exec($this->connection, $sql);
 }