Exemplo n.º 1
0
 public static function castLink($link, array $a, Stub $stub, $isNested)
 {
     $a['status'] = pg_connection_status($link);
     $a['status'] = new ConstStub(PGSQL_CONNECTION_OK === $a['status'] ? 'PGSQL_CONNECTION_OK' : 'PGSQL_CONNECTION_BAD', $a['status']);
     $a['busy'] = pg_connection_busy($link);
     $a['transaction'] = pg_transaction_status($link);
     if (isset(self::$transactionStatus[$a['transaction']])) {
         $a['transaction'] = new ConstStub(self::$transactionStatus[$a['transaction']], $a['transaction']);
     }
     $a['pid'] = pg_get_pid($link);
     $a['last error'] = pg_last_error($link);
     $a['last notice'] = pg_last_notice($link);
     $a['host'] = pg_host($link);
     $a['port'] = pg_port($link);
     $a['dbname'] = pg_dbname($link);
     $a['options'] = pg_options($link);
     $a['version'] = pg_version($link);
     foreach (self::$paramCodes as $v) {
         if (false !== ($s = pg_parameter_status($link, $v))) {
             $a['param'][$v] = $s;
         }
     }
     $a['param']['client_encoding'] = pg_client_encoding($link);
     $a['param'] = new EnumStub($a['param']);
     return $a;
 }
 /**
  * testa se a existe transacao ativa na conexao corrente;.
  * @return boolean
  */
 function inTransaction()
 {
     global $conn;
     $isIntransaction = false;
     $lStatus = pg_transaction_status($conn);
     switch ($lStatus) {
         // sem transacao em  (0)
         case PGSQL_TRANSACTION_IDLE:
             $isIntransaction = false;
             break;
             //em Transacao Ativa, comando sendo executado  (1)
         //em Transacao Ativa, comando sendo executado  (1)
         case PGSQL_TRANSACTION_ACTIVE:
             $isIntransaction = true;
             break;
             //transacao em andamento  (2)
         //transacao em andamento  (2)
         case PGSQL_TRANSACTION_INTRANS:
             $isIntransaction = true;
             break;
             //transacao com erro  (3)
         //transacao com erro  (3)
         case PGSQL_TRANSACTION_INERROR:
             $isIntransaction = false;
             break;
             //falha na conexao; (4);
         //falha na conexao; (4);
         case PGSQL_TRANSACTION_UNKNOWN:
             $isIntransaction = false;
             break;
     }
     return $isIntransaction;
 }
Exemplo n.º 3
0
 /**
  * Is in transaction?
  * @return bool
  */
 public function inTransaction()
 {
     return !in_array(pg_transaction_status($this->connection), array(PGSQL_TRANSACTION_UNKNOWN, PGSQL_TRANSACTION_IDLE), TRUE);
 }
 public function update()
 {
     $this->mNewState = array(pg_connection_status($this->mConn), pg_transaction_status($this->mConn));
 }
Exemplo n.º 5
0
 /**
  * Checks whether a transaction is currently open.
  *
  * @return  bool
  */
 public function inTransaction()
 {
     $status = pg_transaction_status($this->getResource());
     return PGSQL_TRANSACTION_INTRANS === $status || PGSQL_TRANSACTION_INERROR === $status;
 }
Exemplo n.º 6
0
 /**
  * getTransactionStatus
  *
  * Return the current transaction status.
  * Return a PHP constant.
  * @see http://fr2.php.net/manual/en/function.pg-transaction-status.php
  *
  * @access public
  * @return int
  */
 public function getTransactionStatus()
 {
     return pg_transaction_status($this->handler);
 }
Exemplo n.º 7
0
rollback($savepoint=NULL){$this->query($savepoint?"ROLLBACK TO SAVEPOINT $savepoint":'ROLLBACK');}function
inTransaction(){return!in_array(pg_transaction_status($this->connection),array(PGSQL_TRANSACTION_UNKNOWN,PGSQL_TRANSACTION_IDLE),TRUE);}function
Exemplo n.º 8
0
 /**
  * Деструктор. Закрывает открытую транзакцию и записывает в файл(ы) debug информацию.
  *
  */
 public function __destruct()
 {
     --self::$objects;
     if ($this->debugLog) {
         $log = new log("db/" . $this->alias . "/debug/" . $this->debug);
         for ($i = 0; $i < count($this->debugLog); $i++) {
             $log->writeln($this->debugLog[$i]['text']);
         }
     }
     $log = new log("db/" . $this->alias . '/' . date('Y-m-d') . ".log");
     if ($this->log) {
         $log->writeln($this->log);
     }
     if ($this->_transaction) {
         $rollback = false;
         $xstat = pg_transaction_status($this->_transaction);
         $xcodes = array(PGSQL_TRANSACTION_UNKNOWN => 'PGSQL_TRANSACTION_UNKNOWN', PGSQL_TRANSACTION_IDLE => 'PGSQL_TRANSACTION_IDLE', PGSQL_TRANSACTION_INTRANS => 'PGSQL_TRANSACTION_INTRANS', PGSQL_TRANSACTION_INERROR => 'PGSQL_TRANSACTION_INERROR', PGSQL_TRANSACTION_ACTIVE => 'PGSQL_TRANSACTION_ACTIVE');
         switch ($xstat) {
             case PGSQL_TRANSACTION_INTRANS:
             case PGSQL_TRANSACTION_INERROR:
             case PGSQL_TRANSACTION_ACTIVE:
                 $rollback = true;
                 break;
         }
         if ($rollback) {
             $err = "Transaction status is BAD and it rollbacked: {$xcodes[$xstat]}, name=" . $this->alias;
             $this->rollback();
         } else {
             $err = "Transaction counter is BAD on DESTRUCT: status {$xcodes[$xstat]}";
             $this->_transaction = NULL;
         }
         $this->err($err);
     }
     if (!self::$objects) {
         setLastUserAction();
         if (DB::$_stby_log) {
             // можно убрать, отладочное.
             $stby_db = new DB('stat');
             setlocale(LC_ALL, 'en_US.UTF-8');
             foreach (DB::$_stby_log as $key => $val) {
                 list($val['day'], $val['real_mask'], $val['opts']) = explode('=', $key);
                 $sql = "\n                      UPDATE stby_log2\n                         SET master_cnt = master_cnt + ?i, standby_cnt = standby_cnt + ?i,\n                             master_time = master_time + interval ?, standby_time = standby_time + ?, ro_errors_cnt = ro_errors_cnt + ?i\n                       WHERE day = ? AND opts = ? AND real_mask = ?i\n                    ";
                 $res = $stby_db->query($sql, (int) $val['master_cnt'], (int) $val['standby_cnt'], (double) $val['master_time'] . ' seconds', (double) $val['standby_time'] . ' seconds', (int) $val['ro_errors_cnt'], $val['day'], $val['opts'], (int) $val['real_mask']);
                 if (!pg_affected_rows($res)) {
                     $sql = "\n                          INSERT INTO stby_log2 (master_cnt, standby_cnt, master_time, standby_time, ro_errors_cnt, day, opts, real_mask)\n                          VALUES (?i, ?i, ?, ?, ?i, ?, ?, ?i)\n                        ";
                     $stby_db->query($sql, (int) $val['master_cnt'], (int) $val['standby_cnt'], (double) $val['master_time'] . ' seconds', (double) $val['standby_time'] . ' seconds', (int) $val['ro_errors_cnt'], $val['day'], $val['opts'], (int) $val['real_mask']);
                 }
             }
         }
         DB::$_stby_log = array();
     }
 }
Exemplo n.º 9
0
 function status()
 {
     return pg_transaction_status($this->db);
 }
Exemplo n.º 10
0
// connection function tests
include 'config.inc';
$db = pg_pconnect($conn_str);
var_dump($db);
if (pg_connection_status($db) != PGSQL_CONNECTION_OK) {
    echo "pg_connection_status() error\n";
}
if (!pg_connection_reset($db)) {
    echo "pg_connection_reset() error\n";
}
if (pg_connection_busy($db)) {
    echo "pg_connection_busy() error\n";
}
if (function_exists('pg_transaction_status')) {
    if (pg_transaction_status($db) != PGSQL_TRANSACTION_IDLE) {
        echo "pg_transaction_status() error\n";
    }
}
if (false === pg_host($db)) {
    echo "pg_host() error\n";
}
if (!pg_dbname($db)) {
    echo "pg_dbname() error\n";
}
if (!pg_port($db)) {
    echo "pg_port() error\n";
}
if (pg_tty($db)) {
    echo "pg_tty() error\n";
}
Exemplo n.º 11
0
Arquivo: pgsql.php Projeto: roojs/pear
 /**
  * Reverts the current transaction
  *
  * @return int  DB_OK on success.  A DB_Error object on failure.
  */
 function rollback()
 {
     if (pg_transaction_status($this->connection) == PGSQL_TRANSACTION_INTRANS) {
         $this->transaction_opcount = 1;
     }
     if ($this->transaction_opcount > 0) {
         $result = @pg_exec($this->connection, 'abort;');
         $this->transaction_opcount = 0;
         if (!$result) {
             return $this->pgsqlRaiseError();
         }
     }
     return DB_OK;
 }