• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Active Records] Disabling the protection of identifiers

#1
[eluser]Clooner[/eluser]
The following statement gives me problems
Code:
$this->db->select('round(produces.price*produces.discount*'.vat().',2) as price');
It causes problems because vat() returns a value of 1.19.

This will generate mysql code which is invalid.
Code:
`round(produces`.`price*produces`.`discount*1`.`19`, `2)`

I tried to use $this->db->protect_identifiers but this function doesn't allow you to disable the backticks. How can I disable the backticks generated for the 1.19 value?

#2
[eluser]bretticus[/eluser]
From manual...
Quote:$this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.

#3
[eluser]Clooner[/eluser]
[quote author="bretticus" date="1251863324"]From manual...[/quote] Stupid me... I was too focused on the $this->db->protect_identifiers which made we not check more of the manual. Thanks bretticus.

The worse thing is that in this post I give the ansmer myself.

I need more sleep

#4
[eluser]bretticus[/eluser]
[quote author="clooner" date="1251894048"] Stupid me... I was too focused on the $this->db->protect_identifiers which made we not check more of the manual. Thanks bretticus.

The worse thing is that in this post I give the ansmer myself.

I need more sleep[/quote]

Hahaha. Happens to me all the time! Good thing CI has detailed docs (when you can scrutinize them better when not exhausted.) You're welcome.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.