mysql2-lambda-test 0.5.3.test1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 65faa98d30b889cfcc13f71523ea42949d10c9db0112835314e4b81095110671
4
+ data.tar.gz: e519de9fe265ff34b0d4b99d15c3eaf445fde6c360ec6ef03d87b135ff438421
5
+ SHA512:
6
+ metadata.gz: bedd07abae139209619948e42e627f1fce81818e2c41d0a2edceae5977b4bb06fe7a7054744e6586d1526068a50b565c8fa8684d244086c325c272b177825a59
7
+ data.tar.gz: c6a94fdfccf9d2472133977b22cfeca63b73fa8a087135a3da3c67ac9101b2cfcc6b7195f9cf4442395a069f876b7925db5351589b4e8acdb8536274d5400fc3
@@ -0,0 +1 @@
1
+ Changes are maintained under [Releases](https://github.com/brianmario/mysql2/releases)
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Brian Lopez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+
2
+ # [TEST] Precompiled Mysql2 gem for AWS Lambda using MariaDB
3
+
4
+ https://github.com/brianmario/mysql2
@@ -0,0 +1,86 @@
1
+ require 'date'
2
+ require 'bigdecimal'
3
+
4
+ # Load libmysql.dll before requiring mysql2/mysql2.so
5
+ # This gives a chance to be flexible about the load path
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_MYSQL2_LIBMYSQL_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_MYSQL2_LIBMYSQL_DLL']
12
+ elsif File.exist?(File.expand_path('../vendor/libmysql.dll', File.dirname(__FILE__)))
13
+ # Use vendor/libmysql.dll if it exists, convert slashes for Win32 LoadLibrary
14
+ File.expand_path('../vendor/libmysql.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
+ 'libmysql.dll'
20
+ end
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
+ if load_library.call(dll_path.encode('utf-16le')).zero?
29
+ abort "Failed to load libmysql.dll from #{dll_path}"
30
+ end
31
+ end
32
+ end
33
+
34
+ require 'mysql2/version' unless defined? Mysql2::VERSION
35
+ require 'mysql2/error'
36
+ require 'mysql2/mysql2'
37
+ require 'mysql2/result'
38
+ require 'mysql2/client'
39
+ require 'mysql2/field'
40
+ require 'mysql2/statement'
41
+
42
+ # = Mysql2
43
+ #
44
+ # A modern, simple and very fast Mysql library for Ruby - binding to libmysql
45
+ module Mysql2
46
+ end
47
+
48
+ if defined?(ActiveRecord::VERSION::STRING) && ActiveRecord::VERSION::STRING < "3.1"
49
+ begin
50
+ require 'active_record/connection_adapters/mysql2_adapter'
51
+ rescue LoadError
52
+ warn "============= WARNING FROM mysql2 ============="
53
+ warn "This version of mysql2 (#{Mysql2::VERSION}) doesn't ship with the ActiveRecord adapter."
54
+ warn "In Rails version 3.1.0 and up, the mysql2 ActiveRecord adapter is included with rails."
55
+ warn "If you want to use the mysql2 gem with Rails <= 3.0.x, please use the latest mysql2 in the 0.2.x series."
56
+ warn "============= END WARNING FROM mysql2 ============="
57
+ end
58
+ end
59
+
60
+ # For holding utility methods
61
+ module Mysql2
62
+ module Util
63
+ #
64
+ # Rekey a string-keyed hash with equivalent symbols.
65
+ #
66
+ def self.key_hash_as_symbols(hash)
67
+ return nil unless hash
68
+ Hash[hash.map { |k, v| [k.to_sym, v] }]
69
+ end
70
+
71
+ #
72
+ # In Mysql2::Client#query and Mysql2::Statement#execute,
73
+ # Thread#handle_interrupt is used to prevent Timeout#timeout
74
+ # from interrupting query execution.
75
+ #
76
+ # Timeout::ExitException was removed in Ruby 2.3.0, 2.2.3, and 2.1.8,
77
+ # but is present in earlier 2.1.x and 2.2.x, so we provide a shim.
78
+ #
79
+ require 'timeout'
80
+ TIMEOUT_ERROR_CLASS = if defined?(::Timeout::ExitException)
81
+ ::Timeout::ExitException
82
+ else
83
+ ::Timeout::Error
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,155 @@
1
+ module Mysql2
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
+ connect_flags: REMEMBER_OPTIONS | LONG_PASSWORD | LONG_FLAG | TRANSACTIONS | PROTOCOL_41 | SECURE_CONNECTION | CONNECT_ATTRS,
15
+ cast: true,
16
+ default_file: nil,
17
+ default_group: nil,
18
+ }
19
+ end
20
+
21
+ def initialize(opts = {})
22
+ raise Mysql2::Error, "Options parameter must be a Hash" unless opts.is_a? Hash
23
+ opts = Mysql2::Util.key_hash_as_symbols(opts)
24
+ @read_timeout = nil
25
+ @query_options = self.class.default_query_options.dup
26
+ @query_options.merge! opts
27
+
28
+ initialize_ext
29
+
30
+ # Set default connect_timeout to avoid unlimited retries from signal interruption
31
+ opts[:connect_timeout] = 120 unless opts.key?(:connect_timeout)
32
+
33
+ # TODO: stricter validation rather than silent massaging
34
+ %i[reconnect connect_timeout local_infile read_timeout write_timeout default_file default_group secure_auth init_command automatic_close enable_cleartext_plugin default_auth].each do |key|
35
+ next unless opts.key?(key)
36
+ case key
37
+ when :reconnect, :local_infile, :secure_auth, :automatic_close, :enable_cleartext_plugin
38
+ send(:"#{key}=", !!opts[key]) # rubocop:disable Style/DoubleNegation
39
+ when :connect_timeout, :read_timeout, :write_timeout
40
+ send(:"#{key}=", Integer(opts[key])) unless opts[key].nil?
41
+ else
42
+ send(:"#{key}=", opts[key])
43
+ end
44
+ end
45
+
46
+ # force the encoding to utf8
47
+ self.charset_name = opts[:encoding] || 'utf8'
48
+
49
+ ssl_options = opts.values_at(:sslkey, :sslcert, :sslca, :sslcapath, :sslcipher)
50
+ ssl_set(*ssl_options) if ssl_options.any? || opts.key?(:sslverify)
51
+ self.ssl_mode = parse_ssl_mode(opts[:ssl_mode]) if opts[:ssl_mode]
52
+
53
+ flags = case opts[:flags]
54
+ when Array
55
+ parse_flags_array(opts[:flags], @query_options[:connect_flags])
56
+ when String
57
+ parse_flags_array(opts[:flags].split(' '), @query_options[:connect_flags])
58
+ when Integer
59
+ @query_options[:connect_flags] | opts[:flags]
60
+ else
61
+ @query_options[:connect_flags]
62
+ end
63
+
64
+ # SSL verify is a connection flag rather than a mysql_ssl_set option
65
+ flags |= SSL_VERIFY_SERVER_CERT if opts[:sslverify]
66
+
67
+ if %i[user pass hostname dbname db sock].any? { |k| @query_options.key?(k) }
68
+ warn "============= WARNING FROM mysql2 ============="
69
+ warn "The options :user, :pass, :hostname, :dbname, :db, and :sock are deprecated and will be removed at some point in the future."
70
+ warn "Instead, please use :username, :password, :host, :port, :database, :socket, :flags for the options."
71
+ warn "============= END WARNING FROM mysql2 ========="
72
+ end
73
+
74
+ user = opts[:username] || opts[:user]
75
+ pass = opts[:password] || opts[:pass]
76
+ host = opts[:host] || opts[:hostname]
77
+ port = opts[:port]
78
+ database = opts[:database] || opts[:dbname] || opts[:db]
79
+ socket = opts[:socket] || opts[:sock]
80
+
81
+ # Correct the data types before passing these values down to the C level
82
+ user = user.to_s unless user.nil?
83
+ pass = pass.to_s unless pass.nil?
84
+ host = host.to_s unless host.nil?
85
+ port = port.to_i unless port.nil?
86
+ database = database.to_s unless database.nil?
87
+ socket = socket.to_s unless socket.nil?
88
+ conn_attrs = parse_connect_attrs(opts[:connect_attrs])
89
+
90
+ connect user, pass, host, port, database, socket, flags, conn_attrs
91
+ end
92
+
93
+ def parse_ssl_mode(mode)
94
+ m = mode.to_s.upcase
95
+ if m.start_with?('SSL_MODE_')
96
+ return Mysql2::Client.const_get(m) if Mysql2::Client.const_defined?(m)
97
+ else
98
+ x = 'SSL_MODE_' + m
99
+ return Mysql2::Client.const_get(x) if Mysql2::Client.const_defined?(x)
100
+ end
101
+ warn "Unknown MySQL ssl_mode flag: #{mode}"
102
+ end
103
+
104
+ def parse_flags_array(flags, initial = 0)
105
+ flags.reduce(initial) do |memo, f|
106
+ fneg = f.start_with?('-') ? f[1..-1] : nil
107
+ if fneg && fneg =~ /^\w+$/ && Mysql2::Client.const_defined?(fneg)
108
+ memo & ~ Mysql2::Client.const_get(fneg)
109
+ elsif f && f =~ /^\w+$/ && Mysql2::Client.const_defined?(f)
110
+ memo | Mysql2::Client.const_get(f)
111
+ else
112
+ warn "Unknown MySQL connection flag: '#{f}'"
113
+ memo
114
+ end
115
+ end
116
+ end
117
+
118
+ # Set default program_name in performance_schema.session_connect_attrs
119
+ # and performance_schema.session_account_connect_attrs
120
+ def parse_connect_attrs(conn_attrs)
121
+ return {} if Mysql2::Client::CONNECT_ATTRS.zero?
122
+ conn_attrs ||= {}
123
+ conn_attrs[:program_name] ||= $PROGRAM_NAME
124
+ conn_attrs.each_with_object({}) do |(key, value), hash|
125
+ hash[key.to_s] = value.to_s
126
+ end
127
+ end
128
+
129
+ def query(sql, options = {})
130
+ Thread.handle_interrupt(::Mysql2::Util::TIMEOUT_ERROR_CLASS => :never) do
131
+ _query(sql, @query_options.merge(options))
132
+ end
133
+ end
134
+
135
+ def query_info
136
+ info = query_info_string
137
+ return {} unless info
138
+ info_hash = {}
139
+ info.split.each_slice(2) { |s| info_hash[s[0].downcase.delete(':').to_sym] = s[1].to_i }
140
+ info_hash
141
+ end
142
+
143
+ def info
144
+ self.class.info
145
+ end
146
+
147
+ class << self
148
+ private
149
+
150
+ def local_offset
151
+ ::Time.local(2010).utc_offset.to_r / 86400
152
+ end
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,5 @@
1
+ # Loaded by script/console. Land helpers here.
2
+
3
+ Pry.config.prompt = lambda do |context, *|
4
+ "[mysql2] #{context}> "
5
+ end
@@ -0,0 +1,53 @@
1
+ require 'eventmachine'
2
+ require 'mysql2'
3
+
4
+ module Mysql2
5
+ module EM
6
+ class Client < ::Mysql2::Client
7
+ module Watcher
8
+ def initialize(client, deferable)
9
+ @client = client
10
+ @deferable = deferable
11
+ @is_watching = true
12
+ end
13
+
14
+ def notify_readable
15
+ detach
16
+ begin
17
+ result = @client.async_result
18
+ rescue StandardError => e
19
+ @deferable.fail(e)
20
+ else
21
+ @deferable.succeed(result)
22
+ end
23
+ end
24
+
25
+ def watching?
26
+ @is_watching
27
+ end
28
+
29
+ def unbind
30
+ @is_watching = false
31
+ end
32
+ end
33
+
34
+ def close(*args)
35
+ @watch.detach if @watch && @watch.watching?
36
+
37
+ super(*args)
38
+ end
39
+
40
+ def query(sql, opts = {})
41
+ if ::EM.reactor_running?
42
+ super(sql, opts.merge(async: true))
43
+ deferable = ::EM::DefaultDeferrable.new
44
+ @watch = ::EM.watch(socket, Watcher, self, deferable)
45
+ @watch.notify_readable = true
46
+ deferable
47
+ else
48
+ super(sql, opts)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,100 @@
1
+ module Mysql2
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
+ TimeoutError = Class.new(Error)
11
+
12
+ CODES = {
13
+ 1205 => TimeoutError, # ER_LOCK_WAIT_TIMEOUT
14
+
15
+ 1044 => ConnectionError, # ER_DBACCESS_DENIED_ERROR
16
+ 1045 => ConnectionError, # ER_ACCESS_DENIED_ERROR
17
+ 1152 => ConnectionError, # ER_ABORTING_CONNECTION
18
+ 1153 => ConnectionError, # ER_NET_PACKET_TOO_LARGE
19
+ 1154 => ConnectionError, # ER_NET_READ_ERROR_FROM_PIPE
20
+ 1155 => ConnectionError, # ER_NET_FCNTL_ERROR
21
+ 1156 => ConnectionError, # ER_NET_PACKETS_OUT_OF_ORDER
22
+ 1157 => ConnectionError, # ER_NET_UNCOMPRESS_ERROR
23
+ 1158 => ConnectionError, # ER_NET_READ_ERROR
24
+ 1159 => ConnectionError, # ER_NET_READ_INTERRUPTED
25
+ 1160 => ConnectionError, # ER_NET_ERROR_ON_WRITE
26
+ 1161 => ConnectionError, # ER_NET_WRITE_INTERRUPTED
27
+
28
+ 2001 => ConnectionError, # CR_SOCKET_CREATE_ERROR
29
+ 2002 => ConnectionError, # CR_CONNECTION_ERROR
30
+ 2003 => ConnectionError, # CR_CONN_HOST_ERROR
31
+ 2004 => ConnectionError, # CR_IPSOCK_ERROR
32
+ 2005 => ConnectionError, # CR_UNKNOWN_HOST
33
+ 2006 => ConnectionError, # CR_SERVER_GONE_ERROR
34
+ 2007 => ConnectionError, # CR_VERSION_ERROR
35
+ 2009 => ConnectionError, # CR_WRONG_HOST_INFO
36
+ 2012 => ConnectionError, # CR_SERVER_HANDSHAKE_ERR
37
+ 2013 => ConnectionError, # CR_SERVER_LOST
38
+ 2020 => ConnectionError, # CR_NET_PACKET_TOO_LARGE
39
+ 2026 => ConnectionError, # CR_SSL_CONNECTION_ERROR
40
+ 2027 => ConnectionError, # CR_MALFORMED_PACKET
41
+ 2047 => ConnectionError, # CR_CONN_UNKNOW_PROTOCOL
42
+ 2048 => ConnectionError, # CR_INVALID_CONN_HANDLE
43
+ 2049 => ConnectionError, # CR_UNUSED_1
44
+ }.freeze
45
+
46
+ attr_reader :error_number, :sql_state
47
+
48
+ # Mysql gem compatibility
49
+ alias errno error_number
50
+ alias error message
51
+
52
+ def initialize(msg, server_version = nil, error_number = nil, sql_state = nil)
53
+ @server_version = server_version
54
+ @error_number = error_number
55
+ @sql_state = sql_state ? sql_state.encode(**ENCODE_OPTS) : nil
56
+
57
+ super(clean_message(msg))
58
+ end
59
+
60
+ def self.new_with_args(msg, server_version, error_number, sql_state)
61
+ error_class = CODES.fetch(error_number, self)
62
+ error_class.new(msg, server_version, error_number, sql_state)
63
+ end
64
+
65
+ private
66
+
67
+ # In MySQL 5.5+ error messages are always constructed server-side as UTF-8
68
+ # then returned in the encoding set by the `character_set_results` system
69
+ # variable.
70
+ #
71
+ # See http://dev.mysql.com/doc/refman/5.5/en/charset-errors.html for
72
+ # more context.
73
+ #
74
+ # Before MySQL 5.5 error message template strings are in whatever encoding
75
+ # is associated with the error message language.
76
+ # See http://dev.mysql.com/doc/refman/5.1/en/error-message-language.html
77
+ # for more information.
78
+ #
79
+ # The issue is that the user-data inserted in the message could potentially
80
+ # be in any encoding MySQL supports and is insert into the latin1, euckr or
81
+ # koi8r string raw. Meaning there's a high probability the string will be
82
+ # corrupt encoding-wise.
83
+ #
84
+ # See http://dev.mysql.com/doc/refman/5.1/en/charset-errors.html for
85
+ # more information.
86
+ #
87
+ # So in an attempt to make sure the error message string is always in a valid
88
+ # encoding, we'll assume UTF-8 and clean the string of anything that's not a
89
+ # valid UTF-8 character.
90
+ #
91
+ # Returns a valid UTF-8 string.
92
+ def clean_message(message)
93
+ if @server_version && @server_version > 50500
94
+ message.encode(**ENCODE_OPTS)
95
+ else
96
+ message.encode(Encoding::UTF_8, **ENCODE_OPTS)
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,3 @@
1
+ module Mysql2
2
+ Field = Struct.new(:name, :type)
3
+ end
@@ -0,0 +1 @@
1
+ lib/mysql2/libmariadb.so.3
Binary file
@@ -0,0 +1,7 @@
1
+ module Mysql2
2
+ class Result
3
+ attr_reader :server_flags
4
+
5
+ include Enumerable
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module Mysql2
2
+ class Statement
3
+ include Enumerable
4
+
5
+ def execute(*args, **kwargs)
6
+ Thread.handle_interrupt(::Mysql2::Util::TIMEOUT_ERROR_CLASS => :never) do
7
+ _execute(*args, **kwargs)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Mysql2
2
+ VERSION = "0.5.3".freeze
3
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mysql2-lambda-test
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.3.test1
5
+ platform: ruby
6
+ authors:
7
+ - Ken Collins
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-07-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - kcollins@customink.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - CHANGELOG.md
21
+ - LICENSE
22
+ - README.md
23
+ - lib/mysql2.rb
24
+ - lib/mysql2/client.rb
25
+ - lib/mysql2/console.rb
26
+ - lib/mysql2/em.rb
27
+ - lib/mysql2/error.rb
28
+ - lib/mysql2/field.rb
29
+ - lib/mysql2/libmariadb.so
30
+ - lib/mysql2/libmariadb.so.3
31
+ - lib/mysql2/mysql2.so
32
+ - lib/mysql2/result.rb
33
+ - lib/mysql2/statement.rb
34
+ - lib/mysql2/version.rb
35
+ homepage: https://github.com/customink/mysql2-lambda-test
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ bug_tracker_uri: https://github.com/customink/mysql2-lambda-test/issues
40
+ changelog_uri: https://github.com/customink/mysql2-lambda-test/releases/tag/0.5.3.test1
41
+ homepage_uri: https://github.com/customink/mysql2-lambda-test
42
+ source_code_uri: https://github.com/customink/mysql2-lambda-test/tree/0.5.3.test1
43
+ post_install_message:
44
+ rdoc_options:
45
+ - "--charset=UTF-8"
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.5.5
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">"
56
+ - !ruby/object:Gem::Version
57
+ version: 1.3.1
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.7.6.2
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Precompiled Mysql2 gem for AWS Lambda using MariaDB.
64
+ test_files: []