Skip to content

Commit 082d803

Browse files
committed
1 parent f2d8c9a commit 082d803

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

system/database/drivers/sqlsrv/sqlsrv_driver.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ function db_connect($pooling = false)
6666
'CharacterSet' => $character_set,
6767
'ReturnDatesAsStrings' => 1
6868
);
69-
70-
// If the username and password are both empty, assume this is a
69+
70+
// If the username and password are both empty, assume this is a
7171
// 'Windows Authentication Mode' connection.
7272
if(empty($connection['UID']) && empty($connection['PWD'])) {
7373
unset($connection['UID'], $connection['PWD']);
@@ -336,16 +336,20 @@ function _version()
336336
function count_all($table = '')
337337
{
338338
if ($table == '')
339-
return '0';
340-
341-
$query = $this->query("SELECT COUNT(*) AS numrows FROM " . $this->dbprefix . $table);
342-
339+
{
340+
return 0;
341+
}
342+
343+
$query = $this->query($this->_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
344+
343345
if ($query->num_rows() == 0)
344-
return '0';
346+
{
347+
return 0;
348+
}
345349

346350
$row = $query->row();
347351
$this->_reset_select();
348-
return $row->numrows;
352+
return (int) $row->numrows;
349353
}
350354

351355
// --------------------------------------------------------------------
@@ -393,7 +397,7 @@ function _list_columns($table = '')
393397
*/
394398
function _field_data($table)
395399
{
396-
return "SELECT TOP 1 * FROM " . $this->_escape_table($table);
400+
return "SELECT TOP 1 * FROM " . $this->_escape_table($table);
397401
}
398402

399403
// --------------------------------------------------------------------
@@ -439,7 +443,7 @@ function _error_number()
439443
function _escape_table($table)
440444
{
441445
return $table;
442-
}
446+
}
443447

444448

445449
/**
@@ -492,7 +496,7 @@ function _from_tables($tables)
492496
* @return string
493497
*/
494498
function _insert($table, $keys, $values)
495-
{
499+
{
496500
return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
497501
}
498502

@@ -517,10 +521,10 @@ function _update($table, $values, $where)
517521
{
518522
$valstr[] = $key." = ".$val;
519523
}
520-
524+
521525
return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where);
522526
}
523-
527+
524528
// --------------------------------------------------------------------
525529

526530
/**
@@ -573,8 +577,8 @@ function _delete($table, $where)
573577
function _limit($sql, $limit, $offset)
574578
{
575579
$i = $limit + $offset;
576-
577-
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql);
580+
581+
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql);
578582
}
579583

580584
// --------------------------------------------------------------------
@@ -595,5 +599,5 @@ function _close($conn_id)
595599

596600

597601

598-
/* End of file mssql_driver.php */
599-
/* Location: ./system/database/drivers/mssql/mssql_driver.php */
602+
/* End of file sqlsrv_driver.php */
603+
/* Location: ./system/database/drivers/sqlsrv/sqlsrv_driver.php */

user_guide/changelog.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ <h3>Bug fixes:</h3>
6464
<ul>
6565
<li>Fixed a bug (#3094) - <samp>CI_Input::_clean_input_data()</samp> breaks encrypted session cookies.</li>
6666
<li>Fixed a bug (#2508) - <a href="libraries/config.html>Config Library</a> didn't properly detect if the current request is via HTTPS.</li>
67+
<li>Fixed a bug (#3314) - SQLSRV <a href="database/index.html">Database driver</a>'s method <samp>count_all()</samp> didn't escape the supplied table name.</li>
6768
</ul>
6869

6970
<h2>Version 2.2.0</h2>

0 commit comments

Comments
 (0)