activerecord-cubrid2-adapter 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c06a871f89134bc5f13e2905a30968756ade6e68f72d7c227e5b186e65d05cd3
4
- data.tar.gz: c20757cde7ba8620d30f8a6f5803695a1492f1690470a6bc0f0c13b21a8af375
3
+ metadata.gz: 5a4def5956cfad3d9c280869241d377182f2007624ff1ba2e9c90eb2ea456423
4
+ data.tar.gz: 21f100c281de6bb731613f8c2846c222330bd1044fd8785ba48b35611a6658b9
5
5
  SHA512:
6
- metadata.gz: e47475a4c8728ac72673f88abc60ab53179d6397d97930bf475f0b1005e0fe956ebed46ad5c16a16800bb4689d99626e074ba2136e4bff9e88c5a517f3f79da2
7
- data.tar.gz: 92bb1744b6427c10c923db59486e26c1687df128a63af79d842add0a3eb94d478d4db3fa0de6f73603aa25af074e3d517e1200d5d42af4b0696bed5e5c386759
6
+ metadata.gz: 35f826c22d9adec406b63ef687ca5ac12757fe59ffa2a7ebb534cbfa3ad6e28a45f154adcb809d1181f537b055e6569b0bb53abc33c49b63c1bc4b3e4b476651
7
+ data.tar.gz: c64e3974cfd3f960fa12d3e1fd8c3348f41a976d1f3d8797544fc128f01f299edd1c1bedf00790e2b5f8ce20e06a19ec669590f060a5c9ce9eedad3e6fbf679b
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ tests/test_cubrid3.rb
17
17
  tests/test_mysql.rb
18
18
  tests/test_pg.rb
19
19
 
20
+ activerecord-cubrid2-adapter-*.gem
data/README.md CHANGED
@@ -4,24 +4,25 @@ Cubrid database connector for ruby, and active_record, depends on 'cubrid' gem
4
4
  DESCRIPTION
5
5
  -----------
6
6
 
7
- Cubrid2 ActiveRecord adapter privides Cubrid database from Ruby on Rails applications. Now works with Ruby on Rails 6.0 and it is working with Cubrid database versions 9.x to higher.
8
-
9
- BUILD
10
- ------------
11
- ```ruby
12
- gem install rake-compiler
13
- rake build
14
- ```
7
+ Cubrid2 ActiveRecord adapter privides Cubrid database from Ruby on Rails applications. Now works with Ruby on Rails 6.0, 7.0 and it is working with Cubrid database versions 9.x to higher.
15
8
 
16
9
  INSTALLATION
17
10
  ------------
18
11
 
19
12
  ```ruby
20
13
  # Use cubrid as the database for Active Record
21
- gem 'cubrid' # cubrid interface gem, based on native CCI C interface
14
+ gem 'cubrid' # cubrid interface gem, based on native CCI C interface
15
+
16
+ # OR use local build
17
+ # git clone https://github.com/CUBRID/cubrid-ruby.git /opt/cubrid/cubrid-ruby
18
+ # cd /opt/cubrid/cubrid-ruby
19
+ # # goto directory and build cubrid-ruby
20
+
21
+ # gem 'cubrid', path: '/opt/cubrid/cubrid-ruby'
22
+
22
23
  gem 'activerecord-cubrid2-adapter'
23
24
  ```
24
- Currently Rails <6.0, >=7.0, Windows, JRuby is not tested.
25
+ Currently Rails Windows, JRuby is not tested.
25
26
 
26
27
  ### Without Rails and Bundler
27
28
 
@@ -31,9 +32,6 @@ If you want to use ActiveRecord and Cubrid2 adapter without Rails and Bundler th
31
32
  gem install activerecord-cubrid2-adapter
32
33
  ```
33
34
 
34
- USAGE
35
- -----
36
-
37
35
  ### Database connection
38
36
 
39
37
  In Rails application `config/database.yml` use 'cubrid2' as adapter name, e.g.
@@ -48,16 +46,27 @@ development:
48
46
  ```
49
47
 
50
48
  EXAMPLE
51
- -------------
49
+ -----
52
50
 
53
51
  Check test_activerecord.rb in the tests directory.
54
52
 
55
53
 
54
+ BUILDING GEM
55
+ -----
56
+
57
+ ```bash
58
+ gem install rake-compiler
59
+ rake build
60
+
61
+ # OR
62
+
63
+ gem build activerecord-cubrid2-adapter.gemspec
64
+ ```
65
+
56
66
  LINKS
57
67
  -----
58
68
 
59
- * Source code: https://github.com/damulhan/activerecord-cubrid2-adapter
60
- * Active Record – Object-relational mapping in Rails: https://github.com/rails/rails/tree/main/activerecord
61
- * Cubrid Ruby GEM: https://github.com/CUBRID/cubrid-ruby
69
+ * Active Record – Object-relational mapping in Rails: https://github.com/rails/rails/tree/main/activerecord
70
+ * Cubrid Ruby GEM: https://github.com/CUBRID/cubrid-ruby
62
71
  * Cubrid Homepage: https://www.cubrid.org
63
72
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.3
@@ -21,6 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
22
  spec.require_paths = ['lib']
23
23
 
24
- spec.add_dependency 'activerecord', '~> 6.0'
25
- spec.add_dependency 'cubrid', '>= 10.0'
24
+ spec.add_runtime_dependency 'activerecord', '~> 6.0', '>= 6.0'
25
+ spec.add_runtime_dependency 'cubrid', '~> 10.0', '>= 10.0'
26
26
  end
@@ -144,7 +144,7 @@ module ActiveRecord
144
144
  end
145
145
 
146
146
  def index_algorithms
147
- { }
147
+ {}
148
148
  end
149
149
 
150
150
  # HELPER METHODS ===========================================
@@ -176,10 +176,10 @@ module ActiveRecord
176
176
 
177
177
  # CONNECTION MANAGEMENT ====================================
178
178
 
179
- def clear_cache! # :nodoc:
180
- reload_type_map
181
- super
182
- end
179
+ # def clear_cache! # :nodoc:
180
+ # reload_type_map
181
+ # super
182
+ # end
183
183
 
184
184
  #--
185
185
  # DATABASE STATEMENTS ======================================
@@ -326,7 +326,12 @@ module ActiveRecord
326
326
  if supports_rename_index?
327
327
  validate_index_length!(table_name, new_name)
328
328
 
329
- execute "ALTER TABLE #{quote_table_name(table_name)} RENAME INDEX #{quote_table_name(old_name)} TO #{quote_table_name(new_name)}"
329
+ # NOTE: Renaming table index SQL would not work.
330
+ # See: https://www.cubrid.org/manual/ko/10.2/sql/schema/index_stmt.html#alter-index
331
+ # https://www.cubrid.com/index.php?mid=qna&document_srl=3802148
332
+ _query = "ALTER INDEX #{quote_table_name(old_name)} ON #{quote_table_name(table_name)} RENAME TO #{quote_table_name(new_name)}"
333
+ puts "Warning: renaming index not work as manual. Ignoring: #{_query}"
334
+ # execute _query
330
335
  else
331
336
  super
332
337
  end
@@ -351,11 +356,13 @@ module ActiveRecord
351
356
  end
352
357
 
353
358
  def change_column(table_name, column_name, type, options = {}) # :nodoc:
354
- execute("ALTER TABLE #{quote_table_name(table_name)} #{change_column_for_alter(table_name, column_name, type, **options)}")
359
+ execute("ALTER TABLE #{quote_table_name(table_name)} #{change_column_for_alter(table_name, column_name, type,
360
+ **options)}")
355
361
  end
356
362
 
357
363
  def rename_column(table_name, column_name, new_column_name) # :nodoc:
358
- execute("ALTER TABLE #{quote_table_name(table_name)} #{rename_column_for_alter(table_name, column_name, new_column_name)}")
364
+ execute("ALTER TABLE #{quote_table_name(table_name)} #{rename_column_for_alter(table_name, column_name,
365
+ new_column_name)}")
359
366
  rename_column_indexes(table_name, column_name, new_column_name)
360
367
  end
361
368
 
@@ -520,9 +527,9 @@ module ActiveRecord
520
527
  end
521
528
 
522
529
  def check_version # :nodoc:
523
- if database_version < '9.0'
524
- raise "Your version of Cubrid (#{database_version}) is too old. Active Record supports Cubrid >= 9.0."
525
- end
530
+ return unless database_version < '9.0'
531
+
532
+ raise "Your version of Cubrid (#{database_version}) is too old. Active Record supports Cubrid >= 9.0."
526
533
  end
527
534
 
528
535
  private
@@ -650,14 +657,15 @@ module ActiveRecord
650
657
  comment: column.comment
651
658
  }
652
659
 
653
- current_type = exec_query("SHOW COLUMNS FROM #{quote_table_name(table_name)} LIKE #{quote(column_name)}", "SCHEMA").first["Type"]
660
+ current_type = exec_query("SHOW COLUMNS FROM #{quote_table_name(table_name)} LIKE #{quote(column_name)}",
661
+ 'SCHEMA').first['Type']
654
662
  td = create_table_definition(table_name)
655
663
  cd = td.new_column_definition(new_column_name, current_type, **options)
656
664
  schema_creation.accept(ChangeColumnDefinition.new(cd, column.name))
657
665
  end
658
666
 
659
667
  def add_index_for_alter(table_name, column_name, **options)
660
- index, algorithm, _ = add_index_options(table_name, column_name, **options)
668
+ index, algorithm, = add_index_options(table_name, column_name, **options)
661
669
  algorithm = ", #{algorithm}" if algorithm
662
670
 
663
671
  "ADD #{schema_creation.accept(index)}#{algorithm}"
@@ -43,9 +43,8 @@ module ActiveRecord
43
43
 
44
44
  # make sure we carry over any changes to ActiveRecord::Base.default_timezone that have been
45
45
  # made since we established the connection
46
- @connection.query_options[:database_timezone] = ActiveRecord::Base.default_timezone
46
+ # @connection.query_options[:database_timezone] = ActiveRecord::Base.default_timezone
47
47
  # @connection.query_options[:database_timezone] = ActiveRecord.default_timezone
48
-
49
48
  super
50
49
  end
51
50
 
@@ -87,11 +86,11 @@ module ActiveRecord
87
86
  def _extract_rows_from_stmt__raw(stmt, as_hash: false)
88
87
  rows = []
89
88
  if as_hash
90
- while row = stmt.fetch_hash
89
+ while (row = stmt.fetch_hash)
91
90
  rows << row
92
91
  end
93
92
  else
94
- while row = stmt.fetch
93
+ while (row = stmt.fetch)
95
94
  rows << row
96
95
  end
97
96
  end
@@ -101,13 +100,13 @@ module ActiveRecord
101
100
  def _extract_rows_from_stmt__utf8(stmt, as_hash: false)
102
101
  rows = []
103
102
  if as_hash
104
- while row = stmt.fetch_hash
103
+ while (row = stmt.fetch_hash)
105
104
  rows << row.map do |x|
106
105
  [x[0], _as_utf8(x[1])]
107
106
  end.to_h
108
107
  end
109
108
  else
110
- while row = stmt.fetch
109
+ while (row = stmt.fetch)
111
110
  rows << row.map { |x| _as_utf8(x) }
112
111
  end
113
112
  end
@@ -128,7 +127,8 @@ module ActiveRecord
128
127
  end
129
128
 
130
129
  def execute_batch(statements, name = nil)
131
- combine_multi_statements(statements).each do |statement|
130
+ # ss = combine_multi_statements(statements)
131
+ statements.each do |statement|
132
132
  execute(statement, name)
133
133
  end
134
134
  end
@@ -16,11 +16,9 @@ module ActiveRecord
16
16
  client = Cubrid2::Client.new(config)
17
17
  ConnectionAdapters::Cubrid2Adapter.new(client, logger, nil, config)
18
18
  rescue Cubrid2::Error => e
19
- if e.error_number == ER_DATABASE_CONNECTION_ERROR
20
- raise ActiveRecord::NoDatabaseError
21
- else
22
- raise
23
- end
19
+ raise ActiveRecord::NoDatabaseError if e.error_number == ER_DATABASE_CONNECTION_ERROR
20
+
21
+ raise
24
22
  end
25
23
  end
26
24
 
@@ -72,7 +70,7 @@ module ActiveRecord
72
70
  stmt = result.is_a?(Array) ? result.first : result
73
71
  if block_given?
74
72
  if result && stmt
75
- while row = stmt.fetch_hash
73
+ while (row = stmt.fetch_hash)
76
74
  yield row.symbolize_keys
77
75
  end
78
76
  end
@@ -92,8 +90,7 @@ module ActiveRecord
92
90
  def quote_string(string)
93
91
  # escaping with backslash is only allowed when 'no_backslash_escapes' == 'yes' in cubrid config, default is yes.
94
92
  # See: https://www.cubrid.org/manual/ko/11.2/sql/literal.html#id5
95
- # "'#{string.gsub("'", "''")}'"
96
- string
93
+ "#{string.gsub("'", "''")}"
97
94
  end
98
95
 
99
96
  #--
@@ -120,7 +117,7 @@ module ActiveRecord
120
117
 
121
118
  def discard! # :nodoc:
122
119
  super
123
- #@connection.automatic_close = false
120
+ # @connection.automatic_close = false
124
121
  @connection = nil
125
122
  end
126
123
 
data/lib/cubrid2.rb CHANGED
@@ -4,30 +4,30 @@ require 'bigdecimal'
4
4
  # Load libcubrid.dll before requiring cubrid/cubrid.so
5
5
  # This gives a chance to be flexible about the load path
6
6
  # Or to bomb out with a clear error message instead of a linker crash
7
- if RUBY_PLATFORM =~ /mswin|mingw/
8
- dll_path = if ENV['RUBY_CUBRID_LIBCUBRID_DLL']
9
- # If this environment variable is set, it overrides any other paths
10
- # The user is advised to use backslashes not forward slashes
11
- ENV['RUBY_CUBRID_LIBCUBRID_DLL']
12
- elsif File.exist?(File.expand_path('../vendor/libcubrid.dll', File.dirname(__FILE__)))
13
- # Use vendor/libcubrid.dll if it exists, convert slashes for Win32 LoadLibrary
14
- File.expand_path('../vendor/libcubrid.dll', File.dirname(__FILE__))
15
- # elsif defined?(RubyInstaller)
16
- # RubyInstaller-2.4+ native build doesn't need DLL preloading
17
- # else
18
- # This will use default / system library paths
19
- '../vendor/libcubrid.dll'
20
- end
7
+ # if RUBY_PLATFORM =~ /mswin|mingw/
8
+ # dll_path = if ENV['RUBY_CUBRID_LIBCUBRID_DLL']
9
+ # # If this environment variable is set, it overrides any other paths
10
+ # # The user is advised to use backslashes not forward slashes
11
+ # ENV['RUBY_CUBRID_LIBCUBRID_DLL']
12
+ # elsif File.exist?(File.expand_path('../vendor/libcubrid.dll', File.dirname(__FILE__)))
13
+ # # Use vendor/libcubrid.dll if it exists, convert slashes for Win32 LoadLibrary
14
+ # File.expand_path('../vendor/libcubrid.dll', File.dirname(__FILE__))
15
+ # # elsif defined?(RubyInstaller)
16
+ # # RubyInstaller-2.4+ native build doesn't need DLL preloading
17
+ # # else
18
+ # # This will use default / system library paths
19
+ # '../vendor/libcubrid.dll'
20
+ # end
21
21
 
22
- if dll_path
23
- require 'fiddle'
24
- kernel32 = Fiddle.dlopen 'kernel32'
25
- load_library = Fiddle::Function.new(
26
- kernel32['LoadLibraryW'], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_INT
27
- )
28
- abort "Failed to load libcubrid.dll from #{dll_path}" if load_library.call(dll_path.encode('utf-16le')).zero?
29
- end
30
- end
22
+ # if dll_path
23
+ # require 'fiddle'
24
+ # kernel32 = Fiddle.dlopen 'kernel32'
25
+ # load_library = Fiddle::Function.new(
26
+ # kernel32['LoadLibraryW'], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_INT
27
+ # )
28
+ # abort "Failed to load libcubrid.dll from #{dll_path}" if load_library.call(dll_path.encode('utf-16le')).zero?
29
+ # end
30
+ # end
31
31
 
32
32
  # load c extension
33
33
  gem 'cubrid', '>= 10.0'
data/tests/Gemfile CHANGED
@@ -1,10 +1,11 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # I cloned from original cubrid-ruby git repository to test
4
- # git clone https://github.com/CUBRID/cubrid-ruby.git
5
- gem 'cubrid', path: '/opt/cubrid/cubrid-ruby'
6
-
7
- gem 'activerecord', '~> 6.0'
8
- gem 'activerecord-cubrid2-adapter', path: '../'
3
+ gem 'activerecord', '~> 7.0'
9
4
  gem 'test-unit'
10
5
 
6
+ # gem 'cubrid'
7
+ gem 'cubrid', github: 'CUBRID/cubrid-ruby'
8
+ # gem 'cubrid', path: '/opt/cubrid/cubrid-ruby'
9
+
10
+ gem 'activerecord-cubrid2-adapter'
11
+ # gem 'activerecord-cubrid2-adapter', path: '..'
@@ -0,0 +1,61 @@
1
+ Loaded suite test_activerecord
2
+ Started
3
+ ### setup
4
+ -- activerecord-cubrid2-adapter version: 0.0.1
5
+ -- cubrid server version: 11.2.2.0705
6
+ -- charset: utf8
7
+ -- collation: utf8_bin
8
+ ### test_benchmark_insert
9
+ user system total real
10
+ 1th test
11
+ inserted id: 1
12
+ 2th test
13
+ inserted id: 2
14
+ 3th test
15
+ inserted id: 3
16
+ 4th test
17
+ inserted id: 4
18
+ 5th test
19
+ inserted id: 5
20
+ 6th test
21
+ inserted id: 6
22
+ 7th test
23
+ inserted id: 7
24
+ 8th test
25
+ inserted id: 8
26
+ 9th test
27
+ inserted id: 9
28
+ 10th test
29
+ inserted id: 10
30
+ 0.014243 0.002685 0.016928 ( 0.074481)
31
+ ### 10 rows inserted
32
+ ### teardown
33
+ .### setup
34
+ -- activerecord-cubrid2-adapter version: 0.0.1
35
+ -- cubrid server version: 11.2.2.0705
36
+ -- charset: utf8
37
+ -- collation: utf8_bin
38
+ ### test_insert
39
+ inserted id: 2
40
+ inserted id: 3
41
+ inserted id: 4
42
+ #<CubridTest:0x00007fdced0cdbf0
43
+ id: 3,
44
+ name: "test2",
45
+ body: "한글2",
46
+ created_at: 2023-01-20 11:19:29 UTC,
47
+ updated_at: 2023-01-20 11:19:29 UTC>
48
+ #<CubridTest:0x00007fdcf05901f8
49
+ id: 4,
50
+ name: "test3",
51
+ body: "中文3",
52
+ created_at: 2023-01-20 11:19:29 UTC,
53
+ updated_at: 2023-01-20 11:19:29 UTC>
54
+ ### teardown
55
+ .
56
+ Finished in 0.266551841 seconds.
57
+ -------------------------------------------------------------------------------
58
+ 2 tests, 5 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
59
+ 100% passed
60
+ -------------------------------------------------------------------------------
61
+ 7.50 tests/s, 18.76 assertions/s
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-cubrid2-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eui-Taik Na
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-20 00:00:00.000000000 Z
11
+ date: 2023-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '6.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '6.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,10 +27,16 @@ dependencies:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
29
  version: '6.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '6.0'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: cubrid
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '10.0'
31
40
  - - ">="
32
41
  - !ruby/object:Gem::Version
33
42
  version: '10.0'
@@ -35,6 +44,9 @@ dependencies:
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '10.0'
38
50
  - - ">="
39
51
  - !ruby/object:Gem::Version
40
52
  version: '10.0'
@@ -75,6 +87,7 @@ files:
75
87
  - lib/cubrid2/version.rb
76
88
  - tests/Gemfile
77
89
  - tests/test_activerecord.rb
90
+ - tests/test_activerecord_output_example.txt
78
91
  homepage: https://github.com/damulhan/activerecord-cubrid2-adapter
79
92
  licenses:
80
93
  - MIT
@@ -95,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
108
  - !ruby/object:Gem::Version
96
109
  version: '0'
97
110
  requirements: []
98
- rubygems_version: 3.3.7
111
+ rubygems_version: 3.1.4
99
112
  signing_key:
100
113
  specification_version: 4
101
114
  summary: ActiveRecord Cubrid Adapter.