@@ -6,21 +6,30 @@ module PostgresqlExecQuery
6
6
module_function
7
7
8
8
def call ( conn , statement )
9
- conn . send ( :execute_and_clear , *statement ) do |result |
10
- types = { }
11
- fields = result . fields
12
-
13
- fields . each_with_index do |fname , i |
14
- ftype = result . ftype i
15
- fmod = result . fmod i
16
- types [ fname ] = conn . send ( :get_oid_type , ftype , fmod , fname )
9
+ if Rails . version . to_f >= 8.0
10
+ result = conn . send ( :internal_execute , *statement )
11
+ process_result ( conn , result )
12
+ else
13
+ conn . send ( :execute_and_clear , *statement ) do |result |
14
+ process_result ( conn , result )
17
15
end
16
+ end
17
+ end
18
18
19
- if conn . respond_to? ( :build_result , true )
20
- conn . send ( :build_result , columns : fields , rows : result . values , column_types : types )
21
- else
22
- ActiveRecord ::Result . new ( fields , result . values , types )
23
- end
19
+ def process_result ( conn , result )
20
+ types = { }
21
+ fields = result . fields
22
+
23
+ fields . each_with_index do |fname , i |
24
+ ftype = result . ftype i
25
+ fmod = result . fmod i
26
+ types [ fname ] = conn . send ( :get_oid_type , ftype , fmod , fname )
27
+ end
28
+
29
+ if conn . respond_to? ( :build_result , true )
30
+ conn . send ( :build_result , columns : fields , rows : result . values , column_types : types )
31
+ else
32
+ ActiveRecord ::Result . new ( fields , result . values , types )
24
33
end
25
34
end
26
35
end
0 commit comments