ovirt_metrics 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -1
  3. data/lib/active_record/connection_adapters/ovirt_postgresql_adapter.rb +31 -0
  4. data/lib/ovirt_metrics/version.rb +1 -1
  5. data/lib/ovirt_metrics.rb +4 -1
  6. data/spec/spec_helper.rb +3 -0
  7. metadata +37 -50
  8. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/column.rb +0 -15
  9. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/database_statements.rb +0 -170
  10. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/explain_pretty_printer.rb +0 -42
  11. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/array.rb +0 -70
  12. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit.rb +0 -52
  13. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit_varying.rb +0 -13
  14. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bytea.rb +0 -15
  15. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/cidr.rb +0 -48
  16. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/date_time.rb +0 -21
  17. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/decimal.rb +0 -13
  18. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/enum.rb +0 -19
  19. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/hstore.rb +0 -59
  20. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/inet.rb +0 -13
  21. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/json.rb +0 -10
  22. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/jsonb.rb +0 -23
  23. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/money.rb +0 -39
  24. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/point.rb +0 -43
  25. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/rails_5_1_point.rb +0 -50
  26. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/range.rb +0 -93
  27. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/specialized_string.rb +0 -15
  28. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/type_map_initializer.rb +0 -109
  29. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/uuid.rb +0 -21
  30. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/vector.rb +0 -26
  31. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/xml.rb +0 -28
  32. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid.rb +0 -31
  33. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/quoting.rb +0 -116
  34. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/referential_integrity.rb +0 -49
  35. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_definitions.rb +0 -180
  36. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_dumper.rb +0 -47
  37. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_statements.rb +0 -682
  38. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/type_metadata.rb +0 -35
  39. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/utils.rb +0 -77
  40. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql_adapter.rb +0 -856
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ffd084cdcd5c83f2b33a5f3be6d484bc18e5692dcd25b1733dc4217159fc4b8
4
- data.tar.gz: d4c597c0ed52ffd470f5e58409b8002e579c03fd45de8cba1e4e5da38bb1e5dd
3
+ metadata.gz: 6211f1ed82214c903ff55a414db74930b58ee2bdc4c581f22cb3dd3f4f01bd3a
4
+ data.tar.gz: aa3a4075b113230c0c1f19d80c5d8c43a82dafacd34dc2b64b1c867d3b8a4d0f
5
5
  SHA512:
6
- metadata.gz: 4ff0a5552bb9aba180e47cfe4323d4a339620fdb66d9f599fda37882a54572dcc3821cad58c836995d4ad45cf8cd0213038842d1fb813b177085527a93b297b8
7
- data.tar.gz: 76e40dacb3023e84f38710cda3a6a643cac7e82b81ee0c41e543e5b68612504df62d6decea25434ba8c17f00626f27400ee34f3cd9e4ab41aee3ea68e476737d
6
+ metadata.gz: 59e4b4e747d95bd9f75e511a135636b0aa09065516b3cc11d1aa7176fb3b496b2463518b6dbf4d1de6cd11e9f4de890509402e7b693245f1dfe03200cacd2e5d
7
+ data.tar.gz: 2151ec8e5dfc07cc350c4f7b1bc6bd51377d22d7242f0bd897913aab35b8d8d705b9ba4c24dd43b2776424c911a2a7dbcf6001d5ccd57ca86b47ab62338876dc
data/README.md CHANGED
@@ -4,7 +4,6 @@
4
4
  [![Build Status](https://travis-ci.org/ManageIQ/ovirt_metrics.svg?branch=master)](https://travis-ci.org/ManageIQ/ovirt_metrics)
5
5
  [![Code Climate](http://img.shields.io/codeclimate/github/ManageIQ/ovirt_metrics.svg)](https://codeclimate.com/github/ManageIQ/ovirt_metrics)
6
6
  [![Coverage Status](http://img.shields.io/coveralls/ManageIQ/ovirt_metrics.svg)](https://coveralls.io/r/ManageIQ/ovirt_metrics)
7
- [![Dependency Status](https://gemnasium.com/ManageIQ/ovirt_metrics.svg)](https://gemnasium.com/ManageIQ/ovirt_metrics)
8
7
 
9
8
  OvirtMetrics is an ActiveRecord-based gem for reading the oVirt History database.
10
9
 
@@ -0,0 +1,31 @@
1
+ module ActiveRecord
2
+ module ConnectionHandling # :nodoc:
3
+ def ovirt_postgresql_connection(config)
4
+ conn_params = config.symbolize_keys
5
+
6
+ conn_params.delete_if { |_, v| v.nil? }
7
+
8
+ conn_params[:user] = conn_params.delete(:username) if conn_params[:username]
9
+ conn_params[:dbname] = conn_params.delete(:database) if conn_params[:database]
10
+
11
+ valid_conn_param_keys = PG::Connection.conndefaults_hash.keys + [:requiressl]
12
+ conn_params.slice!(*valid_conn_param_keys)
13
+
14
+ conn = PG.connect(conn_params) if ActiveRecord::VERSION::MAJOR >= 6
15
+ ConnectionAdapters::OvirtPostgreSQLAdapter.new(conn, logger, conn_params, config)
16
+ end
17
+ end
18
+
19
+ module ConnectionAdapters
20
+ class OvirtPostgreSQLAdapter < PostgreSQLAdapter
21
+ ADAPTER_NAME = "OvirtPostgreSQL"
22
+
23
+ def check_version
24
+ msg = "The version of PostgreSQL (#{postgresql_version}) is too old (9.2+ required)"
25
+ if postgresql_version < 90200
26
+ raise msg
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module OvirtMetrics
2
- VERSION = "3.0.0"
2
+ VERSION = "3.1.0"
3
3
  end
data/lib/ovirt_metrics.rb CHANGED
@@ -27,7 +27,10 @@ module OvirtMetrics
27
27
  opts ||= {}
28
28
  opts[:port] ||= 5432
29
29
  opts[:database] ||= DEFAULT_HISTORY_DATABASE_NAME
30
- opts[:adapter] = 'postgresql'
30
+ opts[:adapter] = begin
31
+ require "active_record/connection_adapters/ovirt_postgresql_adapter"
32
+ 'ovirt_postgresql'
33
+ end
31
34
 
32
35
  # Don't allow accidental connections to localhost. A blank host will
33
36
  # connect to localhost, so don't allow that at all.
data/spec/spec_helper.rb CHANGED
@@ -93,3 +93,6 @@ OvirtMetrics.config do |c|
93
93
  end
94
94
  ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:"
95
95
 
96
+ require "active_record"
97
+ puts
98
+ puts "\e[93mUsing ActiveRecord #{ActiveRecord.version}\e[0m"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ovirt_metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Barenboim
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-07-23 00:00:00.000000000 Z
12
+ date: 2022-02-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -26,7 +26,21 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
- name: rake
29
+ name: coveralls
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: manageiq-style
30
44
  requirement: !ruby/object:Gem::Requirement
31
45
  requirements:
32
46
  - - ">="
@@ -54,35 +68,35 @@ dependencies:
54
68
  - !ruby/object:Gem::Version
55
69
  version: '0'
56
70
  - !ruby/object:Gem::Dependency
57
- name: rspec
71
+ name: rake
58
72
  requirement: !ruby/object:Gem::Requirement
59
73
  requirements:
60
74
  - - ">="
61
75
  - !ruby/object:Gem::Version
62
- version: '3.0'
76
+ version: '0'
63
77
  type: :development
64
78
  prerelease: false
65
79
  version_requirements: !ruby/object:Gem::Requirement
66
80
  requirements:
67
81
  - - ">="
68
82
  - !ruby/object:Gem::Version
69
- version: '3.0'
83
+ version: '0'
70
84
  - !ruby/object:Gem::Dependency
71
- name: sqlite3
85
+ name: rspec
72
86
  requirement: !ruby/object:Gem::Requirement
73
87
  requirements:
74
- - - "~>"
88
+ - - ">="
75
89
  - !ruby/object:Gem::Version
76
- version: 1.3.6
90
+ version: '3.0'
77
91
  type: :development
78
92
  prerelease: false
79
93
  version_requirements: !ruby/object:Gem::Requirement
80
94
  requirements:
81
- - - "~>"
95
+ - - ">="
82
96
  - !ruby/object:Gem::Version
83
- version: 1.3.6
97
+ version: '3.0'
84
98
  - !ruby/object:Gem::Dependency
85
- name: coveralls
99
+ name: sqlite3
86
100
  requirement: !ruby/object:Gem::Requirement
87
101
  requirements:
88
102
  - - ">="
@@ -99,16 +113,22 @@ dependencies:
99
113
  name: activerecord
100
114
  requirement: !ruby/object:Gem::Requirement
101
115
  requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '5.0'
102
119
  - - "<"
103
120
  - !ruby/object:Gem::Version
104
- version: '5.3'
121
+ version: '7.0'
105
122
  type: :runtime
106
123
  prerelease: false
107
124
  version_requirements: !ruby/object:Gem::Requirement
108
125
  requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '5.0'
109
129
  - - "<"
110
130
  - !ruby/object:Gem::Version
111
- version: '5.3'
131
+ version: '7.0'
112
132
  - !ruby/object:Gem::Dependency
113
133
  name: pg
114
134
  requirement: !ruby/object:Gem::Requirement
@@ -135,39 +155,7 @@ files:
135
155
  - ".rspec"
136
156
  - LICENSE.txt
137
157
  - README.md
138
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/column.rb
139
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/database_statements.rb
140
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/explain_pretty_printer.rb
141
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid.rb
142
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/array.rb
143
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit.rb
144
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit_varying.rb
145
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bytea.rb
146
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/cidr.rb
147
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/date_time.rb
148
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/decimal.rb
149
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/enum.rb
150
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/hstore.rb
151
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/inet.rb
152
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/json.rb
153
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/jsonb.rb
154
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/money.rb
155
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/point.rb
156
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/rails_5_1_point.rb
157
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/range.rb
158
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/specialized_string.rb
159
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/type_map_initializer.rb
160
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/uuid.rb
161
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/vector.rb
162
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/xml.rb
163
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/quoting.rb
164
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/referential_integrity.rb
165
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_definitions.rb
166
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_dumper.rb
167
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_statements.rb
168
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/type_metadata.rb
169
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql/utils.rb
170
- - lib/active_record/connection_adapters/ovirt_legacy_postgresql_adapter.rb
158
+ - lib/active_record/connection_adapters/ovirt_postgresql_adapter.rb
171
159
  - lib/ovirt_metrics.rb
172
160
  - lib/ovirt_metrics/column_definitions.rb
173
161
  - lib/ovirt_metrics/configurator.rb
@@ -236,15 +224,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
236
224
  requirements:
237
225
  - - ">="
238
226
  - !ruby/object:Gem::Version
239
- version: 2.3.1
227
+ version: 2.5.8
240
228
  required_rubygems_version: !ruby/object:Gem::Requirement
241
229
  requirements:
242
230
  - - ">="
243
231
  - !ruby/object:Gem::Version
244
232
  version: '0'
245
233
  requirements: []
246
- rubyforge_project:
247
- rubygems_version: 2.7.6.2
234
+ rubygems_version: 3.3.5
248
235
  signing_key:
249
236
  specification_version: 4
250
237
  summary: OvirtMetrics is an ActiveRecord-based gem for reading the oVirt History database.
@@ -1,15 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- # PostgreSQL-specific extensions to column definitions in a table.
4
- class OvirtLegacyPostgreSQLColumn < Column #:nodoc:
5
- delegate :array, :oid, :fmod, to: :sql_type_metadata
6
- alias :array? :array
7
-
8
- def serial?
9
- return unless default_function
10
-
11
- %r{\Anextval\('"?#{table_name}_#{name}_seq"?'::regclass\)\z} === default_function
12
- end
13
- end
14
- end
15
- end
@@ -1,170 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module OvirtLegacyPostgreSQL
4
- module DatabaseStatements
5
- def explain(arel, binds = [])
6
- sql = "EXPLAIN #{to_sql(arel, binds)}"
7
- OvirtLegacyPostgreSQL::ExplainPrettyPrinter.new.pp(exec_query(sql, 'EXPLAIN', binds))
8
- end
9
-
10
- def select_value(arel, name = nil, binds = [])
11
- arel, binds = binds_from_relation arel, binds
12
- sql = to_sql(arel, binds)
13
- execute_and_clear(sql, name, binds) do |result|
14
- result.getvalue(0, 0) if result.ntuples > 0 && result.nfields > 0
15
- end
16
- end
17
-
18
- def select_values(arel, name = nil, binds = [])
19
- arel, binds = binds_from_relation arel, binds
20
- sql = to_sql(arel, binds)
21
- execute_and_clear(sql, name, binds) do |result|
22
- if result.nfields > 0
23
- result.column_values(0)
24
- else
25
- []
26
- end
27
- end
28
- end
29
-
30
- # Executes a SELECT query and returns an array of rows. Each row is an
31
- # array of field values.
32
- def select_rows(sql, name = nil, binds = [])
33
- execute_and_clear(sql, name, binds) do |result|
34
- result.values
35
- end
36
- end
37
-
38
- # The internal PostgreSQL identifier of the money data type.
39
- MONEY_COLUMN_TYPE_OID = 790 #:nodoc:
40
- # The internal PostgreSQL identifier of the BYTEA data type.
41
- BYTEA_COLUMN_TYPE_OID = 17 #:nodoc:
42
-
43
- # create a 2D array representing the result set
44
- def result_as_array(res) #:nodoc:
45
- # check if we have any binary column and if they need escaping
46
- ftypes = Array.new(res.nfields) do |i|
47
- [i, res.ftype(i)]
48
- end
49
-
50
- rows = res.values
51
- return rows unless ftypes.any? { |_, x|
52
- x == BYTEA_COLUMN_TYPE_OID || x == MONEY_COLUMN_TYPE_OID
53
- }
54
-
55
- typehash = ftypes.group_by { |_, type| type }
56
- binaries = typehash[BYTEA_COLUMN_TYPE_OID] || []
57
- monies = typehash[MONEY_COLUMN_TYPE_OID] || []
58
-
59
- rows.each do |row|
60
- # unescape string passed BYTEA field (OID == 17)
61
- binaries.each do |index, _|
62
- row[index] = unescape_bytea(row[index])
63
- end
64
-
65
- # If this is a money type column and there are any currency symbols,
66
- # then strip them off. Indeed it would be prettier to do this in
67
- # OvirtLegacyPostgreSQLColumn.string_to_decimal but would break form input
68
- # fields that call value_before_type_cast.
69
- monies.each do |index, _|
70
- data = row[index]
71
- # Because money output is formatted according to the locale, there are two
72
- # cases to consider (note the decimal separators):
73
- # (1) $12,345,678.12
74
- # (2) $12.345.678,12
75
- case data
76
- when /^-?\D+[\d,]+\.\d{2}$/ # (1)
77
- data.gsub!(/[^-\d.]/, '')
78
- when /^-?\D+[\d.]+,\d{2}$/ # (2)
79
- data.gsub!(/[^-\d,]/, '').sub!(/,/, '.')
80
- end
81
- end
82
- end
83
- end
84
-
85
- # Queries the database and returns the results in an Array-like object
86
- def query(sql, name = nil) #:nodoc:
87
- log(sql, name) do
88
- result_as_array @connection.async_exec(sql)
89
- end
90
- end
91
-
92
- # Executes an SQL statement, returning a PGresult object on success
93
- # or raising a PGError exception otherwise.
94
- # Note: the PGresult object is manually memory managed; if you don't
95
- # need it specifically, you many want consider the exec_query wrapper.
96
- def execute(sql, name = nil)
97
- log(sql, name) do
98
- @connection.async_exec(sql)
99
- end
100
- end
101
-
102
- def exec_query(sql, name = 'SQL', binds = [], prepare: false)
103
- execute_and_clear(sql, name, binds, prepare: prepare) do |result|
104
- types = {}
105
- fields = result.fields
106
- fields.each_with_index do |fname, i|
107
- ftype = result.ftype i
108
- fmod = result.fmod i
109
- types[fname] = get_oid_type(ftype, fmod, fname)
110
- end
111
- ActiveRecord::Result.new(fields, result.values, types)
112
- end
113
- end
114
-
115
- def exec_delete(sql, name = 'SQL', binds = [])
116
- execute_and_clear(sql, name, binds) {|result| result.cmd_tuples }
117
- end
118
- alias :exec_update :exec_delete
119
-
120
- def sql_for_insert(sql, pk, id_value, sequence_name, binds) # :nodoc:
121
- if pk.nil?
122
- # Extract the table from the insert sql. Yuck.
123
- table_ref = extract_table_ref_from_insert_sql(sql)
124
- pk = primary_key(table_ref) if table_ref
125
- end
126
-
127
- if pk && use_insert_returning?
128
- sql = "#{sql} RETURNING #{quote_column_name(pk)}"
129
- end
130
-
131
- super
132
- end
133
-
134
- def exec_insert(sql, name, binds, pk = nil, sequence_name = nil)
135
- val = exec_query(sql, name, binds)
136
- if !use_insert_returning? && pk
137
- unless sequence_name
138
- table_ref = extract_table_ref_from_insert_sql(sql)
139
- sequence_name = default_sequence_name(table_ref, pk)
140
- return val unless sequence_name
141
- end
142
- last_insert_id_result(sequence_name)
143
- else
144
- val
145
- end
146
- end
147
-
148
- # Begins a transaction.
149
- def begin_db_transaction
150
- execute "BEGIN"
151
- end
152
-
153
- def begin_isolated_db_transaction(isolation)
154
- begin_db_transaction
155
- execute "SET TRANSACTION ISOLATION LEVEL #{transaction_isolation_levels.fetch(isolation)}"
156
- end
157
-
158
- # Commits a transaction.
159
- def commit_db_transaction
160
- execute "COMMIT"
161
- end
162
-
163
- # Aborts a transaction.
164
- def exec_rollback_db_transaction
165
- execute "ROLLBACK"
166
- end
167
- end
168
- end
169
- end
170
- end
@@ -1,42 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module OvirtLegacyPostgreSQL
4
- class ExplainPrettyPrinter # :nodoc:
5
- # Pretty prints the result of an EXPLAIN in a way that resembles the output of the
6
- # PostgreSQL shell:
7
- #
8
- # QUERY PLAN
9
- # ------------------------------------------------------------------------------
10
- # Nested Loop Left Join (cost=0.00..37.24 rows=8 width=0)
11
- # Join Filter: (posts.user_id = users.id)
12
- # -> Index Scan using users_pkey on users (cost=0.00..8.27 rows=1 width=4)
13
- # Index Cond: (id = 1)
14
- # -> Seq Scan on posts (cost=0.00..28.88 rows=8 width=4)
15
- # Filter: (posts.user_id = 1)
16
- # (6 rows)
17
- #
18
- def pp(result)
19
- header = result.columns.first
20
- lines = result.rows.map(&:first)
21
-
22
- # We add 2 because there's one char of padding at both sides, note
23
- # the extra hyphens in the example above.
24
- width = [header, *lines].map(&:length).max + 2
25
-
26
- pp = []
27
-
28
- pp << header.center(width).rstrip
29
- pp << '-' * width
30
-
31
- pp += lines.map {|line| " #{line}"}
32
-
33
- nrows = result.rows.length
34
- rows_label = nrows == 1 ? 'row' : 'rows'
35
- pp << "(#{nrows} #{rows_label})"
36
-
37
- pp.join("\n") + "\n"
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,70 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module OvirtLegacyPostgreSQL
4
- module OID # :nodoc:
5
- class Array < Type::Value # :nodoc:
6
- include Type::Helpers::Mutable
7
-
8
- attr_reader :subtype, :delimiter
9
- delegate :type, :user_input_in_time_zone, :limit, to: :subtype
10
-
11
- def initialize(subtype, delimiter = ',')
12
- @subtype = subtype
13
- @delimiter = delimiter
14
-
15
- @pg_encoder = PG::TextEncoder::Array.new name: "#{type}[]", delimiter: delimiter
16
- @pg_decoder = PG::TextDecoder::Array.new name: "#{type}[]", delimiter: delimiter
17
- end
18
-
19
- def deserialize(value)
20
- if value.is_a?(::String)
21
- type_cast_array(@pg_decoder.decode(value), :deserialize)
22
- else
23
- super
24
- end
25
- end
26
-
27
- def cast(value)
28
- if value.is_a?(::String)
29
- value = @pg_decoder.decode(value)
30
- end
31
- type_cast_array(value, :cast)
32
- end
33
-
34
- def serialize(value)
35
- if value.is_a?(::Array)
36
- @pg_encoder.encode(type_cast_array(value, :serialize))
37
- else
38
- super
39
- end
40
- end
41
-
42
- def ==(other)
43
- other.is_a?(Array) &&
44
- subtype == other.subtype &&
45
- delimiter == other.delimiter
46
- end
47
-
48
- def type_cast_for_schema(value)
49
- return super unless value.is_a?(::Array)
50
- "[" + value.map { |v| subtype.type_cast_for_schema(v) }.join(", ") + "]"
51
- end
52
-
53
- def map(value, &block)
54
- value.map(&block)
55
- end
56
-
57
- private
58
-
59
- def type_cast_array(value, method)
60
- if value.is_a?(::Array)
61
- value.map { |item| type_cast_array(item, method) }
62
- else
63
- @subtype.public_send(method, value)
64
- end
65
- end
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,52 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module OvirtLegacyPostgreSQL
4
- module OID # :nodoc:
5
- class Bit < Type::Value # :nodoc:
6
- def type
7
- :bit
8
- end
9
-
10
- def cast(value)
11
- if ::String === value
12
- case value
13
- when /^0x/i
14
- value[2..-1].hex.to_s(2) # Hexadecimal notation
15
- else
16
- value # Bit-string notation
17
- end
18
- else
19
- value
20
- end
21
- end
22
-
23
- def serialize(value)
24
- Data.new(super) if value
25
- end
26
-
27
- class Data
28
- def initialize(value)
29
- @value = value
30
- end
31
-
32
- def to_s
33
- value
34
- end
35
-
36
- def binary?
37
- /\A[01]*\Z/ === value
38
- end
39
-
40
- def hex?
41
- /\A[0-9A-F]*\Z/i === value
42
- end
43
-
44
- protected
45
-
46
- attr_reader :value
47
- end
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,13 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module OvirtLegacyPostgreSQL
4
- module OID # :nodoc:
5
- class BitVarying < OID::Bit # :nodoc:
6
- def type
7
- :bit_varying
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,15 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module OvirtLegacyPostgreSQL
4
- module OID # :nodoc:
5
- class Bytea < Type::Binary # :nodoc:
6
- def deserialize(value)
7
- return if value.nil?
8
- return value.to_s if value.is_a?(Type::Binary::Data)
9
- PGconn.unescape_bytea(super)
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,48 +0,0 @@
1
- require 'ipaddr'
2
-
3
- module ActiveRecord
4
- module ConnectionAdapters
5
- module OvirtLegacyPostgreSQL
6
- module OID # :nodoc:
7
- class Cidr < Type::Value # :nodoc:
8
- def type
9
- :cidr
10
- end
11
-
12
- def type_cast_for_schema(value)
13
- subnet_mask = value.instance_variable_get(:@mask_addr)
14
-
15
- # If the subnet mask is equal to /32, don't output it
16
- if subnet_mask == (2**32 - 1)
17
- "\"#{value}\""
18
- else
19
- "\"#{value}/#{subnet_mask.to_s(2).count('1')}\""
20
- end
21
- end
22
-
23
- def serialize(value)
24
- if IPAddr === value
25
- "#{value}/#{value.instance_variable_get(:@mask_addr).to_s(2).count('1')}"
26
- else
27
- value
28
- end
29
- end
30
-
31
- def cast_value(value)
32
- if value.nil?
33
- nil
34
- elsif String === value
35
- begin
36
- IPAddr.new(value)
37
- rescue ArgumentError
38
- nil
39
- end
40
- else
41
- value
42
- end
43
- end
44
- end
45
- end
46
- end
47
- end
48
- end