Example #1
0
 /**
  * Constructor method for the adapter.  This constructor implements the setting of the
  * 3 required properties for the object.
  * 
  * @param resource $d The datasource resource
  */
 function pgsqlAdapter($d)
 {
     parent::RecordSetAdapter($d);
     $fieldcount = fbsql_num_fields($d);
     $ob = "";
     $be = $this->isBigEndian;
     $fc = pack('N', $fieldcount);
     if (fbsql_num_rows($d) > 0) {
         fbsql_data_seek($d, 0);
         while ($line = fbsql_fetch_row($d)) {
             // write all of the array elements
             $ob .= "\n" . $fc;
             foreach ($line as $value) {
                 // write all of the array elements
                 if (is_string($value)) {
                     // type as string
                     $os = $this->_directCharsetHandler->transliterate($value);
                     //string flag, string length, and string
                     $len = strlen($os);
                     if ($len < 65536) {
                         $ob .= "" . pack('n', $len) . $os;
                     } else {
                         $ob .= "\f" . pack('N', $len) . $os;
                     }
                 } elseif (is_float($value) || is_int($value)) {
                     // type as double
                     $b = pack('d', $value);
                     // pack the bytes
                     if ($be) {
                         // if we are a big-endian processor
                         $r = strrev($b);
                     } else {
                         // add the bytes to the output
                         $r = $b;
                     }
                     $ob .= "" . $r;
                 } elseif (is_bool($value)) {
                     //type as bool
                     $ob .= "";
                     $ob .= pack('c', $value);
                 } elseif (is_null($value)) {
                     // null
                     $ob .= "";
                 }
             }
         }
     }
     $this->serializedData = $ob;
     $this->numRows = fbsql_num_rows($d);
     for ($i = 0; $i < $fieldcount; $i++) {
         $this->columnNames[$i] = $this->_charsetHandler->transliterate(fbsql_field_name($d, $i));
     }
 }
Example #2
0
 /**
  * Constructor method for the adapter.  This constructor implements the setting of the
  * 3 required properties for the object.
  * 
  * @param resource $d The datasource resource
  */
 function fbsqlAdapter($d)
 {
     parent::RecordSetAdapter($d);
     $fieldcount = fbsql_num_fields($d);
     for ($i = 0; $i < $fieldcount; $i++) {
         $this->columns[] = fbsql_field_name($d, $i);
     }
     if (fbsql_num_rows($d) > 0) {
         fbsql_data_seek($d, 0);
         while ($line = fbsql_fetch_row($d)) {
             $this->rows[] = $line;
         }
     }
 }
Example #3
0
File: fbsql.php Project: roojs/pear
 /**
  * Places a row from the result set into the given array
  *
  * Formating of the array and the data therein are configurable.
  * See DB_result::fetchInto() for more information.
  *
  * This method is not meant to be called directly.  Use
  * DB_result::fetchInto() instead.  It can't be declared "protected"
  * because DB_result is a separate object.
  *
  * @param resource $result    the query result resource
  * @param array    $arr       the referenced array to put the data in
  * @param int      $fetchmode how the resulting array should be indexed
  * @param int      $rownum    the row number to fetch (0 = first row)
  *
  * @return mixed  DB_OK on success, NULL when the end of a result set is
  *                 reached or on failure
  *
  * @see DB_result::fetchInto()
  */
 function fetchInto($result, &$arr, $fetchmode, $rownum = null)
 {
     if ($rownum !== null) {
         if (!@fbsql_data_seek($result, $rownum)) {
             return null;
         }
     }
     if ($fetchmode & DB_FETCHMODE_ASSOC) {
         $arr = @fbsql_fetch_array($result, FBSQL_ASSOC);
         if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
             $arr = array_change_key_case($arr, CASE_LOWER);
         }
     } else {
         $arr = @fbsql_fetch_row($result);
     }
     if (!$arr) {
         return null;
     }
     if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
         $this->_rtrimArrayValues($arr);
     }
     if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
         $this->_convertNullArrayValuesToEmpty($arr);
     }
     return DB_OK;
 }
Example #4
0
 /**
  * Fetch a row and insert the data into an existing array.
  *
  * @param $result fbsql result identifier
  * @param $arr (reference) array where data from the row is stored
  * @param $fetchmode how the array data should be indexed
  * @param   $rownum the row number to fetch
  * @access public
  *
  * @return int DB_OK on success, a DB error on failure
  */
 function fetchInto($result, &$arr, $fetchmode, $rownum = null)
 {
     if ($rownum !== null) {
         if (!@fbsql_data_seek($result, $rownum)) {
             return null;
         }
     }
     if ($fetchmode & DB_FETCHMODE_ASSOC) {
         $arr = @fbsql_fetch_array($result, FBSQL_ASSOC);
     } else {
         $arr = @fbsql_fetch_row($result);
     }
     if (!$arr) {
         $errno = @fbsql_errno($this->connection);
         if (!$errno) {
             return NULL;
         }
         return $this->fbsqlRaiseError($errno);
     }
     return DB_OK;
 }
 /**
  * Fetch a row and return data in an array.
  *
  * @param resource $result result identifier
  * @param int $fetchmode ignored
  * @param int $rownum the row number to fetch
  * @return mixed data array or NULL on success, a MDB error on failure
  * @access public
  */
 function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT, $rownum = NULL)
 {
     $result_value = intval($result);
     if ($rownum == NULL) {
         ++$this->highest_fetched_row[$result_value];
     } else {
         if (!@fbsql_data_seek($result, $rownum)) {
             return NULL;
         }
         $this->highest_fetched_row[$result_value] = max($this->highest_fetched_row[$result_value], $rownum);
     }
     if ($fetchmode == MDB_FETCHMODE_DEFAULT) {
         $fetchmode = $this->fetchmode;
     }
     if ($fetchmode & MDB_FETCHMODE_ASSOC) {
         $row = @fbsql_fetch_assoc($result);
         if (is_array($row) && $this->options['optimize'] == 'portability') {
             $row = array_change_key_case($row, CASE_LOWER);
         }
     } else {
         $row = @fbsql_fetch_row($result);
     }
     if (!$row) {
         if ($this->options['autofree']) {
             $this->freeResult($result);
         }
         return NULL;
     }
     if (isset($this->result_types[$result_value])) {
         $row = $this->convertResultRow($result, $row);
     }
     return $row;
 }
 public function fetchRow()
 {
     if (!empty($this->query)) {
         return fbsql_fetch_row($this->query);
     } else {
         return 0;
     }
 }
Example #7
0
 /**
  * Fetch a row and insert the data into an existing array.
  *
  * @param int       $fetchmode  how the array data should be indexed
  * @param int    $rownum    number of the row where the data can be found
  * @return int data array on success, a MDB2 error on failure
  * @access public
  */
 function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null)
 {
     if (null !== $rownum) {
         $seek = $this->seek($rownum);
         if (MDB2::isError($seek)) {
             return $seek;
         }
     }
     if ($fetchmode == MDB2_FETCHMODE_DEFAULT) {
         $fetchmode = $this->db->fetchmode;
     }
     if ($fetchmode == MDB2_FETCHMODE_ASSOC || $fetchmode == MDB2_FETCHMODE_OBJECT) {
         $row = @fbsql_fetch_assoc($this->result);
         if (is_array($row) && $this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
             $row = array_change_key_case($row, $this->db->options['field_case']);
         }
     } else {
         $row = @fbsql_fetch_row($this->result);
     }
     if (!$row) {
         if (false === $this->result) {
             $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 'resultset has already been freed', __FUNCTION__);
             return $err;
         }
         $null = null;
         return $null;
     }
     $mode = $this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL;
     if ($mode) {
         $this->db->_fixResultArrayValues($row, $mode);
     }
     if ($fetchmode == MDB2_FETCHMODE_ORDERED) {
         if (!empty($this->types)) {
             $row = $this->db->datatype->convertResultRow($this->types, $row, $rtrim);
         }
     } elseif (!empty($this->types_assoc)) {
         $row = $this->db->datatype->convertResultRow($this->types_assoc, $row, $rtrim);
     }
     if (!empty($this->values)) {
         $this->_assignBindColumns($row);
     }
     if ($fetchmode === MDB2_FETCHMODE_OBJECT) {
         $object_class = $this->db->options['fetch_class'];
         if ($object_class == 'stdClass') {
             $row = (object) $row;
         } else {
             $row = new $object_class($row);
         }
     }
     ++$this->rownum;
     return $row;
 }