Active Record doesn't handle 'NULL' columns? [SOLVED] |
[eluser]Jaketoolson[/eluser]
I'm running a UNION on 2 SELECT queries. One of the select creates a fictitious column, setting the value to NULL (i.e. NULL AS sub_cat). This is done because when the 2 queries are combined, the other select query has values for this column. When running this across multiple platforms using various methods (MS Access, MySQL Query Browser, phpMyAdmin, I have no problems except when I use the active record method in CI. Code: $sql = "sub.model_id, sub.sub_cat I receive the following error: Quote:A Database Error Occurred When I switch CI query methods: Code: //from this The correct results are produced: Code: model_id sub_cat
[eluser]Phil_B[/eluser]
Hi Jake, You have all your SQL in the select portion of the ActiveRecord query. This may or may not work but try this instead: Code: $from = '(
[eluser]jmadsen[/eluser]
why not just skip ActiveRecord, since you aren't actually using it? Code: $query = $this->sess_db->query($sql); Active Record is just a query building library. You don't have to use it. http://ellislab.com/codeigniter/user-gui...mples.html
[eluser]Jaketoolson[/eluser]
Quote:why not just skip ActiveRecord, since you aren’t actually using it? I was just being consistent with the other functions in the class I'm writing and put no thought into whether or not I need to use ActiveRecord. Also, for debugging purposes, I begin with a "full query" that I know works and chain it down. Breaking my query apart into a very simple SELECT using ActiveRecord, while still forcing a NULL, still produces the same error: Code: $this->sess_db->select("models.model_id, NULL AS sub_cat"); Quote:A Database Error Occurred I believe this to be a bug.
[eluser]jmadsen[/eluser]
If you print out your query, you will see that NULL is being "pipped" as `NULL` Add "false" as a second argument to your ->select() and you will be fine. i.e., Code: $this->sess_db->select("models.model_id, NULL AS sub_cat", false);
[eluser]Jaketoolson[/eluser]
Thanks! Setting the 2nd parameter to false caused CI to not protect my fields with `backticks` which resolved the issue. |
Welcome Guest, Not a member yet? Register Sign In |