15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/mysql2-cs-bind.rb', line 15
def self.pseudo_bind(sql, values)
sql = sql.dup
placeholders = []
search_pos = 0
while pos = sql.index('?', search_pos)
placeholders.push(pos)
search_pos = pos + 1
end
if placeholders.length != values.length &&
placeholders.length != (values = values.flatten(1)).length
raise ArgumentError, "mismatch between placeholders number and values arguments"
end
while pos = placeholders.pop()
rawvalue = values.pop()
if rawvalue.is_a?(Array)
sql[pos] = rawvalue.map{|v| quote(v) }.join(",")
else
sql[pos] = quote(rawvalue)
end
end
sql
end
|