Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support locking by default and disable it only for SQLite #78

Merged
merged 1 commit into from
Aug 26, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions lib/arel/visitors/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ def visit_Arel_Nodes_Bin o
"BINARY #{visit o.expr}"
end

def visit_Arel_Nodes_Lock o
visit o.expr
end

###
# :'(
# http://dev.mysql.com/doc/refman/5.0/en/select.html#id3482214
Expand Down
4 changes: 0 additions & 4 deletions lib/arel/visitors/oracle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ module Visitors
class Oracle < Arel::Visitors::ToSql
private

def visit_Arel_Nodes_Lock o
visit o.expr
end

def visit_Arel_Nodes_SelectStatement o
o = order_hacks(o)

Expand Down
3 changes: 0 additions & 3 deletions lib/arel/visitors/postgresql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ module Arel
module Visitors
class PostgreSQL < Arel::Visitors::ToSql
private
def visit_Arel_Nodes_Lock o
visit o.expr
end

def visit_Arel_Nodes_Matches o
"#{visit o.left} ILIKE #{visit o.right}"
Expand Down
5 changes: 5 additions & 0 deletions lib/arel/visitors/sqlite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ module Arel
module Visitors
class SQLite < Arel::Visitors::ToSql
private

# Locks are not supported in SQLite
def visit_Arel_Nodes_Lock o
end

def visit_Arel_Nodes_SelectStatement o
o.limit = Arel::Nodes::Limit.new(-1) if o.offset && !o.limit
super
Expand Down
3 changes: 1 addition & 2 deletions lib/arel/visitors/to_sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,8 @@ def visit_Arel_Nodes_Top o
""
end

# FIXME: this does nothing on SQLLite3, but should do things on other
# databases.
def visit_Arel_Nodes_Lock o
visit o.expr
end

def visit_Arel_Nodes_Grouping o
Expand Down
2 changes: 1 addition & 1 deletion test/test_select_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def test_join_sources
it 'adds a lock node' do
table = Table.new :users
mgr = table.from table
mgr.lock.to_sql.must_be_like %{ SELECT FROM "users" }
mgr.lock.to_sql.must_be_like %{ SELECT FROM "users" FOR UPDATE }
end
end

Expand Down
5 changes: 5 additions & 0 deletions test/visitors/test_sqlite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ module Visitors
sql = @visitor.accept(stmt)
sql.must_be_like "SELECT LIMIT -1 OFFSET 1"
end

it 'does not support locking' do
node = Nodes::Lock.new(Arel.sql('FOR UPDATE'))
@visitor.accept(node).must_be_nil
end
end
end
end