Skip to content

Commit 803c6d9

Browse files
committed
ci 3.1.6
1 parent 7b7a9d6 commit 803c6d9

16 files changed

Lines changed: 172 additions & 90 deletions

system/core/CodeIgniter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
* @var string
5656
*
5757
*/
58-
const CI_VERSION = '3.1.5';
58+
const CI_VERSION = '3.1.6';
5959

6060
/*
6161
* ------------------------------------------------------

system/core/Loader.php

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function is_loaded($class)
182182
* Loads and instantiates libraries.
183183
* Designed to be called from application controllers.
184184
*
185-
* @param string $library Library name
185+
* @param mixed $library Library name
186186
* @param array $params Optional parameters to pass to the library class constructor
187187
* @param string $object_name An optional object name to assign to
188188
* @return object
@@ -1037,6 +1037,26 @@ protected function _ci_load_library($class, $params = NULL, $object_name = NULL)
10371037
return $this->_ci_load_stock_library($class, $subdir, $params, $object_name);
10381038
}
10391039

1040+
// Safety: Was the class already loaded by a previous call?
1041+
if (class_exists($class, FALSE))
1042+
{
1043+
$property = $object_name;
1044+
if (empty($property))
1045+
{
1046+
$property = strtolower($class);
1047+
isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property];
1048+
}
1049+
1050+
$CI =& get_instance();
1051+
if (isset($CI->$property))
1052+
{
1053+
log_message('debug', $class.' class already loaded. Second attempt ignored.');
1054+
return;
1055+
}
1056+
1057+
return $this->_ci_init_library($class, '', $params, $object_name);
1058+
}
1059+
10401060
// Let's search for the requested library file and load it.
10411061
foreach ($this->_ci_library_paths as $path)
10421062
{
@@ -1047,27 +1067,8 @@ protected function _ci_load_library($class, $params = NULL, $object_name = NULL)
10471067
}
10481068

10491069
$filepath = $path.'libraries/'.$subdir.$class.'.php';
1050-
1051-
// Safety: Was the class already loaded by a previous call?
1052-
if (class_exists($class, FALSE))
1053-
{
1054-
// Before we deem this to be a duplicate request, let's see
1055-
// if a custom object name is being supplied. If so, we'll
1056-
// return a new instance of the object
1057-
if ($object_name !== NULL)
1058-
{
1059-
$CI =& get_instance();
1060-
if ( ! isset($CI->$object_name))
1061-
{
1062-
return $this->_ci_init_library($class, '', $params, $object_name);
1063-
}
1064-
}
1065-
1066-
log_message('debug', $class.' class already loaded. Second attempt ignored.');
1067-
return;
1068-
}
10691070
// Does the file exist? No? Bummer...
1070-
elseif ( ! file_exists($filepath))
1071+
if ( ! file_exists($filepath))
10711072
{
10721073
continue;
10731074
}
@@ -1112,16 +1113,17 @@ protected function _ci_load_stock_library($library_name, $file_path, $params, $o
11121113
$prefix = config_item('subclass_prefix');
11131114
}
11141115

1115-
// Before we deem this to be a duplicate request, let's see
1116-
// if a custom object name is being supplied. If so, we'll
1117-
// return a new instance of the object
1118-
if ($object_name !== NULL)
1116+
$property = $object_name;
1117+
if (empty($property))
11191118
{
1120-
$CI =& get_instance();
1121-
if ( ! isset($CI->$object_name))
1122-
{
1123-
return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
1124-
}
1119+
$property = strtolower($library_name);
1120+
isset($this->_ci_varmap[$property]) && $property = $this->_ci_varmap[$property];
1121+
}
1122+
1123+
$CI =& get_instance();
1124+
if ( ! isset($CI->$property))
1125+
{
1126+
return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
11251127
}
11261128

11271129
log_message('debug', $library_name.' class already loaded. Second attempt ignored.');
@@ -1143,10 +1145,8 @@ protected function _ci_load_stock_library($library_name, $file_path, $params, $o
11431145
{
11441146
return $this->_ci_init_library($library_name, $prefix, $params, $object_name);
11451147
}
1146-
else
1147-
{
1148-
log_message('debug', $path.' exists, but does not declare '.$prefix.$library_name);
1149-
}
1148+
1149+
log_message('debug', $path.' exists, but does not declare '.$prefix.$library_name);
11501150
}
11511151
}
11521152

@@ -1164,10 +1164,8 @@ protected function _ci_load_stock_library($library_name, $file_path, $params, $o
11641164
$prefix = config_item('subclass_prefix');
11651165
break;
11661166
}
1167-
else
1168-
{
1169-
log_message('debug', $path.' exists, but does not declare '.$subclass);
1170-
}
1167+
1168+
log_message('debug', $path.' exists, but does not declare '.$subclass);
11711169
}
11721170
}
11731171

system/database/DB_driver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,7 @@ public function trans_begin($test_mode = FALSE)
916916

917917
if ($this->_trans_begin())
918918
{
919+
$this->_trans_status = TRUE;
919920
$this->_trans_depth++;
920921
return TRUE;
921922
}
@@ -1044,7 +1045,7 @@ public function compile_binds($sql, $binds)
10441045
*/
10451046
public function is_write_type($sql)
10461047
{
1047-
return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX)\s/i', $sql);
1048+
return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX|MERGE)\s/i', $sql);
10481049
}
10491050

10501051
// --------------------------------------------------------------------

system/database/DB_query_builder.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,11 +1403,9 @@ public function count_all_results($table = '', $reset = TRUE)
14031403
// ORDER BY usage is often problematic here (most notably
14041404
// on Microsoft SQL Server) and ultimately unnecessary
14051405
// for selecting COUNT(*) ...
1406-
if ( ! empty($this->qb_orderby))
1407-
{
1408-
$orderby = $this->qb_orderby;
1409-
$this->qb_orderby = NULL;
1410-
}
1406+
$qb_orderby = $this->qb_orderby;
1407+
$qb_cache_orderby = $this->qb_cache_orderby;
1408+
$this->qb_orderby = $this->qb_cache_orderby = NULL;
14111409

14121410
$result = ($this->qb_distinct === TRUE OR ! empty($this->qb_groupby) OR ! empty($this->qb_cache_groupby) OR $this->qb_limit OR $this->qb_offset)
14131411
? $this->query($this->_count_string.$this->protect_identifiers('numrows')."\nFROM (\n".$this->_compile_select()."\n) CI_count_all_results")
@@ -1417,10 +1415,10 @@ public function count_all_results($table = '', $reset = TRUE)
14171415
{
14181416
$this->_reset_select();
14191417
}
1420-
// If we've previously reset the qb_orderby values, get them back
1421-
elseif ( ! isset($this->qb_orderby))
1418+
else
14221419
{
1423-
$this->qb_orderby = $orderby;
1420+
$this->qb_orderby = $qb_orderby;
1421+
$this->qb_cache_orderby = $qb_cache_orderby;
14241422
}
14251423

14261424
if ($result->num_rows() === 0)

system/database/drivers/mssql/mssql_driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ protected function _limit($sql)
453453
$sql = trim(substr($sql, 0, strrpos($sql, $orderby)));
454454

455455
// Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results
456-
if (count($this->qb_select) === 0)
456+
if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE)
457457
{
458458
$select = '*'; // Inevitable
459459
}

system/database/drivers/mysqli/mysqli_result.php

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ public function field_data()
112112
{
113113
$retval[$i] = new stdClass();
114114
$retval[$i]->name = $field_data[$i]->name;
115-
$retval[$i]->type = $field_data[$i]->type;
115+
$retval[$i]->type = static::_get_field_type($field_data[$i]->type);
116116
$retval[$i]->max_length = $field_data[$i]->max_length;
117-
$retval[$i]->primary_key = (int) ($field_data[$i]->flags & 2);
117+
$retval[$i]->primary_key = (int) ($field_data[$i]->flags & MYSQLI_PRI_KEY_FLAG);
118118
$retval[$i]->default = $field_data[$i]->def;
119119
}
120120

@@ -123,6 +123,60 @@ public function field_data()
123123

124124
// --------------------------------------------------------------------
125125

126+
/**
127+
* Get field type
128+
*
129+
* Extracts field type info from the bitflags returned by
130+
* mysqli_result::fetch_fields()
131+
*
132+
* @used-by CI_DB_mysqli_result::field_data()
133+
* @param int $flags
134+
* @return string
135+
*/
136+
private static function _get_field_type($flags)
137+
{
138+
static $map;
139+
isset($map) OR $map = array(
140+
MYSQLI_TYPE_DECIMAL => 'decimal',
141+
MYSQLI_TYPE_BIT => 'bit',
142+
MYSQLI_TYPE_TINY => 'tinyint',
143+
MYSQLI_TYPE_SHORT => 'smallint',
144+
MYSQLI_TYPE_INT24 => 'mediumint',
145+
MYSQLI_TYPE_LONG => 'int',
146+
MYSQLI_TYPE_LONGLONG => 'bigint',
147+
MYSQLI_TYPE_FLOAT => 'float',
148+
MYSQLI_TYPE_DOUBLE => 'double',
149+
MYSQLI_TYPE_TIMESTAMP => 'timestamp',
150+
MYSQLI_TYPE_DATE => 'date',
151+
MYSQLI_TYPE_TIME => 'time',
152+
MYSQLI_TYPE_DATETIME => 'datetime',
153+
MYSQLI_TYPE_YEAR => 'year',
154+
MYSQLI_TYPE_NEWDATE => 'date',
155+
MYSQLI_TYPE_INTERVAL => 'interval',
156+
MYSQLI_TYPE_ENUM => 'enum',
157+
MYSQLI_TYPE_SET => 'set',
158+
MYSQLI_TYPE_TINY_BLOB => 'tinyblob',
159+
MYSQLI_TYPE_MEDIUM_BLOB => 'mediumblob',
160+
MYSQLI_TYPE_BLOB => 'blob',
161+
MYSQLI_TYPE_LONG_BLOB => 'longblob',
162+
MYSQLI_TYPE_STRING => 'char',
163+
MYSQLI_TYPE_VAR_STRING => 'varchar',
164+
MYSQLI_TYPE_GEOMETRY => 'geometry'
165+
);
166+
167+
foreach ($map as $flag => $name)
168+
{
169+
if ($flags & $flag)
170+
{
171+
return $name;
172+
}
173+
}
174+
175+
return $flags;
176+
}
177+
178+
// --------------------------------------------------------------------
179+
126180
/**
127181
* Free the result
128182
*

system/database/drivers/mysqli/mysqli_utility.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,11 @@ protected function _backup($params = array())
155155
while ($field = $query->result_id->fetch_field())
156156
{
157157
// Most versions of MySQL store timestamp as a string
158-
$is_int[$i] = in_array(strtolower($field->type),
159-
array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'),
160-
TRUE);
158+
$is_int[$i] = ($field->type & MYSQLI_TYPE_TINY)
159+
OR ($field->type & MYSQLI_TYPE_SHORT)
160+
OR ($field->type & MYSQLI_TYPE_INT24)
161+
OR ($field->type & MYSQLI_TYPE_LONG)
162+
OR ($field->type & MYSQLI_TYPE_LONGLONG);
161163

162164
// Create a string of field names
163165
$field_str .= $this->db->escape_identifiers($field->name).', ';

system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ protected function _limit($sql)
284284
$sql = trim(substr($sql, 0, strrpos($sql, $orderby)));
285285

286286
// Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results
287-
if (count($this->qb_select) === 0)
287+
if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE)
288288
{
289289
$select = '*'; // Inevitable
290290
}
@@ -334,4 +334,20 @@ protected function _insert_batch($table, $keys, $values)
334334
return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE;
335335
}
336336

337+
// --------------------------------------------------------------------
338+
339+
/**
340+
* Database version number
341+
*
342+
* @return string
343+
*/
344+
public function version()
345+
{
346+
if (isset($this->data_cache['version']))
347+
{
348+
return $this->data_cache['version'];
349+
}
350+
351+
return $this->data_cache['version'] = $this->conn_id->query("SELECT SERVERPROPERTY('ProductVersion') AS ver")->fetchColumn(0);
352+
}
337353
}

system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ protected function _limit($sql)
316316
$sql = trim(substr($sql, 0, strrpos($sql, $orderby)));
317317

318318
// Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results
319-
if (count($this->qb_select) === 0)
319+
if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE)
320320
{
321321
$select = '*'; // Inevitable
322322
}

system/database/drivers/sqlsrv/sqlsrv_driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ protected function _limit($sql)
478478
$sql = trim(substr($sql, 0, strrpos($sql, $orderby)));
479479

480480
// Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results
481-
if (count($this->qb_select) === 0)
481+
if (count($this->qb_select) === 0 OR strpos(implode(',', $this->qb_select), '*') !== FALSE)
482482
{
483483
$select = '*'; // Inevitable
484484
}

0 commit comments

Comments
 (0)