Class: Arel::Visitors::SQLite
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
Arel::Visitors::ToSql
|
Defined in: | activerecord/lib/arel/visitors/sqlite.rb |
Constant Summary
ToSql
- Inherited
Class Method Summary
Instance Attribute Summary
Instance Method Summary
-
#infix_value_with_paren(o, collector, value, suppress_parens = false)
private
Queries used in UNION should not be wrapped by parentheses, because it is an invalid syntax in
SQLite
. - #prepare_update_statement(o) private
- #visit_Arel_Nodes_False(o, collector) private
- #visit_Arel_Nodes_IsDistinctFrom(o, collector) private
- #visit_Arel_Nodes_IsNotDistinctFrom(o, collector) private
-
#visit_Arel_Nodes_Lock(o, collector)
private
Locks are not supported in
SQLite
. - #visit_Arel_Nodes_SelectStatement(o, collector) private
- #visit_Arel_Nodes_True(o, collector) private
- #visit_Arel_Nodes_UpdateStatement(o, collector) private
ToSql
- Inherited
Visitor
- Inherited
Constructor Details
This class inherits a constructor from Arel::Visitors::ToSql
Instance Method Details
#infix_value_with_paren(o, collector, value, suppress_parens = false) (private)
Queries used in UNION should not be wrapped by parentheses, because it is an invalid syntax in SQLite
.
# File 'activerecord/lib/arel/visitors/sqlite.rb', line 106
def infix_value_with_paren(o, collector, value, suppress_parens = false) collector << "( " unless suppress_parens left = o.left.is_a?(Nodes::Grouping) ? o.left.expr : o.left collector = if left.class == o.class infix_value_with_paren(left, collector, value, true) else grouping_parentheses left, collector, false end collector << value right = o.right.is_a?(Nodes::Grouping) ? o.right.expr : o.right collector = if right.class == o.class infix_value_with_paren(right, collector, value, true) else grouping_parentheses right, collector, false end collector << " )" unless suppress_parens collector end
#prepare_update_statement(o) (private)
[ GitHub ]# File 'activerecord/lib/arel/visitors/sqlite.rb', line 60
def prepare_update_statement(o) # Sqlite need to be built with the SQLITE_ENABLE_UPDATE_DELETE_LIMIT compile-time option # to support LIMIT/OFFSET/ORDER in UPDATE and DELETE statements. if has_join_sources?(o) && !has_limit_or_offset_or_orders?(o) && !has_group_by_and_having?(o) && # The SQLite3 dialect isn't flexible enough to allow anything other than a inner join # for the first join: # UPDATE table SET .. FROM joined_table WHERE ... (o.relation.right.all? { |join| join.is_a?(Arel::Nodes::InnerJoin) || join.right.expr.right.relation != o.relation.left }) o else super end end
#visit_Arel_Nodes_False(o, collector) (private)
[ GitHub ]# File 'activerecord/lib/arel/visitors/sqlite.rb', line 88
def visit_Arel_Nodes_False(o, collector) collector << "0" end
#visit_Arel_Nodes_IsDistinctFrom(o, collector) (private)
[ GitHub ]# File 'activerecord/lib/arel/visitors/sqlite.rb', line 98
def visit_Arel_Nodes_IsDistinctFrom(o, collector) collector = visit o.left, collector collector << " IS NOT " visit o.right, collector end
#visit_Arel_Nodes_IsNotDistinctFrom(o, collector) (private)
[ GitHub ]# File 'activerecord/lib/arel/visitors/sqlite.rb', line 92
def visit_Arel_Nodes_IsNotDistinctFrom(o, collector) collector = visit o.left, collector collector << " IS " visit o.right, collector end
#visit_Arel_Nodes_Lock(o, collector) (private)
Locks are not supported in SQLite
# File 'activerecord/lib/arel/visitors/sqlite.rb', line 75
def visit_Arel_Nodes_Lock(o, collector) collector end
#visit_Arel_Nodes_SelectStatement(o, collector) (private)
[ GitHub ]#visit_Arel_Nodes_True(o, collector) (private)
[ GitHub ]# File 'activerecord/lib/arel/visitors/sqlite.rb', line 84
def visit_Arel_Nodes_True(o, collector) collector << "1" end
#visit_Arel_Nodes_UpdateStatement(o, collector) (private)
[ GitHub ]# File 'activerecord/lib/arel/visitors/sqlite.rb', line 7
def visit_Arel_Nodes_UpdateStatement(o, collector) collector.retryable = false o = prepare_update_statement(o) collector << "UPDATE " # UPDATE with JOIN is in the form of: # # UPDATE t1 # SET .. # FROM t2 # WHERE t1.join_id = t2.join_id # # Or if more than one join is present: # # UPDATE t1 # SET .. # FROM t2 # JOIN t3 ON t2.join_id = t3.join_id # WHERE t1.join_id = t2.join_id if has_join_sources?(o) visit o.relation.left, collector collect_nodes_for o.values, collector, " SET " collector << " FROM " first_join, *remaining_joins = o.relation.right from_items = remaining_joins.extract! do |join| join.right.expr.right.relation == o.relation.left end from_where = [first_join.left] + from_items.map(&:left) collect_nodes_for from_where, collector, " ", ", " if remaining_joins && !remaining_joins.empty? collector << " " remaining_joins.each do |join| visit join, collector collector << " " end end from_where = [first_join.right.expr] + from_items.map { |i| i.right.expr } collect_nodes_for from_where + o.wheres, collector, " WHERE ", " AND " else collector = visit o.relation, collector collect_nodes_for o.values, collector, " SET " collect_nodes_for o.wheres, collector, " WHERE ", " AND " end collect_nodes_for o.orders, collector, " ORDER BY " maybe_visit o.limit, collector end