dmRuby 1.0.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,51 @@
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
+ cast_booleans: false, # cast tinyint(1) fields as true/false in ruby
9
+ symbolize_keys: false, # return field names as symbols instead of strings
10
+ cache_rows: true, # tells to use its internal row cache for results
11
+ cast: true,
12
+ }
13
+ end
14
+
15
+ def initialize(opts = {})
16
+ raise Dm::Error, "Options parameter must be a Hash" unless opts.is_a? Hash
17
+
18
+ opts = Dm::Util.key_hash_as_symbols(opts)
19
+ @query_options = self.class.default_query_options.dup
20
+ @query_options.merge! opts
21
+
22
+ # force the encoding to utf8
23
+
24
+ user = opts[:username] || opts[:user]
25
+ pass = opts[:password] || opts[:pass]
26
+ server = opts[:server] || opts[:host]
27
+
28
+ # Correct the data types before passing these values down to the C level
29
+ user = user.to_s unless user.nil?
30
+ pass = pass.to_s unless pass.nil?
31
+ server = server.to_s unless server.nil?
32
+ self.charset_name = opts[:encoding] || 1
33
+ connect user, pass, server
34
+ end
35
+
36
+ def query(sql, options = {})
37
+ Thread.handle_interrupt(::Dm::Util::TIMEOUT_ERROR_NEVER) do
38
+ _query(sql, @query_options.merge(options))
39
+ end
40
+ end
41
+
42
+
43
+ class << self
44
+ private
45
+
46
+ def local_offset
47
+ ::Time.local(2010).utc_offset.to_r / 86400
48
+ end
49
+ end
50
+ end
51
+ 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 = "1.0.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,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dmRuby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - sunbiao
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-08-06 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
+ - "./CODE_OF_CONDUCT.md"
36
+ - "./ChangeLogs.md"
37
+ - "./Gemfile"
38
+ - "./LICENSE.txt"
39
+ - "./README.md"
40
+ - "./Rakefile"
41
+ - "./dm.gemspec"
42
+ - ext/client.c
43
+ - ext/client.h
44
+ - ext/dm_enc_name_to_ruby.h
45
+ - ext/dm_ext.c
46
+ - ext/dm_ext.h
47
+ - ext/extconf.rb
48
+ - ext/result.c
49
+ - ext/result.h
50
+ - ext/statement.c
51
+ - ext/statement.h
52
+ - lib/dm.rb
53
+ - lib/dm/client.rb
54
+ - lib/dm/console.rb
55
+ - lib/dm/error.rb
56
+ - lib/dm/field.rb
57
+ - lib/dm/result.rb
58
+ - lib/dm/statement.rb
59
+ - lib/dm/version.rb
60
+ homepage: https://www.dameng.com/
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ bug_tracker_uri: https://www.dameng.com/
65
+ changelog_uri: https://www.dameng.com/
66
+ documentation_uri: https://www.dameng.com/
67
+ homepage_uri: https://www.dameng.com/
68
+ source_code_uri: https://www.dameng.com/
69
+ msys2_mingw_dependencies: libmariadbclient
70
+ post_install_message:
71
+ rdoc_options:
72
+ - "--charset=UTF-8"
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 2.0.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.5.14
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: A simple, fast DM library for Ruby, binding to dmdpi
90
+ test_files: []