function affected()
 {
     if (is_null($this->affected)) {
         $this->affected = pg_affected_rows($this->q);
     }
     return $this->affected;
 }
Example #2
0
 public function affectedRows()
 {
     if (!is_resource($this->result)) {
         return false;
     }
     return pg_affected_rows($this->result);
 }
 function execute()
 {
     $this->queryId = parent::execute();
     if (is_resource($this->queryId)) {
         return pg_affected_rows($this->queryId);
     }
 }
Example #4
0
function comprobar_operacion($res, &$error)
{
    if (pg_affected_rows($res) == 0) {
        $error[] = "No se ha podido modificar el artículo.";
        throw new Exception();
    }
}
Example #5
0
 public function __construct($result, $sql, $as_object = FALSE, $params = NULL, $total_rows = NULL)
 {
     parent::__construct($result, $sql, $as_object, $params);
     if ($as_object === TRUE) {
         $this->_as_object = 'stdClass';
     }
     if ($total_rows !== NULL) {
         $this->_total_rows = $total_rows;
     } else {
         switch (pg_result_status($result)) {
             case PGSQL_TUPLES_OK:
                 $this->_total_rows = pg_num_rows($result);
                 break;
             case PGSQL_COMMAND_OK:
                 $this->_total_rows = pg_affected_rows($result);
                 break;
             case PGSQL_BAD_RESPONSE:
             case PGSQL_NONFATAL_ERROR:
             case PGSQL_FATAL_ERROR:
                 throw new Database_Exception(':error [ :query ]', array(':error' => pg_result_error($result), ':query' => $sql));
             case PGSQL_COPY_OUT:
             case PGSQL_COPY_IN:
                 throw new Database_Exception('PostgreSQL COPY operations not supported [ :query ]', array(':query' => $sql));
             default:
                 $this->_total_rows = 0;
         }
     }
 }
Example #6
0
 public function affected_rows()
 {
     if ($this->last_execute_result === null) {
         return 0;
     }
     return pg_affected_rows($this->last_execute_result);
 }
Example #7
0
 protected function updateAffectedRows($result)
 {
     $this->affected_rows += pg_affected_rows($result);
     if ($this->affected_rows != 0 && $this->affected_rows % 500 == 0) {
         echo get_class($this) . " has affected " . $this->affected_rows . " row(s)...\n";
     }
 }
Example #8
0
 public function SetData($setQuery)
 {
     $this->Connect();
     //var_dump('????', $setQuery, "???");
     $result = pg_query($this->connectionHandle, $setQuery);
     return pg_affected_rows($result);
 }
Example #9
0
 function sqlQuery($query)
 {
     if (!$query) {
         return false;
     }
     if (b1n_DEBUG) {
         echo '<pre style="text-align: left">QUERY: ' . $query . '</pre>';
     }
     if (!$this->sqlIsConnected()) {
         user_error('DB NOT CONNECTED');
         return false;
     }
     $result = pg_query($this->sqlGetLink(), $query);
     if (is_bool($result)) {
         return pg_affected_rows($result);
     }
     $num = pg_num_rows($result);
     if ($num > 0) {
         for ($i = 0; $i < $num; $i++) {
             $row[$i] = pg_fetch_array($result, $i, PGSQL_ASSOC);
         }
         return $row;
     }
     return true;
 }
Example #10
0
 public static function castResult($result, array $a, Stub $stub, $isNested)
 {
     $a['num rows'] = pg_num_rows($result);
     $a['status'] = pg_result_status($result);
     if (isset(self::$resultStatus[$a['status']])) {
         $a['status'] = new ConstStub(self::$resultStatus[$a['status']], $a['status']);
     }
     $a['command-completion tag'] = pg_result_status($result, PGSQL_STATUS_STRING);
     if (-1 === $a['num rows']) {
         foreach (self::$diagCodes as $k => $v) {
             $a['error'][$k] = pg_result_error_field($result, $v);
         }
     }
     $a['affected rows'] = pg_affected_rows($result);
     $a['last OID'] = pg_last_oid($result);
     $fields = pg_num_fields($result);
     for ($i = 0; $i < $fields; ++$i) {
         $field = array('name' => pg_field_name($result, $i), 'table' => sprintf('%s (OID: %s)', pg_field_table($result, $i), pg_field_table($result, $i, true)), 'type' => sprintf('%s (OID: %s)', pg_field_type($result, $i), pg_field_type_oid($result, $i)), 'nullable' => (bool) pg_field_is_null($result, $i), 'storage' => pg_field_size($result, $i) . ' bytes', 'display' => pg_field_prtlen($result, $i) . ' chars');
         if (' (OID: )' === $field['table']) {
             $field['table'] = null;
         }
         if ('-1 bytes' === $field['storage']) {
             $field['storage'] = 'variable size';
         } elseif ('1 bytes' === $field['storage']) {
             $field['storage'] = '1 byte';
         }
         if ('1 chars' === $field['display']) {
             $field['display'] = '1 char';
         }
         $a['fields'][] = new EnumStub($field);
     }
     return $a;
 }
Example #11
0
function safe_dml_query($query, $verbose = True)
{
    global $conn;
    if ($verbose) {
        echo "------------------------\n";
        echo "Executing PG query: {$query}\n";
    }
    $time_start = microtime(true);
    pg_send_query($conn, $query) or die("Failed to execute query {$query}");
    while (pg_connection_busy($conn)) {
        if (microtime(true) - $time_start > 30) {
            if (rand(0, 10) == 0) {
                echo "Busy for " . round((microtime(true) - $time_start) * 1000) . " ms -";
            }
            sleep(5);
        }
        usleep(2000);
    }
    $res = pg_get_result($conn);
    if (pg_result_error($res) != null) {
        die("Error during query: " . pg_result_error($res) . "\n");
    }
    $time_end = microtime(true);
    $rows = pg_affected_rows($res);
    if ($verbose) {
        echo "Done executing {$query}: {$rows} touched\n";
        $t = round(($time_end - $time_start) * 1000);
        echo "Query time: {$t} ms\n";
        echo "------------------------\n";
    }
}
Example #12
0
 /**
  * @param   resource    from pg_query() or pg_get_result()
  * @param   string      SQL used to create this result
  * @param   resource    from pg_connect() or pg_pconnect()
  * @param   boolean|string
  * @return  void
  */
 public function __construct($result, $sql, $link, $return_objects)
 {
     // PGSQL_COMMAND_OK     <- SET client_encoding = 'utf8'
     // PGSQL_TUPLES_OK      <- SELECT table_name FROM information_schema.tables
     // PGSQL_COMMAND_OK     <- INSERT INTO pages (name) VALUES ('gone soon')
     // PGSQL_COMMAND_OK     <- DELETE FROM pages WHERE id = 2
     // PGSQL_COMMAND_OK     <- UPDATE pb_users SET company_id = 1
     // PGSQL_FATAL_ERROR    <- SELECT FROM pages
     switch (pg_result_status($result)) {
         case PGSQL_EMPTY_QUERY:
             $this->total_rows = 0;
             break;
         case PGSQL_COMMAND_OK:
             $this->total_rows = pg_affected_rows($result);
             break;
         case PGSQL_TUPLES_OK:
             $this->total_rows = pg_num_rows($result);
             break;
         case PGSQL_COPY_OUT:
         case PGSQL_COPY_IN:
             Kohana_Log::add('debug', 'PostgreSQL COPY operations not supported');
             break;
         case PGSQL_BAD_RESPONSE:
         case PGSQL_NONFATAL_ERROR:
         case PGSQL_FATAL_ERROR:
             throw new Database_Exception(':error [ :query ]', array(':error' => pg_result_error($result), ':query' => $sql));
     }
     $this->link = $link;
     $this->result = $result;
     $this->return_objects = $return_objects;
     $this->sql = $sql;
 }
 public function Afficher()
 {
     if (isset($_SESSION["compte"]) && !empty($_SESSION["compte"])) {
         // - gestion spécifique de la page
         $account_id = $_SESSION['compte']->id;
         $djun_name = $_SESSION['djun_choisi']->nom;
         // - On supprime le D'jun
         $sql = "DELETE FROM \"libertribes\".\"AVATAR\"  WHERE compte_id = {$account_id} and avatar_nom ='{$djun_name}'";
         $result = $this->db_connexion->Requete($sql);
         if (!$result || pg_affected_rows($result) == 0) {
             // - redirection vers la page djun_suppression avec un message d'erreur
             header('Location: index.php?page=djun_suppression&erreur=1');
             exit;
         }
         //  restructurer la variable de session avatar s'il y a plusieurs avatars
         $avatars = array();
         $i = 0;
         foreach ($_SESSION['avatars'] as $avatar) {
             if ($avatar->nom != $_SESSION['djun_choisi']->nom) {
                 $avatars[$i] = $avatar;
                 $i++;
             }
         }
         unset($_SESSION['avatars']);
         $_SESSION['avatars'] = $avatars;
         unset($_SESSION['djun_choisi']);
         unset($_SESSION["avatar_name"]);
         // - redirection vers la page TDB
         header('Location: index.php?page=tdb');
     } else {
         header('Location: index.php?page=connexion&erreur=3');
         exit;
     }
 }
Example #14
0
 public function query($string = '')
 {
     if ($string != '') {
         $this->query = $this->escape($string);
     } else {
         $this->query = $this->select . $this->insert . $this->update . $this->delete . $this->create . $this->from . $this->join . $this->where . $this->group . $this->order . $this->limit;
     }
     $this->insert = " RETURNING id";
     $this->result = pg_exec($this->connection, $this->query);
     $this->inserted_id = $this->result;
     $this->error = pg_errormessage($this->connection);
     $this->affected_rows = pg_affected_rows($this->result);
     $this->select = '';
     $this->insert = '';
     $this->update = '';
     $this->delete = '';
     $this->create = '';
     $this->from = '';
     $this->join = '';
     $this->where = '';
     $this->group = '';
     $this->order = '';
     $this->limit = '';
     return $this;
 }
Example #15
0
 public function rowsAffected($result)
 {
     $affectedRows = pg_affected_rows($result);
     if (!$affectedRows) {
         $affectedRows = pg_num_rows($result);
     }
     return $affectedRows;
 }
 function affectedRows($ressource = null)
 {
     if ($ressource !== null && get_class($ressource) == 'CopixDbResultSetPostgreSQL') {
         return pg_affected_rows($ressource->_idResult);
     } else {
         return -1;
     }
 }
Example #17
0
 public function affected_rows()
 {
     $num_rows = pg_affected_rows($this->_result);
     if (-1 == $num_rows) {
         throw new DatabaseResultException('Number of rows failed');
     }
     return $num_rows;
 }
Example #18
0
function comprobar_insercion($res, &$error)
{
    if (!$res && pg_affected_rows($res) != 1) {
        $error[] = "no se ha podido llevar a cabo la operación.";
        $res = pg_query("rollback");
        throw new Exception();
    }
}
function wpsql_affected_rows()
{
    if ($GLOBALS['pg4wp_result'] === false) {
        return 0;
    } else {
        return pg_affected_rows($GLOBALS['pg4wp_result']);
    }
}
Example #20
0
 public function delete()
 {
     if ($this->id == 0) {
         return false;
     }
     $result = pg_query('update cars set deleted=TRUE where id=\'' . pesc($this->id) . '\'');
     self::getRows(true);
     return pg_affected_rows($result) > 0;
 }
Example #21
0
 public function insertado($sql)
 {
     $resultado = pg_query($this->conexion, $sql);
     if (!$resultado) {
         echo 'Postgres Error: ' . pg_last_error();
         exit;
     }
     return pg_affected_rows($resultado);
 }
 function registrosAfectados($resultado)
 {
     if (pg_affected_rows($resultado)) {
         $mensaje = "Operacion exitosa";
     } else {
         $mensaje = "Error en la operacion";
     }
     header('location:../Index.php?dato=' . $mensaje);
 }
 public function queryExecute($query)
 {
     $result = pg_query($this->connection, $query);
     if (pg_affected_rows($result) === 1) {
         return true;
     } else {
         return $this->convertToArray($result);
     }
 }
 /**
  * The constructor.
  * @access public
  * @param integer $resourceId The resource id for this query.
  */
 function PostgreSQLUpdateQueryResult($resourceId)
 {
     // ** parameter validation
     $resourceRule = ResourceValidatorRule::getRule();
     ArgumentValidator::validate($resourceId, $resourceRule, true);
     // ** end of parameter validation
     $this->_resourceId = $resourceId;
     $this->_numberOfRows = pg_affected_rows($this->_resourceId);
 }
Example #25
0
 function sql_affectedrows()
 {
     if ($this->db_connect_id) {
         $result = @pg_affected_rows($this->db_connect_id);
         return $result;
     } else {
         return false;
     }
 }
Example #26
0
 /**
  * @param resource $Result query result resource
  */
 public function __construct($Result)
 {
     $this->setAffectedRows(pg_affected_rows($Result));
     $Rows = array();
     while ($row = pg_fetch_assoc($Result)) {
         $Rows[] = $row;
     }
     $this->setResult($Rows);
 }
Example #27
0
 private function executeUpdate($query, $params)
 {
     $result = pg_prepare($this->connection, "query", $query);
     if ($params) {
         $resultSet = pg_execute($this->connection, "query", $params);
     } else {
         $resultSet = pg_execute($this->connection, "query");
     }
     return pg_affected_rows($resultSet);
 }
Example #28
0
 function execute_dml($sql)
 {
     $this->conn = pg_connect($this->conn_str);
     $res = pg_query($sql) or die(pg_last_error() . "<script>alert('error');history.go(-1);</script>");
     if (pg_affected_rows($res) > 0) {
         return 1;
     } else {
         return 2;
     }
 }
Example #29
0
 public function exec(&$statement)
 {
     if ($result = @pg_query($this->link, $statement)) {
         if (is_resource($result)) {
             pg_free_result($result);
             return 0;
         }
         return pg_affected_rows($this->link);
     }
     return false;
 }
Example #30
0
 /**
  * Устанавливает или проверяет статус дня рождения.
  *
  * @param integer $status статус
  *
  * @return integer 1 в случае успеха, 0 в случае ошибки
  */
 public function setStatus($status)
 {
     if (pg_affected_rows(settings::SetVariable('birthday' . $this->year, 'status', $status))) {
         return 1;
     }
     $sql = "INSERT INTO settings (id, module, variable, value) SELECT COALESCE(MAX(id),0)+1, 'birthday{$this->year}', 'status', '{$status}' FROM settings";
     if (pg_query(DBConnect(), $sql)) {
         return 1;
     }
     return 0;
 }