db-mariadb 0.2.1 → 0.2.2
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.
- checksums.yaml +4 -4
- data/lib/db/mariadb/connection.rb +16 -12
- data/lib/db/mariadb/error.rb +28 -0
- data/lib/db/mariadb/native/connection.rb +39 -18
- data/lib/db/mariadb/native/field.rb +3 -2
- data/lib/db/mariadb/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f27b7da8ad5cdec94cfd6b7ae6f078b30886231c62f49489892e2d41c1c9d96
|
4
|
+
data.tar.gz: a194fe786b2ce7fe4a22c276e5b38a47d52a965321747604e7a502f62bcaa5f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ec2fb9d0d2c6d2fa0c5720297ea55a18a68da966bf7f0216bdf103260764b54ab8f88b5f3b301820c833348969eb14a37a93873fe3ba68c5106579006c79919
|
7
|
+
data.tar.gz: ac9e5b54a6013203dba3fef1fa70ff2f0969753ff73c397948ccad2f41c4cad114a278068b5e0a8fc5eda7a2e75713d30a83cc7ee602dde78e4faf2efb6c0eb8
|
@@ -74,29 +74,33 @@ module DB
|
|
74
74
|
return buffer
|
75
75
|
end
|
76
76
|
|
77
|
+
def id_column(name = 'id', primary_key: true)
|
78
|
+
buffer = String.new
|
79
|
+
|
80
|
+
append_identifier(name, buffer)
|
81
|
+
|
82
|
+
buffer << " BIGINT AUTO_INCREMENT"
|
83
|
+
|
84
|
+
if primary_key
|
85
|
+
buffer << " PRIMARY KEY"
|
86
|
+
end
|
87
|
+
|
88
|
+
return buffer
|
89
|
+
end
|
90
|
+
|
77
91
|
def status
|
78
92
|
@native.status
|
79
93
|
end
|
80
94
|
|
81
95
|
def send_query(statement)
|
96
|
+
@native.discard_results
|
97
|
+
|
82
98
|
@native.send_query(statement)
|
83
99
|
end
|
84
100
|
|
85
101
|
def next_result
|
86
102
|
@native.next_result
|
87
103
|
end
|
88
|
-
|
89
|
-
def call(statement, streaming: false)
|
90
|
-
@native.send_query(statement)
|
91
|
-
|
92
|
-
last_result = nil
|
93
|
-
|
94
|
-
while result = @native.next_result
|
95
|
-
last_result = result
|
96
|
-
end
|
97
|
-
|
98
|
-
return last_result
|
99
|
-
end
|
100
104
|
end
|
101
105
|
end
|
102
106
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
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
|
13
|
+
# all 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
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
module DB
|
24
|
+
module MariaDB
|
25
|
+
class Error < StandardError
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -48,6 +48,7 @@ module DB
|
|
48
48
|
|
49
49
|
attach_function :mysql_use_result, [:pointer], :pointer
|
50
50
|
attach_function :mysql_next_result, [:pointer], :int
|
51
|
+
attach_function :mysql_more_results, [:pointer], :int
|
51
52
|
attach_function :mysql_free_result, [:pointer], :void
|
52
53
|
|
53
54
|
attach_function :mysql_affected_rows, [:pointer], :uint64
|
@@ -94,7 +95,7 @@ module DB
|
|
94
95
|
end
|
95
96
|
|
96
97
|
if result.read_pointer.null?
|
97
|
-
raise "Could not connect: #{Native.mysql_error(pointer)}!"
|
98
|
+
raise Error, "Could not connect: #{Native.mysql_error(pointer)}!"
|
98
99
|
end
|
99
100
|
|
100
101
|
return self.new(pointer, io, types, **options)
|
@@ -119,7 +120,7 @@ module DB
|
|
119
120
|
|
120
121
|
def check_error!(message)
|
121
122
|
if Native.mysql_errno(self) != 0
|
122
|
-
raise "#{message}: #{Native.mysql_error(self)}!"
|
123
|
+
raise Error, "#{message}: #{Native.mysql_error(self)}!"
|
123
124
|
end
|
124
125
|
end
|
125
126
|
|
@@ -168,42 +169,62 @@ module DB
|
|
168
169
|
end
|
169
170
|
|
170
171
|
if error.read_int != 0
|
171
|
-
raise "Could not send query: #{Native.mysql_error(self)}!"
|
172
|
+
raise Error, "Could not send query: #{Native.mysql_error(self)}!"
|
172
173
|
end
|
173
174
|
end
|
174
175
|
|
176
|
+
# @returns [Boolean] If there are more results.
|
177
|
+
def more_results?
|
178
|
+
Native.mysql_more_results(self) == 1
|
179
|
+
end
|
180
|
+
|
175
181
|
def next_result(types: @types)
|
182
|
+
if result = self.get_result
|
183
|
+
return Result.new(self, types, result)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
# Silently discard any results that application didn't read.
|
188
|
+
def discard_results
|
189
|
+
while result = self.get_result
|
190
|
+
end
|
191
|
+
|
192
|
+
return nil
|
193
|
+
end
|
194
|
+
|
195
|
+
def affected_rows
|
196
|
+
Native.mysql_affected_rows(self)
|
197
|
+
end
|
198
|
+
|
199
|
+
def insert_id
|
200
|
+
Native.mysql_insert_id(self)
|
201
|
+
end
|
202
|
+
|
203
|
+
def info
|
204
|
+
Native.mysql_info(self)
|
205
|
+
end
|
206
|
+
|
207
|
+
protected
|
208
|
+
def get_result
|
176
209
|
if @result
|
177
210
|
self.free_result
|
178
211
|
|
179
212
|
# Successful and there are no more results:
|
180
213
|
return if Native.mysql_next_result(self) == -1
|
181
214
|
|
182
|
-
check_error!("
|
215
|
+
check_error!("Get result")
|
183
216
|
end
|
184
217
|
|
185
218
|
@result = Native.mysql_use_result(self)
|
186
219
|
|
187
220
|
if @result.null?
|
188
|
-
check_error!("
|
221
|
+
check_error!("Get result")
|
189
222
|
|
190
223
|
return nil
|
191
224
|
else
|
192
|
-
return
|
225
|
+
return @result
|
193
226
|
end
|
194
227
|
end
|
195
|
-
|
196
|
-
def affected_rows
|
197
|
-
Native.mysql_affected_rows(self)
|
198
|
-
end
|
199
|
-
|
200
|
-
def insert_id
|
201
|
-
Native.mysql_insert_id(self)
|
202
|
-
end
|
203
|
-
|
204
|
-
def info
|
205
|
-
Native.mysql_info(self)
|
206
|
-
end
|
207
228
|
end
|
208
229
|
end
|
209
230
|
end
|
@@ -25,7 +25,7 @@ require_relative 'types'
|
|
25
25
|
module DB
|
26
26
|
module MariaDB
|
27
27
|
module Native
|
28
|
-
Type = enum(
|
28
|
+
Type = enum(
|
29
29
|
:decimal,
|
30
30
|
:tiny,
|
31
31
|
:short,
|
@@ -98,7 +98,8 @@ module DB
|
|
98
98
|
:flags, :uint,
|
99
99
|
:decimals, :uint,
|
100
100
|
:charsetnr, :uint,
|
101
|
-
:type, Type
|
101
|
+
:type, Type,
|
102
|
+
:extension, :pointer,
|
102
103
|
)
|
103
104
|
|
104
105
|
def name
|
data/lib/db/mariadb/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: db-mariadb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/db/mariadb.rb
|
118
118
|
- lib/db/mariadb/adapter.rb
|
119
119
|
- lib/db/mariadb/connection.rb
|
120
|
+
- lib/db/mariadb/error.rb
|
120
121
|
- lib/db/mariadb/native.rb
|
121
122
|
- lib/db/mariadb/native/connection.rb
|
122
123
|
- lib/db/mariadb/native/field.rb
|