ruby-dm 0.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.
data/ext/statement.h ADDED
@@ -0,0 +1,36 @@
1
+ #ifndef dm_STATEMENT_H
2
+ #define dm_STATEMENT_H
3
+
4
+ typedef struct {
5
+ void* buffer;
6
+ ulength buffer_length;
7
+ }dm_BIND;
8
+
9
+
10
+ typedef struct {
11
+ sdint2 sql_type;
12
+ ulength prec;
13
+ sdint2 scale;
14
+ sdint2 nullable;
15
+ }ParamDesc;
16
+
17
+ typedef struct {
18
+ VALUE client;
19
+ dhstmt stmt;
20
+ int refcount;
21
+ int closed;
22
+ int is_select;
23
+ sdbyte lastrowid[20];
24
+ sdint8 affected_rows;
25
+ udint2 param_num;
26
+ udint2 col_num;
27
+ ParamDesc *paramdesc;
28
+ int is_prepare;
29
+ } dm_stmt_wrapper;
30
+
31
+ void init_dm_statement(void);
32
+ void decr_dm_stmt(dm_stmt_wrapper *stmt_wrapper);
33
+
34
+ VALUE rb_dm_stmt_new(VALUE rb_client, VALUE sql);
35
+
36
+ #endif
data/lib/dm/client.rb ADDED
@@ -0,0 +1,54 @@
1
+ module Dm
2
+ class Client
3
+ attr_reader :query_options, :read_timeout
4
+
5
+ def self.default_query_options
6
+ @default_query_options ||= {
7
+ as: :hash, # the type of object you want each row back as; also supports :array (an array of values)
8
+ async: false, # don't wait for a result after sending the query, you'll have to monitor the socket yourself then eventually call Mysql2::Client#async_result
9
+ cast_booleans: false, # cast tinyint(1) fields as true/false in ruby
10
+ symbolize_keys: false, # return field names as symbols instead of strings
11
+ database_timezone: :local, # timezone Mysql2 will assume datetime objects are stored in
12
+ application_timezone: nil, # timezone Mysql2 will convert to before handing the object back to the caller
13
+ cache_rows: true, # tells Mysql2 to use its internal row cache for results
14
+ cast: true,
15
+ }
16
+ end
17
+
18
+ def initialize(opts = {})
19
+ raise Dm::Error, "Options parameter must be a Hash" unless opts.is_a? Hash
20
+
21
+ opts = Dm::Util.key_hash_as_symbols(opts)
22
+ @query_options = self.class.default_query_options.dup
23
+ @query_options.merge! opts
24
+
25
+ # force the encoding to utf8
26
+
27
+ user = opts[:username] || opts[:user]
28
+ pass = opts[:password] || opts[:pass]
29
+ server = opts[:server] || opts[:host]
30
+
31
+ # Correct the data types before passing these values down to the C level
32
+ user = user.to_s unless user.nil?
33
+ pass = pass.to_s unless pass.nil?
34
+ server = server.to_s unless server.nil?
35
+ self.charset_name = opts[:encoding] || 1
36
+ connect user, pass, server
37
+ end
38
+
39
+ def query(sql, options = {})
40
+ Thread.handle_interrupt(::Dm::Util::TIMEOUT_ERROR_NEVER) do
41
+ _query(sql, @query_options.merge(options))
42
+ end
43
+ end
44
+
45
+
46
+ class << self
47
+ private
48
+
49
+ def local_offset
50
+ ::Time.local(2010).utc_offset.to_r / 86400
51
+ end
52
+ end
53
+ end
54
+ end
data/lib/dm/console.rb ADDED
@@ -0,0 +1,5 @@
1
+ # Loaded by script/console. Land helpers here.
2
+
3
+ Pry.config.prompt = lambda do |context, *|
4
+ "[ruby-dm] #{context}> "
5
+ end
data/lib/dm/error.rb ADDED
@@ -0,0 +1,59 @@
1
+ module Dm
2
+ class Error < StandardError
3
+ ENCODE_OPTS = {
4
+ undef: :replace,
5
+ invalid: :replace,
6
+ replace: '?'.freeze,
7
+ }.freeze
8
+
9
+ ConnectionError = Class.new(Error)
10
+
11
+ attr_reader :error_number
12
+
13
+ # Mysql gem compatibility
14
+ alias errno error_number
15
+ alias error message
16
+
17
+ def initialize(msg, error_number = nil)
18
+ @error_number = error_number
19
+
20
+ super(clean_message(msg))
21
+ end
22
+
23
+ def self.new_with_args(msg, error_number)
24
+ error_class = ConnectionError
25
+ error_class.new(msg, error_number)
26
+ end
27
+
28
+ private
29
+
30
+ # In MySQL 5.5+ error messages are always constructed server-side as UTF-8
31
+ # then returned in the encoding set by the `character_set_results` system
32
+ # variable.
33
+ #
34
+ # See http://dev.mysql.com/doc/refman/5.5/en/charset-errors.html for
35
+ # more context.
36
+ #
37
+ # Before MySQL 5.5 error message template strings are in whatever encoding
38
+ # is associated with the error message language.
39
+ # See http://dev.mysql.com/doc/refman/5.1/en/error-message-language.html
40
+ # for more information.
41
+ #
42
+ # The issue is that the user-data inserted in the message could potentially
43
+ # be in any encoding MySQL supports and is insert into the latin1, euckr or
44
+ # koi8r string raw. Meaning there's a high probability the string will be
45
+ # corrupt encoding-wise.
46
+ #
47
+ # See http://dev.mysql.com/doc/refman/5.1/en/charset-errors.html for
48
+ # more information.
49
+ #
50
+ # So in an attempt to make sure the error message string is always in a valid
51
+ # encoding, we'll assume UTF-8 and clean the string of anything that's not a
52
+ # valid UTF-8 character.
53
+ #
54
+ # Returns a valid UTF-8 string.
55
+ def clean_message(message)
56
+ message.encode(Encoding::UTF_8, **ENCODE_OPTS)
57
+ end
58
+ end
59
+ end
data/lib/dm/field.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Dm
2
+ Field = Struct.new(:name, :type)
3
+ end
data/lib/dm/result.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Dm
2
+ class Result
3
+ attr_reader :server_flags
4
+
5
+ include Enumerable
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module Dm
2
+ class Statement
3
+ def execute(*args, **kwargs)
4
+ Thread.handle_interrupt(::Dm::Util::TIMEOUT_ERROR_NEVER) do
5
+ _execute(*args, **kwargs)
6
+ end
7
+ end
8
+ end
9
+ end
data/lib/dm/version.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dm
4
+ VERSION = "0.1.0"
5
+ end
data/lib/dm.rb ADDED
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+ require 'date'
3
+ require 'bigdecimal'
4
+ require_relative "dm/version"
5
+
6
+
7
+
8
+ module Dm
9
+
10
+ begin
11
+ require "dm/dm/dm_lib_path"
12
+ rescue LoadError
13
+ # rake-compiler doesn't use regular "make install", but uses it's own install tasks.
14
+ DM_LIB_PATH = false
15
+ end
16
+
17
+ add_dll_path = proc do |path, &block|
18
+ if RUBY_PLATFORM =~/(mswin|mingw)/i && path && File.exist?(path)
19
+ begin
20
+ require 'ruby_installer/runtime'
21
+ RubyInstaller::Runtime.add_dll_directory(path, &block)
22
+ rescue LoadError
23
+ old_path = ENV['PATH']
24
+ ENV['PATH'] = "#{path};#{old_path}"
25
+ block.call
26
+ ENV['PATH'] = old_path
27
+ end
28
+ else
29
+ # No need to set a load path manually - it's set as library rpath.
30
+ block.call
31
+ end
32
+ end
33
+
34
+ # Add a load path to the one retrieved from pg_config
35
+ add_dll_path.call(DM_LIB_PATH) do
36
+ require 'dm/error'
37
+ require 'dm/dm_ext'
38
+ require 'dm/result'
39
+ require 'dm/client'
40
+ require 'dm/field'
41
+ require 'dm/statement'
42
+ end
43
+
44
+ end
45
+
46
+ # For holding utility methods
47
+ module Dm
48
+ module Util
49
+ #
50
+ # Rekey a string-keyed hash with equivalent symbols.
51
+ #
52
+ def self.key_hash_as_symbols(hash)
53
+ return nil unless hash
54
+
55
+ Hash[hash.map { |k, v| [k.to_sym, v] }]
56
+ end
57
+ require 'timeout'
58
+ TIMEOUT_ERROR_CLASS = if defined?(::Timeout::ExitException)
59
+ ::Timeout::ExitException
60
+ else
61
+ ::Timeout::Error
62
+ end
63
+ TIMEOUT_ERROR_NEVER = { TIMEOUT_ERROR_CLASS => :never }.freeze
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-dm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - sunbiao
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-12-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bigdecimal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - sunbiao@dameng.com
30
+ executables: []
31
+ extensions:
32
+ - ext/extconf.rb
33
+ extra_rdoc_files: []
34
+ files:
35
+ - "./CHANGELOG.md"
36
+ - "./CODE_OF_CONDUCT.md"
37
+ - "./Gemfile"
38
+ - "./LICENSE.txt"
39
+ - "./README.md"
40
+ - "./Rakefile"
41
+ - "./SYSDBA)"
42
+ - "./dm-0.1.0.gem"
43
+ - "./dm.gemspec"
44
+ - ext/client.c
45
+ - ext/client.h
46
+ - ext/dm_enc_name_to_ruby.h
47
+ - ext/dm_ext.c
48
+ - ext/dm_ext.h
49
+ - ext/dm_lib_path.rb
50
+ - ext/extconf.h
51
+ - ext/extconf.rb
52
+ - ext/result.c
53
+ - ext/result.h
54
+ - ext/statement.c
55
+ - ext/statement.h
56
+ - lib/dm.rb
57
+ - lib/dm/client.rb
58
+ - lib/dm/console.rb
59
+ - lib/dm/error.rb
60
+ - lib/dm/field.rb
61
+ - lib/dm/result.rb
62
+ - lib/dm/statement.rb
63
+ - lib/dm/version.rb
64
+ homepage: https://www.dameng.com/
65
+ licenses:
66
+ - MIT
67
+ metadata:
68
+ bug_tracker_uri: https://www.dameng.com/
69
+ changelog_uri: https://www.dameng.com/
70
+ documentation_uri: https://www.dameng.com/
71
+ homepage_uri: https://www.dameng.com/
72
+ source_code_uri: https://www.dameng.com/
73
+ msys2_mingw_dependencies: libmariadbclient
74
+ post_install_message:
75
+ rdoc_options:
76
+ - "--charset=UTF-8"
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 2.0.0
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.5.14
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: A simple, fast DM library for Ruby, binding to dmdpi
94
+ test_files: []