Welcome Guest, Not a member yet? Register   Sign In
Field Name Problem In CI3
#1

I've used

Code:
$this->db->query("SELECT [ID],[A],[B] FROM TABLE");

in my CI2 installation and all of my queries executed without problem. I'm using SQL Server 2012 and sqlsrv driver as database platform.

But when i try to upgrade my installation to CI3, bracketed fields generates error [XXX] field not found. When i remove bracket everything workes well again.

Why did you remove bracket support in CI3 or did i something wrong?
I'm a person from Turkiye. I don't know English very well and i can't write what i want to say sometimes (as now happenes  Blush ).

If i write something by mistake; please don't distress it and try to understand what i want to write.
Reply
#2

(This post was last modified: 11-24-2014, 03:29 PM by Rufnex.)

I never used this in that way. On SQL Server you can also write id, a, b etc. You can try to disable db debugging. For that change your settings in /application/config/database.php

PHP Code:
    'db_debug' => false

Or you change the value on the fly like

PHP Code:
$this->db->db_debug false;
$this->db->query("SELECT [ID] FROM table");
$this->db->db_debug true

Maybe this work .. but no you have no debugging.

Reply
#3

I don't see anything unusual in the code that would mees up with the usage of square brackets. Could you inspect your SQL logs to see what queries actually get run?
Reply
#4

(11-24-2014, 02:39 PM)mertdogan Wrote: I've used


Code:
$this->db->query("SELECT [ID],[A],[B] FROM TABLE");

in my CI2 installation and all of my queries executed without problem. I'm using SQL Server 2012 and sqlsrv driver as database platform.

But when i try to upgrade my installation to CI3, bracketed fields generates error [XXX] field not found. When i remove bracket everything workes well again.

Why did you remove bracket support in CI3 or did i something wrong?

It's not removed, and especially in the query() method - if something fails, it's the query that's erroneous. Your server might be configured to escape with double quotes instead of square brackets though (and it should be, that's the SQL standard).

(11-24-2014, 03:24 PM)Rufnex Wrote: I never used this in that way. On SQL Server you can also write id, a, b etc. You can try to disable db debugging. For that change your settings in /application/config/database.php


PHP Code:
    'db_debug' => false

Or you change the value on the fly like


PHP Code:
$this->db->db_debug false;
$this->db->query("SELECT [ID] FROM table");
$this->db->db_debug true

Maybe this work .. but no you have no debugging.

This would only turn off displaying the error message, it won't solve anything.
Reply
#5

(This post was last modified: 11-26-2014, 06:09 PM by mertdogan. Edit Reason: remote quotes )

Exquise me; it is my mistake. $this->db->query("SELECT [ID] FROM table"); not generates error message.

PHP Code:
$res=$this->db->select('[ID],[A],[B]')->FROM('DBTABLE')->GET()->RESULT(); 

is generating this field name error. This code hasn't generating error CI2. But after upgrade CI3 this model is generating error.

I think this is a query escaping problem. Because when i will change my code to
PHP Code:
$res=$this->db->select('[ID],[A],[B]',false)->FROM('DBTABLE')->GET()->RESULT(); 

it isn't generating error message again. Because escaped select function resulting SELECT "[ID]","[A]","[B]" FROM "DBTABLE"

This result is about table names too. In CI2; bracketed table names and select column hasn't problem but this occured in CI3. I think function has to remove brackets before escaping them.


In CI2
PHP Code:
$res=$this->db->select('[ID],[A],[B]',false)->FROM('[DBTABLE]')->GET()->RESULT(); 
hasn't problem but after CI3 upgrade they are problem for query now.
I'm a person from Turkiye. I don't know English very well and i can't write what i want to say sometimes (as now happenes  Blush ).

If i write something by mistake; please don't distress it and try to understand what i want to write.
Reply
#6
Sad 

Guys I think there's a problem with that driver. First I wanted that someone clarify the necessity to put double quotation marks in almost all words on the query. This is a problem when you try to use an INNER JOIN as the code below:

PHP Code:
        $this->db->select("data,tab,tma");
        
$this->db->from("abHistorico as ab");
        
$this->db->join("tmap","ab.id_fila = tmap.id_fila AND ab.data BETWEEN data_inicial AND data_final","LEFT");
        
$this->db->where("data BETWEEN '$date_start' AND '$date_end'"); 

The SQLSERVER 2012 notifies the error below:

Incorrect sintax near 'BETWEEN'.

SELECT "data", "tab", "tma" FROM "abHistorico" as "ab" LEFT JOIN "tmap" ON "id_fila" = "id_fila" AND "ab"."data" "BETWEEN" "data_inicial" AND data_final WHERE data BETWEEN '20140901' AND '20140930'

As you can see there are double quotes on the fields as well in BETWEEN inside the inner join clause. If I remove these quotation the query will work. I know this is due to escaping thing, but I want to use the active record class without to have to include a false parameter on theses methods every time, because is annoying. I need help on this problem. And more I want to keep escaping single quotes from the queries.

I am using PHP 5.5, SQLSERVER 2012. If I use ODBC and configure to user the SQL Server Native Client 11.0 the problem is gone, but I have to configure the driver for each database version (Use Sql Server driver sucks).

Regards,
Caju
Reply




Theme © iAndrew 2016 - Forum software by © MyBB