Hi, I'm ThadeusB.

I code stuff. I raise bees. I game.

Check reserved SQL Keywords on web2py DAL

As of web2py version 1.75.1 there is also another argument that can be passed to the DAL constructor to check table names and column names against reserved SQL keywords in target back-end databases.

This argument is check_reserved; it defaults to None.

This is a list of strings that contain the database back-end adapter names, with two extra options all and common.

The adapter name is the same as used in the DAL connection string. So if you want to check against PostgreSQL and MSSQL then your connection string would look as follows

>>> db = DAL('sqlite://storage.db', 
           pool_size=0, 
           check_reserved=['postgres', 'mssql'])

The DAL will scan the keywords in the same order as of the list.

There are two extra options all and common. If you specify all, it will check against all known SQL keywords. If you specify common, it will only check against common SQL keywords such as SELECT, INSERT, UPDATE, etc.

For supported back-ends you may also specify if you would like to check against the non-reserved SQL keywords as well. In this case you would append _nonreserved to the name. For example check_reserved=['postgres', 'postgres_nonreserved'].

The following database backends support reserved words checking.

  • PostgreSQL ('postgres')_nonreserved
  • MySQL ('mysql')
  • FireBird ('firebird')_nonreserved
  • MSSQL ('mssql')
  • Oracle ('oracle')