/**
  * Constructor
  *
  * @param   resource handle
  */
 public function __construct($result, \util\TimeZone $tz = null)
 {
     $fields = [];
     if (is_resource($result)) {
         foreach (sqlsrv_field_metadata($result) as $meta) {
             $fields[$meta['Name']] = $meta;
         }
     }
     parent::__construct($result, $fields, $tz);
 }
 /**
  * Constructor
  *
  * @param   resource handle
  */
 public function __construct($result, TimeZone $tz = NULL)
 {
     $fields = array();
     if (is_resource($result)) {
         foreach (sqlsrv_field_metadata($result) as $meta) {
             $fields[$meta['Name']] = $meta;
         }
     }
     parent::__construct($result, $fields, $tz);
 }
Example #3
0
 public function getResultFields()
 {
     if (empty($this->resultFields)) {
         $fields = sqlsrv_field_metadata($this->resource);
         if ($fields) {
             foreach ($fields as $key => $value) {
                 $this->resultFields[$key] = array("name" => $value["Name"], "type" => $value["Type"]);
             }
         }
     }
     return $this->resultFields;
 }
 /**
  * Field data
  *
  * Generates an array of objects containing field meta-data
  *
  * @access	public
  * @return	array
  */
 function field_data()
 {
     $retval = array();
     foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field) {
         $F = new stdClass();
         $F->name = $field['Name'];
         $F->type = $field['Type'];
         $F->max_length = $field['Size'];
         $F->primary_key = 0;
         $F->default = '';
         $retval[] = $F;
     }
     return $retval;
 }
Example #5
0
 /**
  * Returns an array of fields according to columns in the result.
  *
  * @return \Bitrix\Main\Entity\ScalarField[]
  */
 public function getFields()
 {
     if ($this->resultFields == null) {
         $this->resultFields = array();
         if (is_resource($this->resource)) {
             $fields = sqlsrv_field_metadata($this->resource);
             if ($fields && $this->connection) {
                 $helper = $this->connection->getSqlHelper();
                 foreach ($fields as $value) {
                     $name = $value["Name"] != '' ? $value["Name"] : uniqid();
                     $parameters = array("size" => $value["Size"], "scale" => $value["Scale"]);
                     $this->resultFields[$name] = $helper->getFieldByColumnType($name, $value["Type"], $parameters);
                 }
             }
         }
     }
     return $this->resultFields;
 }
Example #6
0
 public function result_mssqlnative($queryresult = false)
 {
     $this->m_cursor = 0;
     $this->m_rows = array();
     $this->m_num_fields = sqlsrv_num_fields($queryresult);
     $this->m_field_meta = sqlsrv_field_metadata($queryresult);
     while ($row = sqlsrv_fetch_array($queryresult, SQLSRV_FETCH_ASSOC)) {
         if ($row !== null) {
             foreach ($row as $k => $v) {
                 if (is_object($v) && method_exists($v, 'format')) {
                     $row[$k] = $v->format("Y-m-d\\TH:i:s\\Z");
                 }
             }
             $this->m_rows[] = $row;
             //read results into memory, cursors are not supported
         }
     }
     $this->m_row_count = sizeof($this->m_rows);
 }
 function GetFields()
 {
     $_fields = array();
     $_result = sqlsrv_query($this->_Link, $this->SelectCommand);
     $data = sqlsrv_field_metadata($_result);
     //echo "<pre>";
     //print_r($data);
     foreach ($data as $key => $value) {
         $_field = array("Name" => $value['Name'], "Type" => $value['Type'], "Not_Null" => 0);
         array_push($_fields, $_field);
     }
     return $_fields;
     /*while($_prop = sqlsrv_field_metadata($_result))
     		{
     			$_field = array("Name"=>$_prop['Name'],"Type"=>$_prop['Type'],"Not_Null"=>0);
     			array_push($_fields,$_field);
     		}
     		return $_fields;*/
 }
 function sql_field_name($sqltype, $result, $i)
 {
     if ($sqltype == 'mysql') {
         if (class_exists('mysqli_result')) {
             $z = $result->fetch_field();
             return $z->name;
         } elseif (function_exists('mysql_field_name')) {
             return mysql_field_name($result, $i);
         }
     } elseif ($sqltype == 'mssql') {
         if (function_exists('sqlsrv_field_metadata')) {
             $metadata = sqlsrv_field_metadata($result);
             if (is_array($metadata)) {
                 $metadata = $metadata[$i];
             }
             if (is_array($metadata)) {
                 return $metadata['Name'];
             }
         } elseif (function_exists('mssql_field_name')) {
             return mssql_field_name($result, $i);
         }
     } elseif ($sqltype == 'pgsql') {
         return pg_field_name($result, $i);
     } elseif ($sqltype == 'oracle') {
         return oci_field_name($result, $i + 1);
     } elseif ($sqltype == 'sqlite3') {
         return $result->columnName($i);
     } elseif ($sqltype == 'sqlite') {
         return sqlite_field_name($result, $i);
     } elseif ($sqltype == 'odbc') {
         return odbc_field_name($result, $i + 1);
     } elseif ($sqltype == 'pdo') {
         $res = $result->getColumnMeta($i);
         return $res['name'];
     }
 }
Example #9
0
 /**
  * @brief 결과를 fetch
  **/
 function _fetch($result)
 {
     if (!$this->isConnected() || $this->isError() || !$result) {
         return;
     }
     $c = sqlsrv_num_fields($result);
     $m = null;
     $output = array();
     while (sqlsrv_fetch($result)) {
         if (!$m) {
             $m = sqlsrv_field_metadata($result);
         }
         unset($row);
         for ($i = 0; $i < $c; $i++) {
             $row->{$m[$i]['Name']} = sqlsrv_get_field($result, $i, SQLSRV_PHPTYPE_STRING('utf-8'));
         }
         $output[] = $row;
     }
     if (count($output) == 1) {
         return $output[0];
     }
     return $output;
 }
 function FetchField($fieldOffset = -1)
 {
     if ($this->connection->debug) {
         error_log("<hr>fetchfield: {$fieldOffset}, fetch array: <pre>" . print_r($this->fields, true) . "</pre> backtrace: " . adodb_backtrace(false));
     }
     if ($fieldOffset != -1) {
         $this->fieldOffset = $fieldOffset;
     }
     /*$arrKeys = array_keys($this->fields);
     		if(array_key_exists($this->fieldOffset,$arrKeys) && !array_key_exists($arrKeys[$this->fieldOffset],$this->fields)) {
     			$f = false;
     		} else {
     			$f = new ADOFetchObj();
     			$f->name = $arrKeys[$this->fieldOffset];
     			if($fieldOffset == -1) $this->fieldOffset++;
     		}
     
             if (empty($f)) {
                 $f = false;//PHP Notice: Only variable references should be returned by reference
             }*/
     $fieldMeta = @sqlsrv_field_metadata($this->_queryID);
     $f = new ADOFieldObject();
     $f->name = $fieldMeta[$this->fieldOffset]['Name'];
     $f->type = $fieldMeta[$this->fieldOffset]['Type'];
     $f->max_length = $fieldMeta[$this->fieldOffset]['Size'];
     return $f;
 }
 function get_rs_metadata($stmt)
 {
     $metadatas = sqlsrv_field_metadata($stmt);
     $metadataHash = array();
     foreach ($metadatas as $metadata) {
         $metadataHash[$metadata['Name']] = $metadata['Type'];
     }
     return $metadataHash;
 }
Example #12
0
 /**
  * Returns metadata for all columns in a result set.
  * @return array
  */
 public function getResultColumns()
 {
     $columns = [];
     foreach ((array) sqlsrv_field_metadata($this->resultSet) as $fieldMetadata) {
         $columns[] = ['name' => $fieldMetadata['Name'], 'fullname' => $fieldMetadata['Name'], 'nativetype' => $fieldMetadata['Type']];
     }
     return $columns;
 }
Example #13
0
 function _FetchField($fieldOffset = -1)
 {
     $_typeConversion = array(-155 => 'datetimeoffset', -154 => 'time', -152 => 'xml', -151 => 'udt', -11 => 'uniqueidentifier', -10 => 'ntext', -9 => 'nvarchar', -8 => 'nchar', -7 => 'bit', -6 => 'tinyint', -5 => 'bigint', -4 => 'image', -3 => 'varbinary', -2 => 'timestamp', -1 => 'text', 1 => 'char', 2 => 'numeric', 3 => 'decimal', 4 => 'int', 5 => 'smallint', 6 => 'float', 7 => 'real', 12 => 'varchar', 91 => 'date', 93 => 'datetime');
     $fa = @sqlsrv_field_metadata($this->_queryID);
     if ($fieldOffset != -1) {
         $fa = $fa[$fieldOffset];
     }
     $false = false;
     if (empty($fa)) {
         $f = false;
         //PHP Notice: Only variable references should be returned by reference
     } else {
         // Convert to an object
         $fa = array_change_key_case($fa, CASE_LOWER);
         $fb = array();
         if ($fieldOffset != -1) {
             $fb = array('name' => $fa['name'], 'max_length' => $fa['size'], 'column_source' => $fa['name'], 'type' => $_typeConversion[$fa['type']]);
         } else {
             foreach ($fa as $key => $value) {
                 $fb[] = array('name' => $value['name'], 'max_length' => $value['size'], 'column_source' => $value['name'], 'type' => $_typeConversion[$value['type']]);
             }
         }
         $f = (object) $fb;
     }
     return $f;
 }
Example #14
0
 private function _getColumns($tsql, Zend_Db_Adapter_Sqlsrv $db)
 {
     $conn = $db->getConnection();
     $stmt = sqlsrv_prepare($conn, $tsql);
     $data = sqlsrv_field_metadata($stmt);
     $cols = array();
     foreach ($data as $col) {
         $cols[] = $col['Name'];
     }
     return $cols;
 }
 /**
  * Low level handling getting a row from a result set; automatically
  * makes all fetched values strings, just like the other PHP db functions.
  * We have to do this since the sqlsrv extension returns row values in thier
  * native types, which causes problems with how we handle things.
  *
  * @param  resource $result
  * @return array
  */
 private function _fetchRowAssoc($result)
 {
     if (!is_resource($result)) {
         return false;
     }
     $row = array();
     $fieldnames = $this->getFieldsArray($result);
     $fieldMetaData = sqlsrv_field_metadata($result);
     if (sqlsrv_fetch($result)) {
         for ($i = 0; $i < sqlsrv_num_fields($result); $i++) {
             if ($fieldMetaData[$i]['Type'] == -9 || $fieldMetaData[$i]['Type'] >= SQLSRV_SQLTYPE_NVARCHAR(1) && $fieldMetaData[$i]['Type'] <= SQLSRV_SQLTYPE_NVARCHAR(8000) || $fieldMetaData[$i]['Type'] >= SQLSRV_SQLTYPE_NCHAR(1) && $fieldMetaData[$i]['Type'] <= SQLSRV_SQLTYPE_NCHAR(8000) || $fieldMetaData[$i]['Type'] == SQLSRV_SQLTYPE_NVARCHAR('max') || $fieldMetaData[$i]['Type'] == SQLSRV_SQLTYPE_NCHAR('max')) {
                 $row[$fieldnames[$i]] = iconv("utf-16le", "utf-8", sqlsrv_get_field($result, $i, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY)));
             } else {
                 $row[$fieldnames[$i]] = sqlsrv_get_field($result, $i, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
             }
         }
     } else {
         sqlsrv_free_stmt($result);
     }
     return $row;
 }
Example #16
0
 /**
  * Returns metadata for a column in a result set
  *
  * @param integer $column               The 0-indexed column in the result set.
  *
  * @return array                        Associative meta data array with the following structure:
  *
  *          type                 Numeric value that corresponds to a SQL type.
  *          nullable                       An enumerated value indicating whether the column is nullable (SQLSRV_NULLABLE_YES), the column is not nullable (SQLSRV_NULLABLE_NO), or it is not known if the column is nullable (SQLSRV_NULLABLE_UNKNOWN).
  *          name                        Name of the column to which the field corresponds.
  *          size                         The length of this column. Normally -1 for types other than floating point decimals.
  *          precision                   The numeric precision of this column. Normally 0 for types other than floating point decimals.
  *          scale                    The scale for types of variable scale (numeric, decimal, datetime2, datetimeoffset, and time). NULL for other SQL Server data types.
  */
 public function getColumnMeta($column)
 {
     $data = sqlsrv_field_metadata($this->statement);
     if (is_integer($column)) {
         $internal_column = $column + 1;
     } else {
         throw new Doctrine_Adapter_Exception("Unsupported column: {$column}");
     }
     if (!isset($data[$internal_column])) {
         return false;
     }
     return $data[$internal_column];
 }
function sql_field_name($sqltype, $hasil, $i)
{
    if ($sqltype == 'mysql') {
        if (function_exists('mysql_field_name')) {
            return mysql_field_name($hasil, $i);
        }
    } elseif ($sqltype == 'mssql') {
        if (function_exists('mssql_field_name')) {
            return mssql_field_name($hasil, $i);
        } elseif (function_exists('sqlsrv_field_metadata')) {
            $metadata = sqlsrv_field_metadata($hasil);
            if (is_array($metadata)) {
                $metadata = $metadata[$i];
            }
            if (is_array($metadata)) {
                return $metadata['Name'];
            }
        }
    } elseif ($sqltype == 'pgsql') {
        if (function_exists('pg_field_name')) {
            return pg_field_name($hasil, $i);
        }
    } elseif ($sqltype == 'oracle') {
        if (function_exists('oci_field_name')) {
            return oci_field_name($hasil, $i + 1);
        }
    } elseif ($sqltype == 'sqlite3') {
        if (class_exists('SQLite3')) {
            return $hasil->columnName($i);
        }
    } elseif ($sqltype == 'sqlite') {
        if (function_exists('sqlite_field_name')) {
            return sqlite_field_name($hasil, $i);
        }
    } elseif ($sqltype == 'odbc') {
        if (function_exists('odbc_field_name')) {
            return odbc_field_name($hasil, $i + 1);
        }
    } elseif ($sqltype == 'pdo') {
        if (class_exists('PDO')) {
            $res = $hasil->getColumnMeta($i);
            return $res['name'];
        }
    }
}
Example #18
0
 /**
  * Returns metadata for all columns in a result set.
  * @return array
  */
 public function getResultColumns()
 {
     $count = sqlsrv_num_fields($this->resultSet);
     $columns = array();
     for ($i = 0; $i < $count; $i++) {
         $row = (array) sqlsrv_field_metadata($this->resultSet, $i);
         $columns[] = array('name' => $row['Name'], 'fullname' => $row['Name'], 'nativetype' => $row['Type']);
     }
     return $columns;
 }
Example #19
0
 function query($query)
 {
     //if flag to convert query from MySql syntax to MS-Sql syntax is true
     //convert the query
     if ($this->convertMySqlToMSSqlQuery == true) {
         $query = $this->ConvertMySqlToMSSql($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->dbname, $this->dbhost);
     }
     // Perform the query via std mssql_query function..
     $this->result = @sqlsrv_query($this->dbh, $query);
     // If there is an error then take note of it..
     if ($this->result === false) {
         $errors = sqlsrv_errors();
         if (!empty($errors)) {
             $is_insert = true;
             foreach ($errors as $error) {
                 $sqlError = "ErrorCode: " . $error['code'] . " ### State: " . $error['SQLSTATE'] . " ### Error Message: " . $error['message'] . " ### Query: " . $query;
                 $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 = @sqlsrv_rows_affected($this->dbh);
         // Take note of the insert_id
         if (preg_match("/^(insert|replace)\\s+/i", $query)) {
             $identityresultset = @sqlsrv_query($this->dbh, "select SCOPE_IDENTITY()");
             if ($identityresultset != false) {
                 $identityrow = @sqlsrv_fetch($identityresultset);
                 $this->insert_id = $identityrow[0];
             }
         }
         // Return number of rows affected
         $return_val = $this->rows_affected;
     } else {
         // Take note of column info
         $i = 0;
         foreach (@sqlsrv_field_metadata($this->result) as $field) {
             foreach ($field as $name => $value) {
                 $name = strtolower($name);
                 if ($name == "size") {
                     $name = "max_length";
                 } else {
                     if ($name == "type") {
                         $name = "typeid";
                     }
                 }
                 $col->{$name} = $value;
             }
             $col->type = $this->get_datatype($col);
             $this->col_info[$i++] = $col;
             unset($col);
         }
         // Store Query Results
         $num_rows = 0;
         while ($row = @sqlsrv_fetch_object($this->result)) {
             // Store relults as an objects within main array
             $this->last_result[$num_rows] = $row;
             $num_rows++;
         }
         @sqlsrv_free_stmt($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;
 }
Example #20
0
 /**
  * Move the internal result pointer to the next available result
  *
  * @return true on success, false if there is no more result set or an error object on failure
  * @access public
  */
 function nextResult()
 {
     if (false === $this->result) {
         return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, 'resultset has already been freed', __FUNCTION__);
     }
     if (null === $this->result) {
         return false;
     }
     $ret = sqlsrv_next_result($this->result);
     if ($ret) {
         $this->cursor = 0;
         $this->rows = array();
         $this->numFields = sqlsrv_num_fields($this->result);
         $this->fieldMeta = sqlsrv_field_metadata($this->result);
         $this->numRowsAffected = sqlsrv_rows_affected($this->result);
         while ($row = sqlsrv_fetch_array($this->result, SQLSRV_FETCH_ASSOC)) {
             if ($row !== null) {
                 if ($this->offset && $this->offset_count < $this->offset) {
                     $this->offset_count++;
                     continue;
                 }
                 foreach ($row as $k => $v) {
                     if (is_object($v) && method_exists($v, 'format')) {
                         //DateTime Object
                         //$v->setTimezone(new DateTimeZone('GMT'));//TS_ISO_8601 with a trailing 'Z' is GMT
                         $row[$k] = $v->format("Y-m-d H:i:s");
                     }
                 }
                 $this->rows[] = $row;
                 //read results into memory, cursors are not supported
             }
         }
         $this->rowcnt = count($this->rows);
     }
     return $ret;
 }
Example #21
0
 protected function fetch_fields($result)
 {
     //var_dump(sqlsrv_field_metadata($result));
     return array_map(function ($a) {
         $p = array();
         foreach ($a as $k => $v) {
             $p[strtolower($k)] = $v;
         }
         return (object) $p;
     }, sqlsrv_field_metadata($result));
 }
Example #22
0
 /**
  * Field data
  *
  * Generates an array of objects containing field meta-data
  *
  * @return	array
  */
 public function field_data()
 {
     $retval = [];
     foreach (sqlsrv_field_metadata($this->result_id) as $i => $field) {
         $retval[$i] = new stdClass();
         $retval[$i]->name = $field['Name'];
         $retval[$i]->type = $field['Type'];
         $retval[$i]->max_length = $field['Size'];
     }
     return $retval;
 }
Example #23
0
 /**
  * Enter description here...
  *
  * @param unknown_type $results
  */
 function resultSet(&$results)
 {
     $this->results =& $results;
     $this->map = array();
     $index = 0;
     foreach (sqlsrv_field_metadata($results) as $fieldMetadata) {
         $column = $fieldMetadata['Name'];
         if (strpos($column, '__')) {
             if (isset($this->__fieldMappings[$column]) && strpos($this->__fieldMappings[$column], '.')) {
                 $map = explode('.', $this->__fieldMappings[$column]);
             } elseif (isset($this->__fieldMappings[$column])) {
                 $map = array(0, $this->__fieldMappings[$column]);
             } else {
                 $map = array(0, $column);
             }
             $this->map[$index++] = $map;
         } else {
             $this->map[$index++] = array(0, $column);
         }
     }
 }
 /**
  * @see DBManager::getFieldsArray()
  */
 public function getFieldsArray($result, $make_lower_case = false)
 {
     $field_array = array();
     if (!$result) {
         return false;
     }
     foreach (sqlsrv_field_metadata($result) as $fieldMetadata) {
         $key = $fieldMetadata['Name'];
         if ($make_lower_case == true) {
             $key = strtolower($key);
         }
         $field_array[] = $key;
     }
     return $field_array;
 }
Example #25
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;
 }
Example #26
0
 public function __construct($queryresult = false)
 {
     $this->mCursor = 0;
     $this->mRows = array();
     $this->mNumFields = sqlsrv_num_fields($queryresult);
     $this->mFieldMeta = sqlsrv_field_metadata($queryresult);
     $rows = sqlsrv_fetch_array($queryresult, SQLSRV_FETCH_ASSOC);
     foreach ($rows as $row) {
         if ($row !== null) {
             foreach ($row as $k => $v) {
                 if (is_object($v) && method_exists($v, 'format')) {
                     // DateTime Object
                     $row[$k] = $v->format("Y-m-d\\TH:i:s\\Z");
                 }
             }
             $this->mRows[] = $row;
             // read results into memory, cursors are not supported
         }
     }
     $this->mRowCount = count($this->mRows);
     sqlsrv_free_stmt($queryresult);
 }
 function _initrs()
 {
     global $ADODB_COUNTRECS;
     if ($this->connection->debug) {
         error_log("(before) ADODB_COUNTRECS: {$ADODB_COUNTRECS} _numOfRows: {$this->_numOfRows} _numOfFields: {$this->_numOfFields}");
     }
     /*$retRowsAff = sqlsrv_rows_affected($this->_queryID);//"If you need to determine the number of rows a query will return before retrieving the actual results, appending a SELECT COUNT ... query would let you get that information, and then a call to next_result would move you to the "real" results."
             error_log("rowsaff: ".serialize($retRowsAff));
     		$this->_numOfRows = ($ADODB_COUNTRECS)? $retRowsAff:-1;*/
     $this->_numOfRows = -1;
     //not supported
     $fieldmeta = sqlsrv_field_metadata($this->_queryID);
     $this->_numOfFields = $fieldmeta ? count($fieldmeta) : -1;
     if ($this->connection->debug) {
         error_log("(after) _numOfRows: {$this->_numOfRows} _numOfFields: {$this->_numOfFields}");
     }
 }
 public function nextRecord()
 {
     if (!is_resource($this->handle)) {
         return false;
     }
     // Coalesce rather than replace common fields.
     $output = array();
     if ($this->mssql) {
         if ($data = mssql_fetch_row($this->handle)) {
             foreach ($data as $columnIdx => $value) {
                 $columnName = mssql_field_name($this->handle, $columnIdx);
                 // There are many places in the framework that expect the ID to be a string, not a double
                 // Do not set this to an integer, or it will cause failures in many tests that expect a string
                 if ($columnName == 'ID') {
                     $value = (string) $value;
                 }
                 // $value || !$ouput[$columnName] means that the *last* occurring value is shown
                 // !$ouput[$columnName] means that the *first* occurring value is shown
                 if (isset($value) || !isset($output[$columnName])) {
                     $output[$columnName] = $value;
                 }
             }
             return $output;
         }
     } else {
         if ($this->handle && ($data = sqlsrv_fetch_array($this->handle, SQLSRV_FETCH_NUMERIC))) {
             $fields = sqlsrv_field_metadata($this->handle);
             foreach ($fields as $columnIdx => $field) {
                 $value = $data[$columnIdx];
                 if ($value instanceof DateTime) {
                     $value = $value->format('Y-m-d H:i:s');
                 }
                 // $value || !$ouput[$columnName] means that the *last* occurring value is shown
                 // !$ouput[$columnName] means that the *first* occurring value is shown
                 if (isset($value) || !isset($output[$field['Name']])) {
                     $output[$field['Name']] = $value;
                 }
             }
             return $output;
         } else {
             // Free the handle if there are no more results - sqlsrv crashes if there are too many handles
             if ($this->handle) {
                 sqlsrv_free_stmt($this->handle);
                 $this->handle = null;
             }
         }
     }
     return false;
 }
Example #29
0
 /**
  * Returns metadata for a column in a result set.
  *
  * @param int $column
  * @return mixed
  * @throws Zend_Db_Statement_Sqlsrv_Exception
  */
 public function getColumnMeta($column)
 {
     $fields = sqlsrv_field_metadata($this->_stmt);
     if (!$fields) {
         throw new Zend_Db_Statement_Sqlsrv_Exception('Column metadata can not be fetched');
     }
     if (!isset($fields[$column])) {
         throw new Zend_Db_Statement_Sqlsrv_Exception('Column index does not exist in statement');
     }
     return $fields[$column];
 }
Example #30
0
 /**
  * @param mixed $res
  * @param int $n
  * @return int
  */
 public function fieldName($res, $n)
 {
     if ($res instanceof ResultWrapper) {
         $res = $res->result;
     }
     $metadata = sqlsrv_field_metadata($res);
     return $metadata[$n]['Name'];
 }