.t.e.s.t. complicated1 - was total_rows = @connection.select_all("SELECT count(*) as TotalRows from (#{sql.gsub(/\bSELECT(\s+DISTINCT)?\b/i, "SELECT#{$1} TOP 1000000000")}) tally")[0][:TotalRows].to_i
IDENTIFIER      "total_rows", la=1, st=3
WHITESPACE      " ", la=1, st=RubyLexerState[spaceseen,null,EXPR_CMDARG,null,null]
NONUNARY_OP     "=", la=1, st=0
WHITESPACE      " ", la=1, st=RubyLexerState[spaceseen,null,EXPR_BEG,null,null]
INSTANCE_VAR    "@connection", la=1, st=1
DOT             ".", la=1, st=7
IDENTIFIER      "select_all", la=1, st=2
LPAREN          "(", st=RubyLexerState[commandstart,null,EXPR_BEG,null,null]
QUOTED_STRING_BEGIN  """, st=RubyLexerState[substituting,StringTerm[flags=expand,end=",begin=0,nest=0,embed=1],EXPR_BEG,StringTermState[nest=0,embed=1],null]
QUOTED_STRING_LITERAL  "SELECT count(*) as TotalRows from (", la=2, st=RubyLexerState[substituting,StringTerm[flags=expand,end=",begin=0,nest=0,embed=1],EXPR_BEG,StringTermState[nest=0,embed=1],null]
STRING_LITERAL  "#{", st=RubyLexerState[embedded|substituting,StringTerm[flags=expand,end=",begin=0,nest=0,embed=2],EXPR_BEG,StringTermState[nest=0,embed=2],null]
EMBEDDED_RUBY   "sql.gsub(/\\bSELECT(\\s+DISTINCT)?\\b/i, "SELECT#{$1} TOP 1000000000")", la=1, st=RubyLexerState[substituting,StringTerm[flags=expand,end=",begin=0,nest=0,embed=2],EXPR_BEG,StringTermState[nest=0,embed=2],null]
QUOTED_STRING_LITERAL  "}", st=RubyLexerState[substituting,StringTerm[flags=expand,end=",begin=0,nest=0,embed=1],EXPR_BEG,StringTermState[nest=0,embed=1],null]
QUOTED_STRING_LITERAL  ") tally", la=1, st=RubyLexerState[substituting,StringTerm[flags=expand,end=",begin=0,nest=0,embed=1],EXPR_BEG,StringTermState[nest=0,embed=1],null]
QUOTED_STRING_END  """, st=RubyLexerState[substituting,null,EXPR_END,null,null]
RPAREN          ")", st=RubyLexerState[substituting,null,EXPR_END,null,null]
LBRACKET        "[", st=RubyLexerState[substituting,null,EXPR_BEG,null,null]
INT_LITERAL     "0", la=1, st=RubyLexerState[substituting,null,EXPR_END,null,null]
RBRACKET        "]", st=RubyLexerState[substituting,null,EXPR_END,null,null]
LBRACKET        "[", st=RubyLexerState[substituting,null,EXPR_BEG,null,null]
TYPE_SYMBOL     ":", la=1, st=RubyLexerState[symbol|substituting,null,EXPR_FNAME,null,null]
TYPE_SYMBOL     "TotalRows", la=1, st=RubyLexerState[substituting,null,EXPR_END,null,null]
RBRACKET        "]", st=RubyLexerState[substituting,null,EXPR_END,null,null]
DOT             ".", la=1, st=RubyLexerState[substituting,null,EXPR_DOT,null,null]
IDENTIFIER      "to_i", la=1, st=RubyLexerState[substituting,null,EXPR_ARG,null,null]
----- EOF -----

.t.e.s.t. complicated2 - was quoted_value = "'#{quoted_value[1..-2].gsub(/\'/, "\\\\'")}'" if quoted_value.include?("\\\'") # (for ruby mode) " 
IDENTIFIER      "quoted_value", la=1, st=3
WHITESPACE      " ", la=1, st=RubyLexerState[spaceseen,null,EXPR_CMDARG,null,null]
NONUNARY_OP     "=", la=1, st=0
WHITESPACE      " ", la=1, st=RubyLexerState[spaceseen,null,EXPR_BEG,null,null]
QUOTED_STRING_BEGIN  """, st=RubyLexerState[substituting,StringTerm[flags=expand,end=",begin=0,nest=0,embed=1],EXPR_BEG,StringTermState[nest=0,embed=1],null]
QUOTED_STRING_LITERAL  "'", la=2, st=RubyLexerState[substituting,StringTerm[flags=expand,end=",begin=0,nest=0,embed=1],EXPR_BEG,StringTermState[nest=0,embed=1],null]
STRING_LITERAL  "#{", st=RubyLexerState[embedded|substituting,StringTerm[flags=expand,end=",begin=0,nest=0,embed=2],EXPR_BEG,StringTermState[nest=0,embed=2],null]
EMBEDDED_RUBY   "quoted_value[1..-2].gsub(/\\'/, "\\\\\\\\'")", la=1, st=RubyLexerState[substituting,StringTerm[flags=expand,end=",begin=0,nest=0,embed=2],EXPR_BEG,StringTermState[nest=0,embed=2],null]
QUOTED_STRING_LITERAL  "}", st=RubyLexerState[substituting,StringTerm[flags=expand,end=",begin=0,nest=0,embed=1],EXPR_BEG,StringTermState[nest=0,embed=1],null]
QUOTED_STRING_LITERAL  "'", la=1, st=RubyLexerState[substituting,StringTerm[flags=expand,end=",begin=0,nest=0,embed=1],EXPR_BEG,StringTermState[nest=0,embed=1],null]
QUOTED_STRING_END  """, st=RubyLexerState[substituting,null,EXPR_END,null,null]
WHITESPACE      " ", la=1, st=RubyLexerState[substituting|spaceseen,null,EXPR_END,null,null]
ANY_KEYWORD     "if", la=1, st=RubyLexerState[substituting,null,EXPR_BEG,null,null]
WHITESPACE      " ", la=1, st=RubyLexerState[substituting|spaceseen,null,EXPR_BEG,null,null]
IDENTIFIER      "quoted_value", la=1, st=RubyLexerState[substituting,null,EXPR_ARG,null,null]
DOT             ".", la=1, st=RubyLexerState[substituting,null,EXPR_DOT,null,null]
IDENTIFIER      "include?", la=1, st=RubyLexerState[substituting,null,EXPR_ARG,null,null]
LPAREN          "(", st=RubyLexerState[substituting|commandstart,null,EXPR_BEG,null,null]
QUOTED_STRING_BEGIN  """, st=RubyLexerState[substituting,StringTerm[flags=expand,end=",begin=0,nest=0,embed=1],EXPR_BEG,StringTermState[nest=0,embed=1],null]
QUOTED_STRING_LITERAL  "\\\\\\'", la=1, st=RubyLexerState[substituting,StringTerm[flags=expand,end=",begin=0,nest=0,embed=1],EXPR_BEG,StringTermState[nest=0,embed=1],null]
QUOTED_STRING_END  """, st=RubyLexerState[substituting,null,EXPR_END,null,null]
RPAREN          ")", st=RubyLexerState[substituting,null,EXPR_END,null,null]
WHITESPACE      " ", la=1, st=RubyLexerState[substituting|spaceseen,null,EXPR_END,null,null]
LINE_COMMENT    "# (for ruby mode) " ", la=1, st=RubyLexerState[substituting|commandstart|spaceseen,null,EXPR_BEG,null,null]
----- EOF -----

<Unnamed test>
----- EOF -----

