3
4
5
6
7
8
9
10
11
12
13
14
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/rgviz_rails/adapters/sqlite_adapter.rb', line 3
def accept_scalar_function_column(node, visitor)
case node.function
when ScalarFunctionColumn::Year
visitor << "strftime('%Y', "
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Month
visitor << "strftime('%m', "
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Day
visitor << "strftime('%d', "
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Hour
visitor << "strftime('%H', "
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Minute
visitor << "strftime('%M', "
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Second
visitor << "strftime('%S', "
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Millisecond
raise NotSupported.new("The millisecond function is not supported in SQLite")
when ScalarFunctionColumn::Quarter
raise NotSupported.new("The quarter function is not supported in SQLite")
when ScalarFunctionColumn::DayOfWeek
visitor << "1 + strftime('%w', "
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Now
visitor << "strftime('%Y-%m-%d %H:%M:%S')"
when ScalarFunctionColumn::DateDiff
visitor << "julianday("
node.arguments[0].accept visitor
visitor << ") - julianday("
node.arguments[1].accept visitor
visitor << ")"
when ScalarFunctionColumn::ToDate
visitor << "strftime('%Y-%m-%d', "
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Upper
visitor << "upper("
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Lower
visitor << "lower("
node.arguments[0].accept visitor
visitor << ")"
when ScalarFunctionColumn::Concat
visitor << "("
node.arguments.each_with_index do |arg, i|
visitor << " || " if i > 0
arg.accept visitor
end
visitor << ")"
end
end
|