简体   繁体   English

Doctrine-PostgreSQL-表/字段名称中的大写和空格

[英]Doctrine - PostgreSQL - Uppercase and Spaces in Table / Field names

Having issues with Doctrine 2.3 and PostgreSQL with Spaces and Upper case Field / Table names Doctrine 2.3和PostgreSQL带有空格和大写字段/表名的问题

Example: ( Yes we are working on migrating away from this ) 示例:(是的,我们正在努力从此迁移)

SELECT "Field Name"
FROM "Table Name"

We also have a mix of the two formats 我们也有两种格式的混合

SELECT "Field Name", another_field_name
FROM "Table Name", another_table_name

When using doctrine I'm getting a PDOException. 当使用该学说时,我得到一个PDOException。 When looking at the error I see that there are no double quotes around Fields / Tables ( names ) that have Upper case and Spaces. 查看错误时,我发现在具有大写字母和空格的字段/表(名称)周围没有双引号。

Is there a fix? 有解决办法吗? Workaround? 解决方法?

Here is an example of what Doctrine is generating 这是教义产生的一个例子

SELECT t0.TheId AS theid1, t0.Name AS name2, t0.User AS user3
FROM The Table t0 
WHERE t0.TheId = 1234

Here is how I need it 这是我需要的

SELECT t0."TheId" AS theid1, t0."Name" AS name2, t0."User" AS user3
FROM "The Table" t0 
WHERE t0."TheId" = 1234

You may need to use backticks to let Doctrine know that it should be quoted: Quoting reserved words . 您可能需要使用反引号使教义知道该词应加引号: 引用保留字 Eg: 例如:

<?php
/** @Column(name="`number`", type="integer") */
private $number;

Unfortunately the accepted answer won't work in the presented situation. 不幸的是,所接受的答案在当前情况下不起作用。 The backticks will not work as every column in a doctrine query gets an alias by using the lower cased name with an appended identifier. 反引号将不起作用,因为通过使用带有附加标识符的小写名称,教义查询中的每一列都会获得别名。 This alias would have spaces in it and would therefore generate a sql error when passed to postgres. 该别名中将包含空格,因此在传递给postgres时将产生sql错误。

The only way this could be corrected is in Doctrine itself when the query is generated. 可以更正此问题的唯一方法是在生成查询时在教义本身中。

update it seems this may have been corrected in the latest version of doctrine2. 更新似乎已在最新版本的doctrine2中更正了此问题。 It now replaces non acceptable characters. 现在,它将替换不可接受的字符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM