54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/DrbDB/MyMultiSQL.rb', line 54
def guess_table(query,field)
sql=String.new(query)
sql=sql+" \r\n"
llength=sql.length
while (sql.gsub!("`"," ")) and sql.length != llength do llength=sql.length end
while (sql.gsub!("\r\n"," ")) and sql.length != llength do llength=sql.length end
while (sql.gsub!("\n"," ")) and sql.length != llength do llength=sql.length end
while (sql.gsub!(" "," ")) and sql.length != llength do llength=sql.length end
llast=0
while (last=sql.index(")") and (llast != last))
llast = last
if first=sql[0 .. last].rindex("(") then
sql[first .. last]=self.guess_table(sql[first +1 .. last -1],field)
end
end
sql=sql.gsub(",","")
first=sql.index(" ",sql.upcase.rindex("FROM")+"from".length)+1 if sql.upcase.rindex("FROM")
first=sql.index(" ",sql.upcase.rindex("UPDATE")+"update".length)+1 if sql.upcase.rindex("UPDATE")
first=sql.index(" ",sql.upcase.rindex("INSERT INTO")+"insert into".length)+1 if sql.upcase.rindex("INSERT INTO")
if first
last=sql.index(" ",first)-1
table=sql[first .. last]
else
table=""
end
table
end
|