@@ -6,11 +6,12 @@ module ArJdbc
66 # Strives to provide Rails built-in PostgreSQL adapter (API) compatibility.
77 module PostgreSQL
88
9+ # @deprecated no longer used
910 # @private
10- AR4_COMPAT = ::ActiveRecord ::VERSION ::MAJOR > 3 unless const_defined? ( :AR4_COMPAT )
11+ AR4_COMPAT = AR40
12+ # @deprecated no longer used
1113 # @private
12- AR42_COMPAT = ::ActiveRecord ::VERSION ::MAJOR > 4 ||
13- ( ::ActiveRecord ::VERSION ::MAJOR == 4 && ::ActiveRecord ::VERSION ::MINOR >= 2 )
14+ AR42_COMPAT = AR42
1415
1516 require 'arjdbc/postgresql/column'
1617 require 'arjdbc/postgresql/explain_support'
@@ -22,7 +23,7 @@ module PostgreSQL
2223 ForeignKeyDefinition = ::ActiveRecord ::ConnectionAdapters ::ForeignKeyDefinition if ::ActiveRecord ::ConnectionAdapters . const_defined? :ForeignKeyDefinition
2324
2425 # @private
25- Type = ::ActiveRecord ::Type if AR42_COMPAT
26+ Type = ::ActiveRecord ::Type if AR42
2627
2728 # @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
2829 def self . jdbc_connection_class
@@ -217,7 +218,7 @@ def type_cast(value, column, array_member = false)
217218 else
218219 super ( value , column )
219220 end
220- end if AR4_COMPAT && ! AR42_COMPAT
221+ end if AR40 && ! AR42
221222
222223 # @private
223224 def _type_cast ( value )
@@ -232,8 +233,8 @@ def _type_cast(value)
232233 else
233234 super
234235 end
235- end if AR42_COMPAT
236- private :_type_cast if AR42_COMPAT
236+ end if AR42
237+ private :_type_cast if AR42
237238
238239 NATIVE_DATABASE_TYPES = {
239240 :primary_key => "serial primary key" ,
@@ -275,14 +276,14 @@ def _type_cast(value)
275276 :tstzrange => { :name => "tstzrange" } ,
276277 :int4range => { :name => "int4range" } ,
277278 :int8range => { :name => "int8range" } ,
278- } ) if AR4_COMPAT
279+ } ) if AR40
279280
280281 NATIVE_DATABASE_TYPES . update (
281282 :bigserial => "bigserial" ,
282283 :bigint => { :name => "bigint" } ,
283284 :bit => { :name => "bit" } ,
284285 :bit_varying => { :name => "bit varying" }
285- ) if AR42_COMPAT
286+ ) if AR42
286287
287288 def native_database_types
288289 NATIVE_DATABASE_TYPES
@@ -295,13 +296,13 @@ def prepare_column_options(column, types)
295296 spec [ :array ] = 'true' if column . respond_to? ( :array ) && column . array
296297 spec [ :default ] = "\" #{ column . default_function } \" " if column . default_function
297298 spec
298- end if AR4_COMPAT
299+ end if AR40
299300
300301 # Adds `:array` as a valid migration key.
301302 # @override
302303 def migration_keys
303304 super + [ :array ]
304- end if AR4_COMPAT
305+ end if AR40
305306
306307 # Enable standard-conforming strings if available.
307308 def set_standard_conforming_strings
@@ -369,12 +370,12 @@ def supports_transaction_isolation?; true end
369370
370371 def supports_index_sort_order? ; true end
371372
372- def supports_partial_index? ; true end if AR4_COMPAT
373+ def supports_partial_index? ; true end if AR40
373374
374375 # Range data-types weren't introduced until PostgreSQL 9.2.
375376 def supports_ranges?
376377 postgresql_version >= 90200
377- end if AR4_COMPAT
378+ end if AR40
378379
379380 def supports_transaction_isolation? ( level = nil )
380381 true
@@ -875,7 +876,7 @@ def quote(value, column = nil)
875876 sql_type = column . respond_to? ( :sql_type ) && column . sql_type
876877 sql_type && sql_type [ 0 , 3 ] == 'bit' ? quote_bit ( value ) : super
877878 when Array
878- if AR4_COMPAT && column . array? # will be always falsy in AR < 4.0
879+ if AR40 && column . array? # will be always falsy in AR < 4.0
879880 "'#{ jdbc_column_class . array_to_string ( value , column , self ) . gsub ( /'/ , "''" ) } '"
880881 elsif column . type == :json # only in AR-4.0
881882 super ( jdbc_column_class . json_to_string ( value ) , column )
@@ -896,7 +897,7 @@ def quote(value, column = nil)
896897 end
897898 when Range
898899 sql_type = column . respond_to? ( :sql_type ) && column . sql_type
899- if sql_type && sql_type [ -5 , 5 ] == 'range' && AR4_COMPAT
900+ if sql_type && sql_type [ -5 , 5 ] == 'range' && AR40
900901 escaped = quote_string ( jdbc_column_class . range_to_string ( value ) )
901902 "'#{ escaped } '::#{ sql_type } "
902903 else super
@@ -909,7 +910,7 @@ def quote(value, column = nil)
909910 else
910911 super
911912 end
912- end unless AR42_COMPAT
913+ end unless AR42
913914
914915 # @private
915916 def _quote ( value )
@@ -933,8 +934,8 @@ def _quote(value)
933934 else
934935 super
935936 end
936- end if AR42_COMPAT
937- private :_quote if AR42_COMPAT
937+ end if AR42
938+ private :_quote if AR42
938939
939940 # Quotes a string, escaping any ' (single quote) and \ (backslash) chars.
940941 # @return [String]
@@ -963,7 +964,7 @@ def quote_bit(value)
963964
964965 def quote_bit ( value )
965966 "B'#{ value } '"
966- end if AR4_COMPAT
967+ end if AR40
967968
968969 def escape_bytea ( string )
969970 return unless string
@@ -991,7 +992,7 @@ def quote_table_name(name)
991992 # @override
992993 def quote_table_name_for_assignment ( table , attr )
993994 quote_column_name ( attr )
994- end if AR4_COMPAT
995+ end if AR40
995996
996997 # @override
997998 def quote_column_name ( name )
@@ -1074,7 +1075,7 @@ def add_column(table_name, column_name, type, options = {})
10741075 end if ::ActiveRecord ::VERSION ::MAJOR < 4
10751076
10761077 # @private documented above
1077- def add_column ( table_name , column_name , type , options = { } ) ; super end if AR42_COMPAT
1078+ def add_column ( table_name , column_name , type , options = { } ) ; super end if AR42
10781079
10791080 # Changes the column of a table.
10801081 def change_column ( table_name , column_name , type , options = { } )
@@ -1124,7 +1125,7 @@ def change_column_default(table_name, column_name, default)
11241125 else
11251126 execute "ALTER TABLE #{ quote_table_name ( table_name ) } ALTER COLUMN #{ quote_column_name ( column_name ) } SET DEFAULT #{ quote ( default ) } "
11261127 end
1127- end unless AR42_COMPAT # unless const_defined? :SchemaCreation
1128+ end unless AR42 # unless const_defined? :SchemaCreation
11281129
11291130 # @private documented above
11301131 def change_column_default ( table_name , column_name , default )
@@ -1138,7 +1139,7 @@ def change_column_default(table_name, column_name, default)
11381139 else
11391140 execute alter_column_query % "SET DEFAULT #{ quote_default_value ( default , column ) } "
11401141 end
1141- end if AR42_COMPAT
1142+ end if AR42
11421143
11431144 # @private
11441145 def change_column_null ( table_name , column_name , null , default = nil )
@@ -1150,7 +1151,7 @@ def change_column_null(table_name, column_name, null, default = nil)
11501151 end
11511152 end
11521153 execute ( "ALTER TABLE #{ quote_table_name ( table_name ) } ALTER #{ quote_column_name ( column_name ) } #{ null ? 'DROP' : 'SET' } NOT NULL" )
1153- end unless AR42_COMPAT # unless const_defined? :SchemaCreation
1154+ end unless AR42 # unless const_defined? :SchemaCreation
11541155
11551156 # @private
11561157 def change_column_null ( table_name , column_name , null , default = nil )
@@ -1159,7 +1160,7 @@ def change_column_null(table_name, column_name, null, default = nil)
11591160 execute ( "UPDATE #{ quote_table_name ( table_name ) } SET #{ quote_column_name ( column_name ) } =#{ quote_default_value ( default , column ) } WHERE #{ quote_column_name ( column_name ) } IS NULL" ) if column
11601161 end
11611162 execute ( "ALTER TABLE #{ quote_table_name ( table_name ) } ALTER #{ quote_column_name ( column_name ) } #{ null ? 'DROP' : 'SET' } NOT NULL" )
1162- end if AR42_COMPAT
1163+ end if AR42
11631164
11641165 def rename_column ( table_name , column_name , new_column_name )
11651166 execute "ALTER TABLE #{ quote_table_name ( table_name ) } RENAME COLUMN #{ quote_column_name ( column_name ) } TO #{ quote_column_name ( new_column_name ) } "
@@ -1169,7 +1170,7 @@ def rename_column(table_name, column_name, new_column_name)
11691170 def add_index ( table_name , column_name , options = { } )
11701171 index_name , index_type , index_columns , index_options , index_algorithm , index_using = add_index_options ( table_name , column_name , options )
11711172 execute "CREATE #{ index_type } INDEX #{ index_algorithm } #{ quote_column_name ( index_name ) } ON #{ quote_table_name ( table_name ) } #{ index_using } (#{ index_columns } )#{ index_options } "
1172- end if AR4_COMPAT
1173+ end if AR40
11731174
11741175 def remove_index! ( table_name , index_name )
11751176 execute "DROP INDEX #{ quote_table_name ( index_name ) } "
@@ -1259,12 +1260,12 @@ def columns(table_name)
12591260
12601261 column . new ( name , default_value , oid_type , type , ! notnull , default_function , oid , self )
12611262 end
1262- end if AR42_COMPAT
1263+ end if AR42
12631264
12641265 # @private only for API compatibility
12651266 def new_column ( name , default , cast_type , sql_type = nil , null = true , default_function = nil )
12661267 jdbc_column_class . new ( name , default , cast_type , sql_type , null , default_function )
1267- end if AR42_COMPAT
1268+ end if AR42
12681269
12691270 # @private
12701271 def column_for ( table_name , column_name )
@@ -1306,7 +1307,7 @@ def tables(name = nil)
13061307 # @private
13071308 TABLE_EXISTS_SQL_PREFIX = 'SELECT COUNT(*) as table_count FROM pg_class c'
13081309 TABLE_EXISTS_SQL_PREFIX << ' LEFT JOIN pg_namespace n ON n.oid = c.relnamespace'
1309- if AR42_COMPAT # -- (r)elation/table, (v)iew, (m)aterialized view
1310+ if AR42 # -- (r)elation/table, (v)iew, (m)aterialized view
13101311 TABLE_EXISTS_SQL_PREFIX << " WHERE c.relkind IN ('r','v','m')"
13111312 else
13121313 TABLE_EXISTS_SQL_PREFIX << " WHERE c.relkind IN ('r','v')"
@@ -1349,7 +1350,7 @@ def index_name_exists?(table_name, index_name, default)
13491350 AND t.relname = '#{ table_name } '
13501351 AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname = ANY (current_schemas(false)) )
13511352 SQL
1352- end if AR42_COMPAT
1353+ end if AR42
13531354
13541355 # Returns an array of indexes for the given table.
13551356 def indexes ( table_name , name = nil )
@@ -1411,7 +1412,7 @@ def column_name_for_operation(operation, node)
14111412 when 'average' then 'avg'
14121413 else operation . downcase
14131414 end
1414- end if AR42_COMPAT
1415+ end if AR42
14151416
14161417 private
14171418
@@ -1474,9 +1475,9 @@ class PostgreSQLAdapter < JdbcAdapter
14741475 include ::ArJdbc ::PostgreSQL
14751476 include ::ArJdbc ::PostgreSQL ::ExplainSupport
14761477
1477- require 'arjdbc/postgresql/oid_types' if AR4_COMPAT
1478+ require 'arjdbc/postgresql/oid_types' if AR40
14781479 include ::ArJdbc ::PostgreSQL ::OIDTypes if ::ArJdbc ::PostgreSQL . const_defined? ( :OIDTypes )
1479- include ::ArJdbc ::PostgreSQL ::ColumnHelpers if AR42_COMPAT
1480+ include ::ArJdbc ::PostgreSQL ::ColumnHelpers if AR42
14801481
14811482 include ::ArJdbc ::Util ::QuotedCache
14821483
@@ -1488,13 +1489,13 @@ def initialize(*args)
14881489
14891490 @table_alias_length = nil
14901491
1491- initialize_type_map ( @type_map = Type ::HashLookupTypeMap . new ) if AR42_COMPAT
1492+ initialize_type_map ( @type_map = Type ::HashLookupTypeMap . new ) if AR42
14921493
14931494 @use_insert_returning = @config . key? ( :insert_returning ) ?
14941495 self . class . type_cast_config_to_boolean ( @config [ :insert_returning ] ) : nil
14951496 end
14961497
1497- if AR42_COMPAT
1498+ if AR42
14981499 require 'active_record/connection_adapters/postgresql/schema_definitions'
14991500 else
15001501 require 'arjdbc/postgresql/base/schema_definitions'
0 commit comments