Skip to content

Commit 7a46ad7

Browse files
committed
Postgres, fix explain warnings and functionality (3 tests fails only due binds, we use ? instead of )
1 parent 89827d2 commit 7a46ad7

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

lib/arjdbc/postgresql/adapter.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
require 'arjdbc/postgresql/base/array_decoder'
2323
require 'arjdbc/postgresql/base/array_encoder'
2424
require 'arjdbc/postgresql/name'
25+
require 'arjdbc/postgresql/database_statements'
2526
require 'arjdbc/postgresql/schema_statements'
2627

2728
require 'active_model'
@@ -477,11 +478,6 @@ def execute_batch(statements, name = nil)
477478
execute(combine_multi_statements(statements), name)
478479
end
479480

480-
def explain(arel, binds = [])
481-
sql, binds = to_sql_and_binds(arel, binds)
482-
ActiveRecord::ConnectionAdapters::PostgreSQL::ExplainPrettyPrinter.new.pp(exec_query("EXPLAIN #{sql}", 'EXPLAIN', binds))
483-
end
484-
485481
# from ActiveRecord::ConnectionAdapters::PostgreSQL::DatabaseStatements
486482
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
487483
:close, :declare, :fetch, :move, :set, :show
@@ -809,6 +805,7 @@ class PostgreSQLAdapter < AbstractAdapter
809805

810806
require 'arjdbc/postgresql/oid_types'
811807
include ::ArJdbc::PostgreSQL::OIDTypes
808+
include ::ArJdbc::PostgreSQL::DatabaseStatements
812809
include ::ArJdbc::PostgreSQL::SchemaStatements
813810

814811
include ::ArJdbc::PostgreSQL::ColumnHelpers
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
module ArJdbc
4+
module PostgreSQL
5+
module DatabaseStatements
6+
def explain(arel, binds = [], options = [])
7+
sql = build_explain_clause(options) + " " + to_sql(arel, binds)
8+
result = internal_exec_query(sql, "EXPLAIN", binds)
9+
ActiveRecord::ConnectionAdapters::PostgreSQL::ExplainPrettyPrinter.new.pp(result)
10+
end
11+
12+
def build_explain_clause(options = [])
13+
return "EXPLAIN" if options.empty?
14+
15+
"EXPLAIN (#{options.join(", ").upcase})"
16+
end
17+
end
18+
end
19+
end

0 commit comments

Comments
 (0)