Class: Arel::Visitors::Derby
- Inherits:
-
ToSql
- Object
- ToSql
- Arel::Visitors::Derby
- Defined in:
- lib/arel/visitors/derby.rb
Instance Method Summary collapse
-
#visit_Arel_Nodes_InsertStatement(o, a = nil) ⇒ Object
NOTE: marker set by ArJdbc::Derby.
- #visit_Arel_Nodes_Limit(o, a = nil) ⇒ Object
-
#visit_Arel_Nodes_Lock(o, a = nil) ⇒ Object
This generates SELECT...FOR UPDATE, but it will only work if the current transaction isolation level is set to SERIALIZABLE.
- #visit_Arel_Nodes_Offset(o, a = nil) ⇒ Object
- #visit_Arel_Nodes_SelectStatement(o, a = nil) ⇒ Object
Instance Method Details
#visit_Arel_Nodes_InsertStatement(o, a = nil) ⇒ Object
NOTE: marker set by ArJdbc::Derby
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/arel/visitors/derby.rb', line 34 def visit_Arel_Nodes_InsertStatement o, a = nil sql = "INSERT INTO " sql << visit(o.relation, a) values = o.values if o.columns.any? cols = o.columns.map { |x| quote_column_name x.name } sql << ' (' << cols.join(', ') << ') ' elsif o.values.eql? VALUES_DEFAULT cols = o.relation.engine.columns.map { |c| c.name } sql << ' (' << cols.join(', ') << ')' sql << ' VALUES ' sql << ' (' << cols.map { 'DEFAULT' }.join(', ') << ')' values = false end sql << visit(values, a) if values sql end |
#visit_Arel_Nodes_Limit(o, a = nil) ⇒ Object
16 17 18 |
# File 'lib/arel/visitors/derby.rb', line 16 def visit_Arel_Nodes_Limit o, a = nil "FETCH FIRST #{limit_for(o)} ROWS ONLY" end |
#visit_Arel_Nodes_Lock(o, a = nil) ⇒ Object
This generates SELECT...FOR UPDATE, but it will only work if the current transaction isolation level is set to SERIALIZABLE. Otherwise, locks aren't held for the entire transaction.
27 28 29 |
# File 'lib/arel/visitors/derby.rb', line 27 def visit_Arel_Nodes_Lock o, a = nil do_visit o.expr, a end |
#visit_Arel_Nodes_Offset(o, a = nil) ⇒ Object
20 21 22 |
# File 'lib/arel/visitors/derby.rb', line 20 def visit_Arel_Nodes_Offset o, a = nil "OFFSET #{do_visit o.value, a} ROWS" end |
#visit_Arel_Nodes_SelectStatement(o, a = nil) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/arel/visitors/derby.rb', line 7 def visit_Arel_Nodes_SelectStatement o, a = nil sql = o.cores.map { |x| do_visit(x, a) }.join sql << " ORDER BY #{o.orders.map { |x| visit x }.join(', ')}" unless o.orders.empty? sql << " #{do_visit o.offset, a}" if o.offset sql << " #{do_visit o.limit, a}" if o.limit sql << " #{do_visit o.lock, a}" if o.lock sql end |