Function _protect_identifiers from CI_DB_driver class breaks when active_record is set to FALSE #2284

Open
sergio-bobillier opened this Issue Feb 26, 2013 · 2 comments

Comments

Projects
None yet
5 participants
@sergio-bobillier

When active_record is set to false in config.php file and you try to use the update_string function specifying a complete route for the table name (database.table) the _protect_identifiers function causes the following errors:

Message:  Undefined property: CI_DB_mysql_driver::$ar_aliased_tables
Filename: database/DB_driver.php
Line Number: 1299

Message:  in_array() expects parameter 2 to be array, null given
Filename: database/DB_driver.php
Line Number: 1299

The UPDATE string is produced without problem but the errors are reported, causing trouble for example in functions that produce XML output.

How to reproduce:

  • Create a new CodeIgniter application and a new database with a single table.
  • Alter the database.php file in the application/config folder, configure the database connection and set active record to false
$active_record = FALSE;
  • In the Welcome controller write a sample block of code similar to the next one. The important thing here is to use update_string function and specify a complete route for the table name (database.table)
$this->load->database();
$where = "id = 1";
$data = array("name" => 'Apple');
$sql = $this->db->update_string("test_ci.Test_Table", $data, $where);
echo $sql;

This will cause two PHP errors (the ones mentioned above) however the last line will print the SQL UPDATE statement.

A suggested fix wold be to check if ar_aliased_tables attribute was initialized and if not then initialize it, or initialize it as an empty array when the function starts or the class is constructed.

@UzEE

This comment has been minimized.

Show comment Hide comment
@UzEE

UzEE Apr 1, 2013

Any workarounds for this issue for the time being? This is causing a problem in my application flow.

UzEE commented Apr 1, 2013

Any workarounds for this issue for the time being? This is causing a problem in my application flow.

@jim-parry jim-parry added the Bug label Nov 12, 2014

@steveheinsch

This comment has been minimized.

Show comment Hide comment
@steveheinsch

steveheinsch Dec 23, 2014

As a temp workaround you could try
$this->db->_protect_identifiers = FALSE;

//your query...

As a temp workaround you could try
$this->db->_protect_identifiers = FALSE;

//your query...

narfbg added a commit that referenced this issue Aug 7, 2015

[ci skip] Partial patch for #2284
The issue description is about update_string(), which
I'm not sure if can be fixed at all. This patch only
addresses protect_identifiers().

@narfbg narfbg added the Dead Issue? label Aug 7, 2015

@narfbg narfbg modified the milestone: 3.0.2 Aug 14, 2015

vegnuli pushed a commit to venenux/codeigniterpower that referenced this issue Aug 18, 2017

backported fix bcit-ci/CodeIgniter@a12cf28
* sove issue bcit-ci/CodeIgniter#2284
* qb_aliases_tables are empty due ACTIVE RECORD are deactivated and disabled
* so check if are empty and assumed protect_identifiers() disabled
* so then the query builder dont make protective that part of the WHERE for the query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment