[DB-SIG] db module wrapper

Randall Smith randall at tnr.cc
Fri Aug 20 06:43:17 CEST 2004


Ian Bicking wrote:
> 
> Does this work with all the cases?  This can be hard, especially the 
> (Postgres) cases:
> 
> SELECT * FROM questions WHERE answer = 'maybe?' AND user_id = ?
> SELECT * FROM questions WHERE answer = '''maybe?''' AND user_id = ?
> SELECT * FROM questions WHERE answer = '\'maybe?\'' AND user_id = ?
> SELECT * FROM questions WHERE answer = '
> maybe
> ?
> ' AND user_id = ?
> SELECT * FROM "questions?" WHERE answer = 'maybe' AND user_id = ?
> 
> 
> For MySQL support, you'd need to recognize double quotes in addition to 
> single quotes, with the backquote for quoted columns.
> 

I thought about this allot today.  I finally came up with a surprisingly 
simple solution that I coded < 30 lines.  Performance is good also.  At 
first, I was thinking of ways to identify the quoted strings.  But the 
scope of this task only requires that I know where NOT to look for qmarks.

The only oddity is non-standard escapes like Postgresql's '\'.  '\' is 
not a problem to handle, I just have to know when to treat it as an 
escape character and when not to.  Do you know of any other databases 
that use '\' as an escape character or any other non-standard escape 
characters in use?

Randall


More information about the DB-SIG mailing list