I created a table named order. (Yes, bad choice I see). If I make a #OneToMany relation I get a mysql syntax error because Doctrine does not write the name in "`". Can't believe it...
How to fix this?
I had to use:
#ORM\Table(name=" `order` ")
And yes, I had to include the spaces between the quotes and the backtics. Very strange behavior.
You should enable quote_identifier with doctrine
Related
Okay, this may be silly, but i can't make CI to stop quoting my table. I use this code in my model :
$oracle->select('id',FALSE);
$oracle->from('ms_item');
That code will result Select statement as follow:
SELECT id FROM "ms_item"
The problem is, Oracle can't find the table when it have quotes or double quotes. The CI said that second parameter in select() will remove any quote generated by Query Builder, but i don't know how to remove the quote generated by from(), please help...
Thank you...
For note, i'm using Oracle 11g and oci8_11g.dll
Try writing the table name in upper case.
$oracle->from('MS_ITEM');
When a table is created, unless you quote it, it will be stored as an uppercase table name. When you are quoting it ( as CI wants to do), it's performing a case sensitive match
I banged my head against the wall for hours trying to understand why I could not complete an OOP insert statement into a MySQL insert table.
In my table I had a column named keys which was not getting inserted into.
I tried a lot of solutions, but then i renamed the column and the error sorted itself out.
Can anybody please tell me why this is occuring?
I am using wampserver 2.4.
It's a reserved word. You have to backtick it if you want to use it:
Like this:
insert into `keys` values (val1, val2) etc...
It's a mysql reserved word. You have to enclose it within ` to use it as column name. But I discourage that, troubles might appear anyway, for example with some libraries.
when your using reserved words you should enclose them inside backtick
for example `keys`
Im using ZF2 with DoctrineModule and DoctrineORMModule.
Problem: I got some Tablenames in my Database that are equal to MYSQL Commands
Doctrine generates Tablenames in SQL Statements without the "`"'s
SELECT ... FROM references
But I want it to be like this Format
SELECT ... FROM `references`
to be safe..
How to Fix it in Doctrine 1 to fix my Problem I had done this:
http://i.stack.imgur.com/UN5KB.png
(link: http://www.doctrine-project.org/documentation/manual/1_0/fr/configuration:naming-convention-attributes:table-name-format)
I do not find any Fix for this Problem in Doctrine2.
Thanks for helping.
In Doctrine2 there is no automatic identifier quoting. What you could do in this case is directly putting the quotes inside your mappings, like following:
#Table(name="`references`")
That should do the trick, but won't work with schemas and SQLite in 2.2.
I'm using postgresql database.
I have table with column called "from" (I can't change it).
Sql insertion query generated by doctrine are incorrect, because column name "from" should be closed by quotation marks. How can I tell doctrine to do this?
I believe, there is fast and clean way to correct that.
Thanks in advance.
Maybe $conn->setAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true);? From Docs -> Configuration -> Identifier quoting
My script is like this:
$query = Doctrine_Query::create ()
->select('count(p.product_id) as num_a')
->from ( 'ProductComments p' )
->groupBy('p.product_id')
->having('num_a =2 ');
And the generated sql is:
SELECT COUNT(i.product_id) AS i__0 FROM productcomments i GROUP BY i.product_id HAVING num_a=2
Thus I get an error when execute the sql.
I have two questions:
why is the alias of the table 'i' instead of 'p'?
why is the 'num_a' in having clause not replaced with 'i__0',how to fixed it?
Thanks for your suggestion...
I also had a problem with setting alias.
I had to set alias and then use "ORDER BY" with that alias.
Following solution worked for me:
$myQuery->addSelect('(<my select>) AS my_alias');
$myQuery->orderBy('my_alias');
In the result query looked like "...() AS p_0 ... ORDER BY p_0".
I hope it will help someone.
1: why is the alias of the table 'i'
instead of 'p'?
2: why is the 'num_a'
in having clause not replaced with
'i__0',how to fixed it?
Both questions are simply answered: Doctrine uses it's own aliases for the query. You do no need to know these aliases since they will not affect you nor will you need to work with it.
Even though Doctrine names the alias i__0 you can access the attribute with your custom alias, e.g. $yourObject->num_a will have the proper value, namely the result of count(p.product_id).
To see the output of your query is a useful debug feature, but relying on in inside your application is non-sense since these values are only used for the internal mechanisms of Doctrine.
This would not be valid SQL.
SQL standard state that SELECT will be logically executed after having. So You need to repeat aliased code in having.
Good advice. As long as You work with SQL consuming DBs stick as closely to SQL as possible.