On 03/02/2013 10:16 AM, Stephen Chrzanowski wrote:
Just had a thought;
You could do a few things, unfortunately all at the code base level;
1> I don't know if Python will handle it, but I know most other languages
have a string-replace function, or, more specifically, in Delphi, there is
a "format" command in which you would create a string, fill it in with
parameters (Like %s, %d, etc) and then you have an array of variables the
system would fill in. Create a variable that contains the SQL you need,
but replace what needs to be quoted with a format specifier. Then,
regenerate the SQL with either quoted or non-quoted variables. This would
become a PITA if you had 30 field names or so, however. Not to mention bug
prone.
2> In line with a true string replace, replace all the field names in the
string to a format like '%db..table%' then run a string replace against all
the possible field names and replace them with either a quoted string, or a
non-quoted string.
3> Another option is to manually mangle the string based on what Sybase is
being fed. So, if you're going to toss it into SQLite:
- scan the string for double-periods, and remember the position
- backup, character by character, until the first non-valid character, and
put a single/double quote
- go forward+1 from the remembered position until the first non-valid
character, and drop the same quote.
4> The last thing, off the top of my head, would be to locate each and
every SQL string, and move it into a file of its own, then duplicate for
SQLite and mangle as needed. Along with option 1, nightmare to manage.
My thought, #3 would probably be the easiest to implement, as it'd require
one function to be created and an appropriate result returned then going
through the code and applying the function where needed, but it'd probably
the slowest since you'll be practically touching each and every character
in the string before its fed to the DBMS. #2 would be next in line as a
search and replace based on field names would PROBABLY be more quicker
instead of mangling strings character by character, but it'd involve going
in and modifying the SQL calls themselves, as well as adding the
appropriate string replace commands.
Another option: wrap the appropriate functions from the various classes
in the python sqlite3 module, and have them convert '..' to '.' in
queries before passing on. You'd just have to make sure not to replace
'..' appearing inside string constants.
Assuming you're lazy like me, and only issue sql using methods of the
Connection object, that means interposing on Connection.execute and
Connection.executemany; the Connection object has read-only attributes,
so you'd probably need a wrapper class.
Ryan
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users