aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-10-15 16:11:48 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-10-26 13:44:09 -0700
commitffb999125a60cbdcee2e6709df019d55f21b22a6 (patch)
treef533122d42061e74b5ffe2b5055fb6fa58edd3be /activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
parenteb83eb6c98ae95a994dcac07d2c6246f7fd61962 (diff)
downloadrails-ffb999125a60cbdcee2e6709df019d55f21b22a6.tar.gz
rails-ffb999125a60cbdcee2e6709df019d55f21b22a6.tar.bz2
rails-ffb999125a60cbdcee2e6709df019d55f21b22a6.zip
initial exec() method is working in pg adapter
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 5949985e4d..75b4c1e653 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -220,11 +220,19 @@ module ActiveRecord
@local_tz = nil
@table_alias_length = nil
@postgresql_version = nil
+ @statements = Hash.new { |h,k| h[k] = "a#{h.length + 1}" }
connect
@local_tz = execute('SHOW TIME ZONE').first["TimeZone"]
end
+ def clear_cache!
+ @statements.each_value do |value|
+ exec "DEALLOCATE #{value}"
+ end
+ @statements.clear
+ end
+
# Is this connection alive and ready for queries?
def active?
if @connection.respond_to?(:status)
@@ -250,8 +258,14 @@ module ActiveRecord
end
end
+ def reset!
+ clear_cache!
+ super
+ end
+
# Close the connection.
def disconnect!
+ clear_cache!
@connection.close rescue nil
end
@@ -501,6 +515,30 @@ module ActiveRecord
end
end
+ def exec(sql, name = 'SQL', binds = [])
+ return async_exec(sql, name, binds) if @async
+
+ log(sql, name) do
+ end
+ end
+
+ def async_exec(sql, name, binds)
+ log(sql, name) do
+ unless @statements.key? sql
+ @connection.prepare @statements[sql], sql
+ end
+
+ key = @statements[sql]
+
+ # Clear the queue
+ @connection.get_last_result
+ @connection.send_query_prepared(key, [])
+ @connection.block
+ result = @connection.get_last_result
+ ActiveRecord::Result.new(result.fields, result_as_array(result))
+ end
+ end
+
# Executes an UPDATE query and returns the number of affected tuples.
def update_sql(sql, name = nil)
super.cmd_tuples