4

Is there a way to have Propel automatically escape column names which are reserved words when adding/updating a row?

Right now I have a column named 'order' and when I try to update using

$row->setOrder(1)->save();

I get a syntax error "PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "order"\nLINE 1: UPDATE terms SET order=$1 WHERE terms.id=$2\n ^'"

knsheely
  • 543
  • 5
  • 13

1 Answers1

5

I found the answer to this at http://propelorm.org/documentation/reference/schema.html#database-element.

Adding the parameter identifierQuoting="true" to my <database> tag in my schema.xml fixed the problem. I believe you can also add that to a <table> tag to limit it to a single table. I'm not sure why this wouldn't be the default setting.

knsheely
  • 543
  • 5
  • 13
  • I can guess that it is the common rule for every programming language: do not use reserved words as identifiers :o) – Abelisto Mar 19 '16 at 22:37
  • @Abelisto it's not just "identifier". It's a column name. So if you have an "order" column in your DB logic - why you should change it to something else? Simpler is to escape the sql query fields. Actual issue is that Propel does not escape fields/names by default. – Djanym Jan 04 '21 at 16:29