From: Michael N. <mne...@us...> - 2003-02-01 13:45:27
|
Update of /cvsroot/ruby-dbi/src/lib/dbi In directory sc8-pr-cvs1:/tmp/cvs-serv16506 Modified Files: sql.rb Log Message: method BasicBind#tokens: added support for C-style (non-nesting) and Ada/SQL92-style comments Index: sql.rb =================================================================== RCS file: /cvsroot/ruby-dbi/src/lib/dbi/sql.rb,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- sql.rb 6 Feb 2002 14:24:21 -0000 1.12 +++ sql.rb 1 Feb 2003 13:45:23 -0000 1.13 @@ -140,12 +140,27 @@ # This is NOT a full lexer for SQL. It just breaks up the SQL # string enough so that question marks, double question marks and # quoted strings are separated. This is used when binding - # arguments to "?" in the SQL string. Note: comments are not - # handled. + # arguments to "?" in the SQL string. + # + # C-style (/* */) and Ada-style (--) comments are handled. + # Note: Nested C-style comments are NOT handled! # def tokens(sql) - toks = sql.scan(/('([^'\\]|''|\\.)*'|"([^"\\]|""|\\.)*"|\?\??|[^'"?]+)/) - toks.collect {|t| t[0]} + sql.scan(%r{ + ( + -- .* (?# matches "--" style comments to the end of line or string ) + | + /[*] .*? [*]/ (?# matches C-style comments ) + | + ' ( [^'\\] | '' | \\. )* ' (?# match strings surrounded by apostophes ) + | + " ( [^"\\] | "" | \\. )* " (?# match strings surrounded by " ) + | + \?\?? (?# match one or two question marks ) + | + [^-/'"?]+ (?# match all characters except ' " ? - and / ) + + )}x).collect {|t| t.first} end end # module BasicBind |