CodeIgniter Forums

Full Version: Query Build + MSSQL
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys, we are working on a large MS Dynamics Nav Project.

I could need some advice relating to the "from Queries" of the Query Builder, it seems on weird table names there are problems
Below a few examples:

Table Name: AAA$Sales Contingent

Input:
PHP Code:
->from('[AAA$Sales Contingent]'

Output:
Code:
FROM "[AAA$Sales" "Contingent]"


Input:
PHP Code:
->from('[AAA$Sales Contingent] AS asc'

Output:
Code:
FROM "[AAA$Sales Contingent]" AS "asc"


Basically if i don't want to use an alias it is nearly impossible to get a correct statement - is this on purpose or am i missing something here ?

I mean don 't get me wrong an Alias on such table names is almost always necessary, but there are simple statements where you don't need an alias. 

I just ask this question because we couldn't find anything documented about this, and one of us spent some time right now to get a correct statement because he wasn't aware of the fact that he has to use an alias.
CI has never supported table names with spaces (or commas, for that matter) in them. If it has previously worked for you, that's simply because it didn't support field name escaping for MSSQL at all.

https://github.com/bcit-ci/CodeIgniter/issues/1649
https://github.com/bcit-ci/CodeIgniter/issues/2755

Also, that you get double quotes in the result means that you shouldn't be using square brackets either (whether double quotes or square brackets are used is detected dynamically when you connect to the database). I'm not 100% sure right now about the behavior with already escaped field names, but you might want to try using double quotes instead and see if that helps.
yeah, the only reason why i started this topic was because i thought i was missing something
thx for your answer