views:

54

answers:

1

How to use illegal names for MySQL with SQLObject?

In pure SQL it is possible to use backquotes, say:

    SELECT `select from` FROM table1 WHERE 1;

...can be used to select the field called select from. Is it possible to tell SQLObject to utilize backquotes?

+1  A: 
CREATE TABLE table1 (
  id INT(11),
  `select from` VARCHAR(255),
  PRIMARY KEY (id)
);
INSERT INTO table1 VALUES(1, 'test value');

to access select from from SQLObject, declare the column with backticks:

>>> class Table1(SQLObject):
...     myIllegallyNamedColumn = Col(dbName="`select from`")
... 
>>> list(Table1.select())
[<Table1 0 myIllegallyNamedColumn='test value'>]
ax
@ax: Great! You solved my mystery of the week.
Alex
I'd be wary about relying on this: apart from being MySQL-only, it seems like a bug that SQLObject is not properly escaping schema names already. Really this should be fixed in the library (at which point the above might break!)
bobince