Part of the EllisLab Network
   
 
Backticks not added when using custom operator (v1.6.2)
Posted: 05 June 2008 08:56 PM   [ Ignore ]  
Summer Student
Total Posts:  2
Joined  06-05-2008

in my code (where CI is a codeigniter instance)

$this->CI->db->where(“left >”, (int)$record[$this->left_column]);

produces: ...WHERE left > 11…

$this->CI->db->where(“left”, (int)$record[$this->left_column]);

produces: ...WHERE `left` = 11…

In the former case, where I am using a custom operator the backticks are not produced and I have to insert them myself. This seems to be fairly inconsistent and inconvenient. Please consider fixing this.

Suggested fix:
change line 444 in DB_active_rec.php from
$k =  preg_replace(”/([A-Za-z_0-9]+)/”, $this->_protect_identifiers(’$1’), $k);
to
$k =  preg_replace(”/([A-Za-z_0-9]+)/e”, ’$this->_protect_identifiers(”\\1”)’, $k);

Profile
 
 
Posted: 10 June 2008 09:39 AM   [ Ignore ]   [ # 1 ]  
Grad Student
Avatar
Rank
Total Posts:  92
Joined  12-27-2007

i think backtick is okay with sql query. it can help you to solve some problem.

here is my example:
I have a table which has field called ‘delete’, it just a boolean to check whether the record deleted or not (not real delete record but delete by flag only). if you try to do this query : select * from mytable where delete = ‘N’ ;—> it will produce error .. but if the backtick used then it will the normal query.

 Signature 

[color=blue]——
wysmedia.com
Using:Code Igniter 1.6.2

Programming: 90% make data validation, 9% UI, 1% data entry

Profile
 
 
Posted: 11 June 2008 03:40 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  2
Joined  06-05-2008

Right,
backticks are good
and the library DOES NOT ADD backticks when operators such as > or < are used. It is a problem causing inconsistencies in the formatting of queries when both custom operators and equality is mixed.  Try doing something like $this->db->where(‘field1’, $value)->where(‘field2 >’, $value2); and it will add backticks to field1 but not field2 producing an illegal query.

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 62663 Total Logged-in Users: 36
Total Topics: 77201 Total Anonymous Users: 1
Total Replies: 416766 Total Guests: 268
Total Posts: 493967    
Members ( View Memberlist )