Welcome Guest, Not a member yet? Register   Sign In
Active Record with mssql ?
#11

[eluser]Matthieu Fauveau[/eluser]
I had to build an app which sync with an MSSQL server a few months ago and runned into this problem. However I do not remember why I came with the brackets idea, I think it's a colleague who brought that up. It's probably something specific to MSSQL. In the app I had to sync, tables where actually views, maybe it's related.
#12

[eluser]Matthieu Fauveau[/eluser]
[quote author="Randy Casburn" date="1216856267"]Yes...from the MSSQL docs...
Quote:To escape the name of a database that contains spaces, hyphens (”-”), or any other exceptional characters, the database name must be enclosed in brackets, as is shown in the example, below. This technique must also be applied when selecting a database name that is also a reserved word (such as “primary”).

That applies to the table names as well too apparently. I'm not using MSSQL too much anymore. I should have caught this sooner.

Thanks Matthieu!

Randy[/quote]

Glad to be able to help from time to time Wink
#13

[eluser]ZCoders[/eluser]
and now ....
Code:
$query = $this->db->get("[tbl_menu]");
, not works in mysql :-(....
#14

[eluser]Matthieu Fauveau[/eluser]
In the file /database/drivers/mssql/mssql_driver.php you could modify the following function at line 406 with something like :
Code:
function _escape_table($table)
{
if(strpos($table, '_') !== FALSE)
{
    $table = '['.$table.']';
}
        
return $table;
}

or simply (in case it's not a problem to always enclose in brackets with MSSQL) :
Code:
function _escape_table($table)
{
return '['.$table.']';
}

It's definitely something that need to be handled by default in CI as active record classes cannot be extended...
#15

[eluser]ZCoders[/eluser]
Even so, I get this error...
Quote: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 '[tbl_menu])' at line 2

greetings
#16

[eluser]Randy Casburn[/eluser]
Matthiew -- why don't you recommend this to the Dereks as a change the core?

You could be our newest CI hero! I think this is a good input.

Randy
#17

[eluser]Matthieu Fauveau[/eluser]
Did you remove the brackets from your active record query ? By modifying the file I indicated you will not need to use them anymore as the driver will put them for you when you'll be using an MSSQL base. At least it should, I did not test it Wink
#18

[eluser]Matthieu Fauveau[/eluser]
[quote author="Randy Casburn" date="1216858279"]Matthiew -- why don't you recommend this to the Dereks as a change the core?

You could be our newest CI hero! I think this is a good input.

Randy[/quote]

I'll send a PM for him to take a look at the thread.

Becoming a CI hero? No kidding? It's definitely worth a shot Wink
#19

[eluser]ZCoders[/eluser]
i am test.!
#20

[eluser]Derek Jones[/eluser]
Thanks for the great legwork there, Matthieu. If you don't mind, can I ask you to file a bug report with this information, pointing back to this thread?




Theme © iAndrew 2016 - Forum software by © MyBB