/**
  * Constructor
  *
  * @param   resource handle
  */
 public function __construct($result, TimeZone $tz = NULL)
 {
     $fields = array();
     if (is_resource($result)) {
         for ($i = 0, $num = sybase_num_fields($result); $i < $num; $i++) {
             $field = sybase_fetch_field($result, $i);
             $fields[$field->name] = $field->type;
         }
     }
     parent::__construct($result, $fields, $tz);
 }
 /**
  * Field data
  *
  * Generates an array of objects containing field meta-data
  *
  * @access	public
  * @return	array
  */
 function field_data()
 {
     $retval = array();
     while ($field = sybase_fetch_field($this->result_id)) {
         $F = new stdClass();
         $F->name = $field->name;
         $F->type = $field->type;
         $F->max_length = $field->max_length;
         $F->primary_key = 0;
         $F->default = '';
         $retval[] = $F;
     }
     return $retval;
 }
 /**
  * Returns information about a table or a result set
  *
  * NOTE: only supports 'table' and 'flags' if <var>$result</var>
  * is a table name.
  *
  * @param object|string  $result  DB_result object from a query or a
  *                                 string containing the name of a table.
  *                                 While this also accepts a query result
  *                                 resource identifier, this behavior is
  *                                 deprecated.
  * @param int            $mode    a valid tableInfo mode
  *
  * @return array  an associative array with the information requested.
  *                 A DB_Error object on failure.
  *
  * @see DB_common::tableInfo()
  * @since Method available since Release 1.6.0
  */
 function tableInfo($result, $mode = null)
 {
     if (is_string($result)) {
         /*
          * Probably received a table name.
          * Create a result resource identifier.
          */
         if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) {
             return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED);
         }
         $id = @sybase_query("SELECT * FROM {$result} WHERE 1=0", $this->connection);
         $got_string = true;
     } elseif (isset($result->result)) {
         /*
          * Probably received a result object.
          * Extract the result resource identifier.
          */
         $id = $result->result;
         $got_string = false;
     } else {
         /*
          * Probably received a result resource identifier.
          * Copy it.
          * Deprecated.  Here for compatibility only.
          */
         $id = $result;
         $got_string = false;
     }
     if (!is_resource($id)) {
         return $this->sybaseRaiseError(DB_ERROR_NEED_MORE_DATA);
     }
     if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
         $case_func = 'strtolower';
     } else {
         $case_func = 'strval';
     }
     $count = @sybase_num_fields($id);
     $res = array();
     if ($mode) {
         $res['num_fields'] = $count;
     }
     for ($i = 0; $i < $count; $i++) {
         $f = @sybase_fetch_field($id, $i);
         // column_source is often blank
         $res[$i] = array('table' => $got_string ? $case_func($result) : $case_func($f->column_source), 'name' => $case_func($f->name), 'type' => $f->type, 'len' => $f->max_length, 'flags' => '');
         if ($res[$i]['table']) {
             $res[$i]['flags'] = $this->_sybase_field_flags($res[$i]['table'], $res[$i]['name']);
         }
         if ($mode & DB_TABLEINFO_ORDER) {
             $res['order'][$res[$i]['name']] = $i;
         }
         if ($mode & DB_TABLEINFO_ORDERTABLE) {
             $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
         }
     }
     // free the result only if we were called on a table
     if ($got_string) {
         @sybase_free_result($id);
     }
     return $res;
 }
 function FetchField($fieldOffset = -1)
 {
     if ($fieldOffset != -1) {
         $o = @sybase_fetch_field($this->_queryID, $fieldOffset);
     } else {
         if ($fieldOffset == -1) {
             /*	The $fieldOffset argument is not provided thus its -1 	*/
             $o = @sybase_fetch_field($this->_queryID);
         }
     }
     // older versions of PHP did not support type, only numeric
     if ($o && !isset($o->type)) {
         $o->type = $o->numeric ? 'float' : 'varchar';
     }
     return $o;
 }
 /**
  * Enter description here...
  *
  * @param unknown_type $results
  */
 function resultSet(&$results)
 {
     $this->results =& $results;
     $this->map = array();
     $num_fields = sybase_num_fields($results);
     $index = 0;
     $j = 0;
     while ($j < $num_fields) {
         $column = sybase_fetch_field($results, $j);
         if (!empty($column->table)) {
             $this->map[$index++] = array($column->table, $column->name);
         } else {
             $this->map[$index++] = array(0, $column->name);
         }
         $j++;
     }
 }
Example #6
0
 protected function _table_name($field)
 {
     return sybase_fetch_field($this->_result, $field)->column_source;
 }
Example #7
0
 /**
  * Get column information
  * @param integer
  * @return object
  */
 protected function fetch_field($intOffset)
 {
     return @sybase_fetch_field($this->resResult, $intOffset);
 }
 function query($query)
 {
     //if flag to convert query from MySql syntax to Sybase syntax is true
     //convert the query
     if ($this->convertMySqlTosybaseQuery == true) {
         $query = $this->ConvertMySqlTosybase($query);
     }
     // Initialise return
     $return_val = 0;
     // Flush cached values..
     $this->flush();
     // For reg expressions
     $query = trim($query);
     // Log how the function was called
     $this->func_call = "\$db->query(\"{$query}\")";
     // Keep track of the last query for debug..
     $this->last_query = $query;
     // Count how many queries there have been
     $this->num_queries++;
     // Use core file cache function
     if ($cache = $this->get_cache($query)) {
         return $cache;
     }
     // If there is no existing database connection then try to connect
     if (!isset($this->dbh) || !$this->dbh) {
         $this->connect($this->dbuser, $this->dbpassword, $this->dbhost);
         $this->select($this->dbname);
     }
     // Perform the query via std sybase_query function..
     $this->result = @sybase_query($query);
     // If there is an error then take note of it..
     if ($this->result == false) {
         $get_errorcodeSql = "SELECT @@ERROR as errorcode";
         $error_res = @sybase_query($get_errorcodeSql, $this->dbh);
         $errorCode = @sybase_result($error_res, 0, "errorcode");
         $get_errorMessageSql = "SELECT severity as errorSeverity, text as errorText FROM sys.messages  WHERE message_id = " . $errorCode;
         $errormessage_res = @sybase_query($get_errorMessageSql, $this->dbh);
         if ($errormessage_res) {
             $errorMessage_Row = @sybase_fetch_row($errormessage_res);
             $errorSeverity = $errorMessage_Row[0];
             $errorMessage = $errorMessage_Row[1];
         }
         $sqlError = "ErrorCode: " . $errorCode . " ### Error Severity: " . $errorSeverity . " ### Error Message: " . $errorMessage . " ### Query: " . $query;
         $is_insert = true;
         $this->register_error($sqlError);
         $this->show_errors ? trigger_error($sqlError, E_USER_WARNING) : null;
         return false;
     }
     // Query was an insert, delete, update, replace
     $is_insert = false;
     if (preg_match("/^(insert|delete|update|replace)\\s+/i", $query)) {
         $this->rows_affected = @sybase_rows_affected($this->dbh);
         // Take note of the insert_id
         if (preg_match("/^(insert|replace)\\s+/i", $query)) {
             $identityresultset = @sybase_query("select SCOPE_IDENTITY()");
             if ($identityresultset != false) {
                 $identityrow = @sybase_fetch_row($identityresultset);
                 $this->insert_id = $identityrow[0];
             }
         }
         // Return number of rows affected
         $return_val = $this->rows_affected;
     } else {
         // Take note of column info
         $i = 0;
         while ($i < @sybase_num_fields($this->result)) {
             $this->col_info[$i] = @sybase_fetch_field($this->result);
             $i++;
         }
         // Store Query Results
         $num_rows = 0;
         while ($row = @sybase_fetch_object($this->result)) {
             // Store relults as an objects within main array
             $this->last_result[$num_rows] = $row;
             $num_rows++;
         }
         @sybase_free_result($this->result);
         // Log number of rows the query returned
         $this->num_rows = $num_rows;
         // Return number of rows selected
         $return_val = $this->num_rows;
     }
     // disk caching of queries
     $this->store_cache($query, $is_insert);
     // If debug ALL queries
     $this->trace || $this->debug_all ? $this->debug() : null;
     return $return_val;
 }
 function IsTimestamp($vField)
 {
     if (!$this->res) {
         return false;
     }
     $o = sybase_fetch_field($this->res, $vField);
     return $o['type'] == 'datetime' && strlen($this->f($vField)) > 10;
 }
 public function columns()
 {
     if (empty($this->query)) {
         return false;
     }
     $columns = array();
     $num_fields = $this->num_fields();
     for ($i = 0; $i < $num_fields; $i++) {
         $columns[] = sybase_fetch_field($this->query, $i);
     }
     return $columns;
 }
Example #11
0
 private function _getTextFields($result)
 {
     if ($this->_result == $result) {
         return $this->_text_fields;
     }
     $this->_result = $result;
     $this->_text_fields = array();
     for ($i = sybase_num_fields($result) - 1; $i >= 0; $i--) {
         $type = sybase_fetch_field($result, $i);
         if (!$type->numeric) {
             $this->_text_fields[$type->name] = $type->type;
         }
     }
     return $this->_text_fields;
 }