Welcome Guest, Not a member yet? Register   Sign In
False table prefix in sql select statement
#1

[eluser]uk81[/eluser]
I have another thing to discuss.

I open a bug report for this (because for me it is truely a bug), but I am be "urged" to open a forum discussion on this.
So we can discuss if it is a bug or not.

Here is the full description what it is about:
http://codeigniter.com/bug_tracker/bug/4432/

I set up only one little sql select (on a mysql db) and use the date_format() function inside the statement. The 2nd parameter for this function is the format string. I put one inside and it has dots in it. After using the db->select() function there will be my table-prefix (set up in the CI config) append on the front of the format-string.
See and read the bug note, there is also a code-example.

I does not try until now the last suggestion from Derek.

Please write me your suggestions and ideas.

Thanks.
#2

[eluser]Derek Allard[/eluser]
Could you post your select statement here for reference? Did you add the second parameter to avoid CI's escaping?
#3

[eluser]Unknown[/eluser]
I've a similar problem

Code:
$select = str_replace('$',$this->db->dbprefix,
            '$purchase.ID, $purchase.price, $purchase.state,
            DATE_FORMAT($purchase.timestamp_created,     "%e.%c.%Y %H:%i:%s") AS timestamp_created,
            DATE_FORMAT($purchase.timestamp_ordered,     "%e.%c.%Y %H:%i:%s") AS timestamp_ordered,
            DATE_FORMAT($purchase.timestamp_confirmed,    "%e.%c.%Y %H:%i:%s") AS timestamp_confirmed,
            (
                SELECT         GROUP_CONCAT($client.name)
                FROM         $client
                WHERE         $purchase.client_ID = $client.ID
            ) AS "client",
            (
                SELECT         GROUP_CONCAT($product.name SEPARATOR \',<br />\')
                FROM         $product
                LEFT JOIN     $purchase_product
                       ON     ($purchase_product.product_ID = $product.ID)
                WHERE         $purchase_product.purchase_ID = $purchase.ID
            ) AS "products"');
        
        $this->db->select($select, false);
        $this->db->from('purchase');
        $this->db->group_by('purchase.ID');
        $this->db->order_by('purchase.timestamp_created','DESC');

produces the following mysql error


Quote:A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(kfc_purchase.timestamp_created, "%e %c %Y %H %i") AS timestamp_created, ( SELE' at line 1

SELECT kfc_purchase.ID, kfc_purchase.price, kfc_purchase.state, kfc_DATE_FORMAT(kfc_purchase.timestamp_created, "%e %c %Y %H %i") AS timestamp_created, ( SELECT GROUP_CONCAT(kfc_client.name) FROM kfc_client WHERE kfc_purchase.client_ID = kfc_client.ID ) AS "client", ( SELECT GROUP_CONCAT(kfc_product.name SEPARATOR ',
') FROM kfc_product LEFT JOIN kfc_purchase_product ON (kfc_purchase_product.product_ID = kfc_product.ID) WHERE kfc_purchase_product.purchase_ID = kfc_purchase.ID ) AS "products" FROM (kfc_purchase) GROUP BY kfc_purchase.ID ORDER BY kfc_purchase.timestamp_created DESC

The problem is that CI adds my table prefix to DATE_FORMAT although I set the the second parameter false in "$this->db->select($select, false);"

Is this a bug?




Theme © iAndrew 2016 - Forum software by © MyBB