예제 #1
0
 public function fetchAll($how = NULL, $class_name = NULL, $ctor_args = NULL)
 {
     if ($how === null) {
         $how = $this->_parent->getAttribute(PDO::ATTR_DEFAULT_FETCH_MODE);
     }
     switch ($how) {
         case PDO::FETCH_ASSOC:
         case PDO::FETCH_BOTH:
             break;
         default:
             throw new UnsupportedFetchMode("FetchMode {$how} is not supported by PgBabylon");
     }
     $result = [];
     while ($r = $this->fetch($how)) {
         $result[] = $r;
     }
     return $result;
 }
예제 #2
0
파일: PDO.php 프로젝트: rtshome/pgbabylon
 /**
  * Prepares a statement for execution and returns a statement object
  *
  * @link http://php.net/manual/en/pdo.prepare.php
  * @param string $statement This must be a valid SQL statement for the target database server.
  * @param array $driver_options [optional] <p>
  * This array holds one or more key=&gt;value pairs to set
  * attribute values for the <b>PDOStatement</b> object that this method
  * returns.
  * You would use to set PgBabylon\PDO::AUTO_COLUMN_BINDING to request PgBabylon autobinding query columns
  * to native PHP types.<br>
  * Warning 1: This is expensive because, for each column (not row) of the statement, a query
  * to pgsql server is made to get native type information.<br>
  *
  * You would most commonly use this to set the
  * <b>PDO::ATTR_CURSOR</b> value to
  * <b>PDO::CURSOR_SCROLL</b> to request a scrollable cursor.
  * Some drivers have driver specific options that may be set at
  * prepare-time.
  * </p>
  *
  * @return PDOStatement If the database server successfully prepares the statement,
  * <b>PDO::prepare</b> returns a
  * <b>PDOStatement</b> object.
  * If the database server cannot successfully prepare the statement,
  * <b>PDO::prepare</b> returns <b>FALSE</b> or emits
  * <b>PDOException</b> (depending on error handling).
  * </p>
  * <p>
  *
  * @throws \PDOException
  */
 public function prepare($statement, $driver_options = null)
 {
     // Specific pgbabylon options
     $pgbabylonOptions = [];
     if ($driver_options === self::AUTO_COLUMN_BINDING || is_array($driver_options) && in_array(self::AUTO_COLUMN_BINDING, $driver_options)) {
         $pgbabylonOptions[] = self::AUTO_COLUMN_BINDING;
         $driver_options = is_array($driver_options) ? array_filter($driver_options, function ($v) {
             return !$v === self::AUTO_COLUMN_BINDING;
         }) : null;
     }
     if ($driver_options === self::USE_ORIGINAL_PDO_STATEMENT || is_array($driver_options) && in_array(self::USE_ORIGINAL_PDO_STATEMENT, $driver_options)) {
         $driver_options = is_array($driver_options) ? array_filter($driver_options, function ($v) {
             return !$v === self::AUTO_COLUMN_BINDING;
         }) : null;
         return parent::prepare($statement, is_null($driver_options) ? [] : $driver_options);
     }
     /*
     $sth = parent::prepare($statement, is_null($driver_options) ? [] : $driver_options);
     if($sth === false)
         return false;
     */
     return new PDOStatement($statement, $driver_options, $pgbabylonOptions, $this);
 }
예제 #3
0
        }
        rmdir(__TESTS_TEMP_DIR__);
    }
});
if ($result === 0 && mkdir(__TESTS_TEMP_DIR__)) {
    try {
        @exec(sprintf("pg_ctl init -D \"%s\" >/dev/null 2>&1", __TESTS_TEMP_DIR__), $output, $result);
        if ($result !== 0) {
            throw new \Exception(sprintf("Unable to init db in temp dir %s", __TESTS_TEMP_DIR__));
        }
        @exec(sprintf("pg_ctl -w -l \"%s/postgres.log\" -o \"-k '%s'\" start -D \"%s\" >/dev/null 2>&1", __TESTS_TEMP_DIR__, __TESTS_TEMP_DIR__, __TESTS_TEMP_DIR__), $output, $result);
        if ($result !== 0) {
            throw new \Exception("Unable to start test db");
        }
        define('__DB_RUNNING__', true);
        $pdo = new PDO(sprintf("pgsql:host=%s dbname=template1", __TESTS_TEMP_DIR__));
        $r = $pdo->query("SELECT version()");
        if ($r === false) {
            throw new \Exception("Unable to check version of test postgresql");
        }
        if ($r->rowCount() !== 1) {
            throw new \Exception("SELECT version() returned 0 rows");
        }
        if (!preg_match("/^PostgreSQL ([0-9.]{3})/", $r->fetchAll(PDO::FETCH_ASSOC)[0]['version'], $regs)) {
            throw new \Exception("Unable to get version from PostgreSQL version() stored procedure");
        }
        define('__PGSQL_VERSION__', $regs[1]);
        echo sprintf("INFO: PostgreSQL %s server running with datadir %s\r\n", __PGSQL_VERSION__, __TESTS_TEMP_DIR__);
    } catch (Exception $e) {
        if (!defined('__DB_RUNNING__')) {
            define('__DB_RUNNING__', false);