Exemple #1
0
 /**
  * Returns information about a table or a result set
  *
  * @param object|string  $result  MDB2_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 MDB2_Error object on failure.
  *
  * @see MDB2_Driver_Common::tableInfo()
  */
 function tableInfo($result, $mode = null)
 {
     if (is_string($result)) {
         return parent::tableInfo($result, $mode);
     }
     $db =& $this->getDBInstance();
     if (MDB2::isError($db)) {
         return $db;
     }
     $resource = MDB2::isResultCommon($result) ? $result->getResource() : $result;
     if (!is_resource($resource)) {
         return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 'Could not generate result resource', __FUNCTION__);
     }
     if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
         if ($db->options['field_case'] == CASE_LOWER) {
             $case_func = 'strtolower';
         } else {
             $case_func = 'strtoupper';
         }
     } else {
         $case_func = 'strval';
     }
     $count = @fbsql_num_fields($resource);
     $res = array();
     if ($mode) {
         $res['num_fields'] = $count;
     }
     for ($i = 0; $i < $count; $i++) {
         $res[$i] = array('table' => $case_func(@fbsql_field_table($resource, $i)), 'name' => $case_func(@fbsql_field_name($resource, $i)), 'type' => @fbsql_field_type($resource, $i), 'length' => @fbsql_field_len($resource, $i), 'flags' => @fbsql_field_flags($resource, $i));
         // todo: implement $db->datatype->mapNativeDatatype();
         $res[$i]['mdb2type'] = $res[$i]['type'];
         if ($mode & MDB2_TABLEINFO_ORDER) {
             $res['order'][$res[$i]['name']] = $i;
         }
         if ($mode & MDB2_TABLEINFO_ORDERTABLE) {
             $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
         }
     }
     return $res;
 }
Exemple #2
0
 /**
  * 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  MDB2_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 MDB2_Error object on failure.
  *
  * @see MDB2_Driver_Common::tableInfo()
  */
 function tableInfo($result, $mode = null)
 {
     if (is_string($result)) {
         return parent::tableInfo($result, $mode);
     }
     $db = $this->getDBInstance();
     if (PEAR::isError($db)) {
         return $db;
     }
     $resource = MDB2::isResultCommon($result) ? $result->getResource() : $result;
     if (!is_resource($resource)) {
         return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 'Could not generate result resource', __FUNCTION__);
     }
     if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
         if ($db->options['field_case'] == CASE_LOWER) {
             $case_func = 'strtolower';
         } else {
             $case_func = 'strtoupper';
         }
     } else {
         $case_func = 'strval';
     }
     $meta = @sqlsrv_field_metadata($resource);
     $count = count($meta);
     $res = array();
     if ($mode) {
         $res['num_fields'] = $count;
     }
     $db->loadModule('Datatype', null, true);
     for ($i = 0; $i < $count; $i++) {
         $res[$i] = array('table' => '', 'name' => $case_func($meta[$i]['Name']), 'type' => $meta[$i]['Type'], 'length' => $meta[$i]['Size'], 'numeric_precision' => $meta[$i]['Precision'], 'numeric_scale' => $meta[$i]['Scale'], 'flags' => '');
         $mdb2type_info = $db->datatype->mapNativeDatatype($res[$i]);
         if (PEAR::isError($mdb2type_info)) {
             return $mdb2type_info;
         }
         $res[$i]['mdb2type'] = $mdb2type_info[0][0];
         if ($mode & MDB2_TABLEINFO_ORDER) {
             $res['order'][$res[$i]['name']] = $i;
         }
         if ($mode & MDB2_TABLEINFO_ORDERTABLE) {
             $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
         }
     }
     return $res;
 }
Exemple #3
0
 /**
  * Returns information about a table
  *
  * @param string         $result  a string containing the name of a table
  * @param int            $mode    a valid tableInfo mode
  *
  * @return array  an associative array with the information requested.
  *                 A MDB2_Error object on failure.
  *
  * @see MDB2_Driver_Common::tableInfo()
  * @since Method available since Release 1.7.0
  */
 function tableInfo($result, $mode = null)
 {
     if (is_string($result)) {
         return parent::tableInfo($result, $mode);
     }
     $db =& $this->getDBInstance();
     if (PEAR::isError($db)) {
         return $db;
     }
     return $db->raiseError(MDB2_ERROR_NOT_CAPABLE, null, null, 'This DBMS can not obtain tableInfo from result sets', __FUNCTION__);
 }
 /**
  * Returns information about a table or a result set
  *
  * @param object|string  $result  MDB2_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 MDB2_Error object on failure.
  *
  * @see MDB2_Driver_Common::setOption()
  */
 function tableInfo($result, $mode = null)
 {
     if (is_string($result)) {
         return parent::tableInfo($result, $mode);
     }
     $db =& $this->getDBInstance();
     if (PEAR::isError($db)) {
         return $db;
     }
     $resource = MDB2::isResultCommon($result) ? $result->getResource() : $result;
     if (!is_object($resource)) {
         return $db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 'Could not generate result resource', __FUNCTION__);
     }
     if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
         if ($db->options['field_case'] == CASE_LOWER) {
             $case_func = 'strtolower';
         } else {
             $case_func = 'strtoupper';
         }
     } else {
         $case_func = 'strval';
     }
     $count = @mysqli_num_fields($resource);
     $res = array();
     if ($mode) {
         $res['num_fields'] = $count;
     }
     $db->loadModule('Datatype', null, true);
     for ($i = 0; $i < $count; $i++) {
         $tmp = @mysqli_fetch_field($resource);
         $flags = '';
         foreach ($this->flags as $const => $means) {
             if ($tmp->flags & $const) {
                 $flags .= $means . ' ';
             }
         }
         if ($tmp->def) {
             $flags .= 'default_' . rawurlencode($tmp->def);
         }
         $flags = trim($flags);
         $res[$i] = array('table' => $case_func($tmp->table), 'name' => $case_func($tmp->name), 'type' => isset($this->types[$tmp->type]) ? $this->types[$tmp->type] : 'unknown', 'length' => $tmp->length, 'flags' => $flags);
         $mdb2type_info = $db->datatype->mapNativeDatatype($res[$i]);
         if (PEAR::isError($mdb2type_info)) {
             return $mdb2type_info;
         }
         $res[$i]['mdb2type'] = $mdb2type_info[0][0];
         if ($mode & MDB2_TABLEINFO_ORDER) {
             $res['order'][$res[$i]['name']] = $i;
         }
         if ($mode & MDB2_TABLEINFO_ORDERTABLE) {
             $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
         }
     }
     return $res;
 }
Exemple #5
0
 /**
  * wrap a result set into the correct class
  *
  * @param   resource result handle
  * @param   mixed   array that contains the types of the columns in
  *                        the result set
  * @param   mixed   string which specifies which result class to use
  * @param   mixed   string which specifies which class to wrap results in
  * @param   string  number of rows to select
  * @param   string  first row to select
  *
  * @return mixed   an MDB2_Result, a MDB2 error on failure
  */
 protected function _wrapResult($result_resource, $types = array(), $result_class = true, $result_wrap_class = true, $limit = null, $offset = null)
 {
     if ($types === true) {
         if ($this->supports('result_introspection')) {
             $this->loadModule('Reverse', null, true);
             $tableInfo = $this->reverse->tableInfo($result_resource);
             if (MDB2::isError($tableInfo)) {
                 return $tableInfo;
             }
             $types = array();
             $types_assoc = array();
             foreach ($tableInfo as $field) {
                 $types[] = $field['mdb2type'];
                 $types_assoc[$field['name']] = $field['mdb2type'];
             }
         } else {
             $types = null;
         }
     }
     if ($result_class === true) {
         $result_class = $this->options['result_buffering'] ? $this->options['buffered_result_class'] : $this->options['result_class'];
     }
     if ($result_class) {
         $class_name = sprintf($result_class, $this->phptype);
         if (!MDB2::classExists($class_name)) {
             $err = MDB2_Driver_Common::raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'result class does not exist ' . $class_name, __FUNCTION__);
             return $err;
         }
         $result = new $class_name($this, $result_resource, $limit, $offset);
         if (!MDB2::isResultCommon($result)) {
             $err = MDB2_Driver_Common::raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'result class is not extended from MDB2_Result_Common', __FUNCTION__);
             return $err;
         }
         if (!empty($types)) {
             $err = $result->setResultTypes($types);
             if (MDB2::isError($err)) {
                 $result->free();
                 return $err;
             }
         }
         if (!empty($types_assoc)) {
             $err = $result->setResultTypes($types_assoc);
             if (MDB2::isError($err)) {
                 $result->free();
                 return $err;
             }
         }
         if ($result_wrap_class === true) {
             $result_wrap_class = $this->options['result_wrap_class'];
         }
         if ($result_wrap_class) {
             if (!MDB2::classExists($result_wrap_class)) {
                 $err = MDB2_Driver_Common::raiseError(MDB2_ERROR_NOT_FOUND, null, null, 'result wrap class does not exist ' . $result_wrap_class, __FUNCTION__);
                 return $err;
             }
             $result = new $result_wrap_class($result, $this->fetchmode);
         }
         return $result;
     }
     return $result_resource;
 }