Use reserved keywords of mysql

64 views
Skip to first unread message

ajith c t

unread,
Jun 18, 2013, 3:09:16 AM6/18/13
to web...@googlegroups.com
Hi,
     Is there is any update on the usage of reserved keywords in the table definition. In this thread 


I need to create a table in mysql db as:

    db.define_table('rms_rule', 
            Field('condition', requires=IS_IN_SET(['IsEqual','IsNotEqual','IsGreater','IsLesser','IsNull','IsNotNull','Likeliness','IsMatch','IsNotMatch','In'])),
    )

I tried with backticks(`) as mysql stats and different combinations of qoutes.

If I use it as given above the error is a mysql programming error:

ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'condition VARCHAR(255),\n    description VARCHAR(255) NOT NULL,\n    params VARCHA' at line 13")

So it passed DAL but escaping might be the problem. But using the backticks as mysql says, it generates syntax error which is caught by DAL. 

db.define_table('rms_rule', 
            Field('`condition`', requires=IS_IN_SET(['IsEqual','IsNotEqual','IsGreater','IsLesser','IsNull','IsNotNull','Likeliness','IsMatch','IsNotMatch','In'])),
    )

SyntaxError: invalid table or field name: `condition`

is there any way in escaping these reserve keywords. Its difficult to change the field name as its already defined by third party in mysql.

The above thread was one year back.

Niphlod

unread,
Jun 18, 2013, 6:45:36 AM6/18/13
to web...@googlegroups.com
There's nothing in the actual code that uses escaping. we tried but it was reverted soon.

It's on the roadmap but it's not done yet, as it is a rather hard point.

On the implementation process, we may provide a "sql_name" attribute for both fields and tables that will output the escaped sequence for the "object" needed.
Using row.backtick_fieldname_backtick is kinda a bummer.... separing "field names" from "sql names" allows to "map" your preferred name to your actual column/table in the database.

pbreit

unread,
Jun 28, 2016, 1:06:49 PM6/28/16
to web2py-users
Does the new DAL relax the reserved SQL words limitation?

Niphlod

unread,
Jun 28, 2016, 3:22:09 PM6/28/16
to web2py-users
if I'm not mistaken very recent releases quote everything by default, and even if the previous statement is incorrect, the entity_quoting argument is there for some time now.
Reply all
Reply to author
Forward
0 new messages