gbase8sdb 0.2.1__cp27-cp27mu-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
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.
- gbase8sdb/__init__.py +119 -0
- gbase8sdb/column_metadata.py +119 -0
- gbase8sdb/connection.py +157 -0
- gbase8sdb/constructors.py +34 -0
- gbase8sdb/cursor.py +405 -0
- gbase8sdb/defaults.py +46 -0
- gbase8sdb/driver.so +0 -0
- gbase8sdb/dsn.py +39 -0
- gbase8sdb/errors.py +306 -0
- gbase8sdb/exceptions.py +41 -0
- gbase8sdb/lob.py +81 -0
- gbase8sdb/var.py +78 -0
- gbase8sdb/version.py +7 -0
- gbase8sdb-0.2.1.dist-info/LICENSE.txt +21 -0
- gbase8sdb-0.2.1.dist-info/METADATA +96 -0
- gbase8sdb-0.2.1.dist-info/RECORD +19 -0
- gbase8sdb-0.2.1.dist-info/THIRD_PARTY_LICENSES.txt +455 -0
- gbase8sdb-0.2.1.dist-info/WHEEL +6 -0
- gbase8sdb-0.2.1.dist-info/top_level.txt +1 -0
gbase8sdb/errors.py
ADDED
@@ -0,0 +1,306 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
import re
|
4
|
+
from . import exceptions
|
5
|
+
|
6
|
+
ERR_EXCEPTION_TYPES = {
|
7
|
+
1: exceptions.InterfaceError,
|
8
|
+
2: exceptions.ProgrammingError,
|
9
|
+
3: exceptions.NotSupportedError,
|
10
|
+
4: exceptions.DatabaseError,
|
11
|
+
5: exceptions.InternalError,
|
12
|
+
6: exceptions.OperationalError,
|
13
|
+
7: exceptions.Warning,
|
14
|
+
}
|
15
|
+
|
16
|
+
# dbapi error code in InterfaceError
|
17
|
+
ERR_MISSING_ERROR = 1000
|
18
|
+
ERR_NOT_CONNECTED = 1001
|
19
|
+
ERR_NOT_A_QUERY = 1002
|
20
|
+
ERR_CURSOR_NOT_OPEN = 1003
|
21
|
+
|
22
|
+
# dbapi error code in ProgrammingError
|
23
|
+
ERR_NO_STATEMENT = 2001
|
24
|
+
ERR_NO_STATEMENT_PREPARED = 2002
|
25
|
+
ERR_WRONG_EXECUTE_PARAMETERS_TYPE = 2003
|
26
|
+
ERR_WRONG_EXECUTEMANY_PARAMETERS_TYPE = 2004
|
27
|
+
ERR_ARGS_AND_KEYWORD_ARGS = 2005
|
28
|
+
ERR_MIXED_POSITIONAL_AND_NAMED_BINDS = 2006
|
29
|
+
ERR_EXPECTING_TYPE = 2007
|
30
|
+
ERR_MIXED_ELEMENT_TYPES = 2008
|
31
|
+
ERR_WRONG_ARRAY_DEFINITION = 2009
|
32
|
+
ERR_ARGS_MUST_BE_LIST_OR_TUPLE = 2010
|
33
|
+
ERR_KEYWORD_ARGS_MUST_BE_DICT = 2011
|
34
|
+
ERR_DUPLICATED_PARAMETER = 2012
|
35
|
+
ERR_EXPECTING_VAR = 2013
|
36
|
+
ERR_INCORRECT_VAR_ARRAYSIZE = 2014
|
37
|
+
ERR_INVALID_MAKEDSN_ARG = 2015
|
38
|
+
ERR_INIT_GBASE8S_CLIENT_NOT_CALLED = 2016
|
39
|
+
ERR_INVALID_GCI_ATTR_TYPE = 2017
|
40
|
+
ERR_INVALID_CONNECT_PARAMS = 2018
|
41
|
+
ERR_EXPECTING_LIST_FOR_ARRAY_VAR = 2019
|
42
|
+
ERR_INVALID_LOB_OFFSET = 2020
|
43
|
+
ERR_INVALID_ARRAYSIZE = 2021
|
44
|
+
ERR_INVALID_LOB_AMOUNT = 2022
|
45
|
+
ERR_INVALID_ARGS = 2023
|
46
|
+
|
47
|
+
# dbapi error code in NotSupportedError
|
48
|
+
ERR_TIME_NOT_SUPPORTED = 3000
|
49
|
+
ERR_PYTHON_VALUE_NOT_SUPPORTED = 3001
|
50
|
+
ERR_PYTHON_TYPE_NOT_SUPPORTED = 3002
|
51
|
+
ERR_UNSUPPORTED_TYPE_SET = 3003
|
52
|
+
ERR_ARRAYS_OF_ARRAYS = 3004
|
53
|
+
ERR_GBASE8S_TYPE_NOT_SUPPORTED = 3005
|
54
|
+
ERR_DB_TYPE_NOT_SUPPORTED = 3006
|
55
|
+
ERR_SELF_BIND_NOT_SUPPORTED = 3007
|
56
|
+
ERR_UNSUPPORTED_PYTHON_TYPE_FOR_DB_TYPE = 3008
|
57
|
+
ERR_LOB_OF_WRONG_TYPE = 3009
|
58
|
+
ERR_GBASE8S_TYPE_NAME_NOT_SUPPORTED = 3010
|
59
|
+
ERR_NAMED_TIMEZONE_NOT_SUPPORTED = 3011
|
60
|
+
ERR_CURSOR_DIFF_CONNECTION = 3012
|
61
|
+
|
62
|
+
|
63
|
+
# dbapi error code in DatabaseError
|
64
|
+
ERR_GBASE8S_NUMBER_NO_REPR = 4000
|
65
|
+
ERR_INVALID_NUMBER = 4001
|
66
|
+
ERR_NUMBER_WITH_INVALID_EXPONENT = 4002
|
67
|
+
ERR_NUMBER_STRING_OF_ZERO_LENGTH = 4003
|
68
|
+
ERR_NUMBER_STRING_TOO_LONG = 4004
|
69
|
+
ERR_NUMBER_WITH_EMPTY_EXPONENT = 4005
|
70
|
+
ERR_CONTENT_INVALID_AFTER_NUMBER = 4006
|
71
|
+
|
72
|
+
|
73
|
+
# error code in InternalError
|
74
|
+
ERR_BUFFER_LENGTH_INSUFFICIENT = 5001
|
75
|
+
ERR_INTEGER_TOO_LARGE = 5002
|
76
|
+
ERR_UNEXPECTED_NEGATIVE_INTEGER = 5003
|
77
|
+
ERR_UNEXPECTED_END_OF_DATA = 5004
|
78
|
+
|
79
|
+
|
80
|
+
class ErrorWrapper(object):
|
81
|
+
regex_server_error = re.compile("ERROR:\s+\-(?P<code>[0-9]+):\s+.*")
|
82
|
+
regex_gci_error = re.compile("ERROR:\[GCI\]\s+.*")
|
83
|
+
|
84
|
+
def __init__(
|
85
|
+
self,
|
86
|
+
message = None,
|
87
|
+
context = None,
|
88
|
+
isrecoverable = False,
|
89
|
+
iswarning = False,
|
90
|
+
code = 0,
|
91
|
+
offset = 0,
|
92
|
+
):
|
93
|
+
self.exc_type = exceptions.DatabaseError
|
94
|
+
self.is_session_dead = False
|
95
|
+
self.offset = offset
|
96
|
+
self.code = code
|
97
|
+
self.full_code = ""
|
98
|
+
self.iswarning = iswarning
|
99
|
+
self.isrecoverable = isrecoverable
|
100
|
+
self.context = context
|
101
|
+
self.message = message
|
102
|
+
self._wrapper_error()
|
103
|
+
|
104
|
+
def _wrapper_error(self):
|
105
|
+
if self.message is not None:
|
106
|
+
if not self.message.startswith("ERROR"): # GDPI ERROR
|
107
|
+
pos = self.message.find(":")
|
108
|
+
if pos > 0:
|
109
|
+
self.full_code = self.message[:pos]
|
110
|
+
else:
|
111
|
+
match = self.regex_server_error.match(self.message)
|
112
|
+
if match is not None: # Gbase8s error
|
113
|
+
self.code = int(match.group("code"))
|
114
|
+
self.full_code = "GBA-{}".format(self.code)
|
115
|
+
else: # GCI error
|
116
|
+
match = self.regex_gci_error.match(self.message)
|
117
|
+
if match is not None:
|
118
|
+
self.full_code = "GCI-{}".format(self.code)
|
119
|
+
|
120
|
+
if self.full_code.startswith("DBAPI-"):
|
121
|
+
driver_error_num = int(self.full_code[6:])
|
122
|
+
self.exc_type = ERR_EXCEPTION_TYPES[driver_error_num // 1000]
|
123
|
+
elif self.full_code.startswith("GCI-"): # GCI error as InterfaceError
|
124
|
+
self.exc_type = exceptions.InterfaceError
|
125
|
+
elif self.code != 0:
|
126
|
+
if self.code in ERR_INTEGRITY_ERROR_CODES:
|
127
|
+
self.exc_type = exceptions.IntegrityError
|
128
|
+
elif self.code in ERR_PROGRAMMING_ERROR_CODES:
|
129
|
+
self.exc_type = exceptions.ProgrammingError
|
130
|
+
elif self.code in ERR_DATA_ERROR_CODES:
|
131
|
+
self.exc_type = exceptions.DataError
|
132
|
+
|
133
|
+
|
134
|
+
def __str__(self):
|
135
|
+
return str(self.message)
|
136
|
+
|
137
|
+
def __unicode__(self):
|
138
|
+
return self.message.decode('utf-8')
|
139
|
+
|
140
|
+
|
141
|
+
# error raise by gbase8sdb
|
142
|
+
ERROR_TYPE = "DBAPI"
|
143
|
+
|
144
|
+
def _get_whole_error(code, **kwargs):
|
145
|
+
msg_map = ERROR_MSG_MAPPING.get(code, None)
|
146
|
+
if not msg_map:
|
147
|
+
msg_map = "not found error code: {}.".format(code)
|
148
|
+
kwargs = {}
|
149
|
+
code = ERR_MISSING_ERROR
|
150
|
+
try:
|
151
|
+
whole_msg = msg_map.format(**kwargs)
|
152
|
+
except KeyError:
|
153
|
+
whole_msg = msg_map + "\nformat error with :\n" + str(kwargs)
|
154
|
+
return "{}-{:04}: {}".format(ERROR_TYPE, code, whole_msg)
|
155
|
+
|
156
|
+
|
157
|
+
def _create_error_wrapper(code, context_error_message=None, cause=None, **args):
|
158
|
+
message = _get_whole_error(code, **args)
|
159
|
+
if context_error_message is None and cause is not None:
|
160
|
+
context_error_message = str(cause)
|
161
|
+
if context_error_message is not None:
|
162
|
+
message = "{}\n{}".format(message, context_error_message)
|
163
|
+
return ErrorWrapper(message)
|
164
|
+
|
165
|
+
|
166
|
+
def raise_error(error_num, context_error_message=None, cause=None, **args):
|
167
|
+
error = _create_error_wrapper(error_num, context_error_message, cause, **args)
|
168
|
+
raise error.exc_type(error)
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
# GBA codes in IntegrityError
|
173
|
+
ERR_INTEGRITY_ERROR_CODES = [
|
174
|
+
268, # unique constraint violated
|
175
|
+
391, # cannot insert NULL
|
176
|
+
530, # check constraint violated
|
177
|
+
691, # referential constraint
|
178
|
+
703, # Primary key on table has a field with a null key value
|
179
|
+
]
|
180
|
+
# GBA codes in ProgrammingError
|
181
|
+
ERR_PROGRAMMING_ERROR_CODES = [
|
182
|
+
206, # table not found
|
183
|
+
310, # table already exists
|
184
|
+
201, # syntax error
|
185
|
+
]
|
186
|
+
|
187
|
+
# GBA codes in DataError
|
188
|
+
ERR_DATA_ERROR_CODES = [
|
189
|
+
1202, # divide by zero.
|
190
|
+
]
|
191
|
+
|
192
|
+
|
193
|
+
# mapping error code and error message
|
194
|
+
ERROR_MSG_MAPPING = {
|
195
|
+
ERR_KEYWORD_ARGS_MUST_BE_DICT: (
|
196
|
+
'<keyword_parameters> must be dict'
|
197
|
+
),
|
198
|
+
ERR_LOB_OF_WRONG_TYPE: (
|
199
|
+
"LOB must be type {expected_type_name}, not type {actual_type_name}"
|
200
|
+
),
|
201
|
+
ERR_MIXED_ELEMENT_TYPES: (
|
202
|
+
"The element {element} does not match the data type of the preceding elements."
|
203
|
+
),
|
204
|
+
ERR_MIXED_POSITIONAL_AND_NAMED_BINDS: (
|
205
|
+
"Positional and named bindings are not allowed to be used together"
|
206
|
+
),
|
207
|
+
ERR_NAMED_TIMEZONE_NOT_SUPPORTED: (
|
208
|
+
"Other modes are incompatible with the use of named time zones"
|
209
|
+
),
|
210
|
+
ERR_NO_STATEMENT: (
|
211
|
+
"Neither a statement is specified nor a prior one prepared"
|
212
|
+
),
|
213
|
+
ERR_NO_STATEMENT_PREPARED: (
|
214
|
+
"statement should be prepared in advance"
|
215
|
+
),
|
216
|
+
ERR_NOT_A_QUERY: (
|
217
|
+
"No rows are returned by the executed statement"
|
218
|
+
),
|
219
|
+
ERR_NOT_CONNECTED: (
|
220
|
+
"The database connection is not established"
|
221
|
+
),
|
222
|
+
ERR_NUMBER_STRING_OF_ZERO_LENGTH: "invalid number: zero length string",
|
223
|
+
ERR_NUMBER_STRING_TOO_LONG: "invalid number: string too long",
|
224
|
+
ERR_NUMBER_WITH_EMPTY_EXPONENT: "invalid number: empty exponent",
|
225
|
+
ERR_NUMBER_WITH_INVALID_EXPONENT: "invalid number: invalid exponent",
|
226
|
+
ERR_GBASE8S_NUMBER_NO_REPR: (
|
227
|
+
"The value is incapable of being expressed as a Gbase8s number"
|
228
|
+
),
|
229
|
+
ERR_GBASE8S_TYPE_NAME_NOT_SUPPORTED: 'not support Gbase8s data type name "{name}"',
|
230
|
+
ERR_GBASE8S_TYPE_NOT_SUPPORTED: "not support Gbase8s data type {num}",
|
231
|
+
ERR_PYTHON_TYPE_NOT_SUPPORTED: "not support Python type {typ}",
|
232
|
+
ERR_PYTHON_VALUE_NOT_SUPPORTED: 'not support Python value of type "{type_name}"',
|
233
|
+
ERR_SELF_BIND_NOT_SUPPORTED: "binding to self is not supported",
|
234
|
+
ERR_TIME_NOT_SUPPORTED: (
|
235
|
+
"Gbase8s Database does not support time only variables"
|
236
|
+
),
|
237
|
+
ERR_UNEXPECTED_END_OF_DATA: (
|
238
|
+
"unexpected end of data: want {num_bytes_wanted} bytes but "
|
239
|
+
"only {num_bytes_available} bytes are available"
|
240
|
+
),
|
241
|
+
ERR_UNEXPECTED_NEGATIVE_INTEGER: (
|
242
|
+
"Internal error: a negative integer was read, "
|
243
|
+
"but a positive integer was anticipated"
|
244
|
+
),
|
245
|
+
ERR_UNSUPPORTED_PYTHON_TYPE_FOR_DB_TYPE: (
|
246
|
+
"unsupported Python type {py_type_name} for database type "
|
247
|
+
"{db_type_name}"
|
248
|
+
),
|
249
|
+
ERR_UNSUPPORTED_TYPE_SET: "type {db_type_name} does not support being set",
|
250
|
+
ERR_WRONG_ARRAY_DEFINITION: (
|
251
|
+
"expecting a list of two elements [type, numelems]"
|
252
|
+
),
|
253
|
+
ERR_WRONG_EXECUTE_PARAMETERS_TYPE: (
|
254
|
+
"expecting a dictionary, list or tuple, or keyword args"
|
255
|
+
),
|
256
|
+
ERR_WRONG_EXECUTEMANY_PARAMETERS_TYPE: (
|
257
|
+
'For the "parameters" argument, a list of sequences '
|
258
|
+
'or dictionaries is expected, '
|
259
|
+
"or alternatively, an integer to denote the execution count of the statement"
|
260
|
+
),
|
261
|
+
ERR_INVALID_GCI_ATTR_TYPE: "invalid GCI attribute type {attr_type}",
|
262
|
+
ERR_INVALID_NUMBER: "invalid number",
|
263
|
+
ERR_INVALID_MAKEDSN_ARG: '"{name}" argument contains invalid values',
|
264
|
+
ERR_INVALID_LOB_OFFSET: "LOB offset must be greater than zero",
|
265
|
+
ERR_INVALID_LOB_AMOUNT: "LOB amount must be greater than zero",
|
266
|
+
ERR_INVALID_CONNECT_PARAMS: "invalid connection params",
|
267
|
+
ERR_INVALID_ARRAYSIZE: "arraysize must be an integer greater than zero",
|
268
|
+
ERR_INTEGER_TOO_LARGE: (
|
269
|
+
"internal error: read integer of length {length} when expecting "
|
270
|
+
"integer of no more than length {max_length}"
|
271
|
+
),
|
272
|
+
ERR_INIT_GBASE8S_CLIENT_NOT_CALLED: (
|
273
|
+
"init_gbase8s_client() must be called first"
|
274
|
+
),
|
275
|
+
ERR_INCORRECT_VAR_ARRAYSIZE: (
|
276
|
+
"variable array size of {var_arraysize} is "
|
277
|
+
"too small (should be at least {required_arraysize})"
|
278
|
+
),
|
279
|
+
ERR_EXPECTING_VAR: (
|
280
|
+
"type handler should return None or the value returned by a call "
|
281
|
+
"to cursor.var()"
|
282
|
+
),
|
283
|
+
ERR_EXPECTING_TYPE: "expected a type",
|
284
|
+
ERR_EXPECTING_LIST_FOR_ARRAY_VAR: (
|
285
|
+
"expecting list when setting array variables"
|
286
|
+
),
|
287
|
+
ERR_DUPLICATED_PARAMETER: (
|
288
|
+
'"{deprecated_name}" and "{new_name}" cannot be specified together'
|
289
|
+
),
|
290
|
+
ERR_DB_TYPE_NOT_SUPPORTED: 'database type "{name}" is not supported',
|
291
|
+
ERR_CURSOR_NOT_OPEN: "cursor is not open",
|
292
|
+
ERR_CURSOR_DIFF_CONNECTION: (
|
293
|
+
"It is not supported to bind a cursor from a different connection."
|
294
|
+
),
|
295
|
+
ERR_CONTENT_INVALID_AFTER_NUMBER: "invalid number (content after number)",
|
296
|
+
ERR_BUFFER_LENGTH_INSUFFICIENT: (
|
297
|
+
"internal error: buffer of length {actual_buffer_len} "
|
298
|
+
"insufficient to hold {required_buffer_len} bytes"
|
299
|
+
),
|
300
|
+
ERR_ARRAYS_OF_ARRAYS: "arrays of arrays are not supported",
|
301
|
+
ERR_ARGS_AND_KEYWORD_ARGS: (
|
302
|
+
"expecting positional arguments or keyword arguments, not both"
|
303
|
+
),
|
304
|
+
ERR_ARGS_MUST_BE_LIST_OR_TUPLE: "arguments must be a list or tuple",
|
305
|
+
ERR_INVALID_ARGS: "Invalid arguments",
|
306
|
+
}
|
gbase8sdb/exceptions.py
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
class Warning(Exception):
|
5
|
+
pass
|
6
|
+
|
7
|
+
|
8
|
+
class Error(Exception):
|
9
|
+
pass
|
10
|
+
|
11
|
+
|
12
|
+
class DatabaseError(Error):
|
13
|
+
pass
|
14
|
+
|
15
|
+
|
16
|
+
class DataError(DatabaseError):
|
17
|
+
pass
|
18
|
+
|
19
|
+
|
20
|
+
class IntegrityError(DatabaseError):
|
21
|
+
pass
|
22
|
+
|
23
|
+
|
24
|
+
class InterfaceError(Error):
|
25
|
+
pass
|
26
|
+
|
27
|
+
|
28
|
+
class InternalError(DatabaseError):
|
29
|
+
pass
|
30
|
+
|
31
|
+
|
32
|
+
class NotSupportedError(DatabaseError):
|
33
|
+
pass
|
34
|
+
|
35
|
+
|
36
|
+
class OperationalError(DatabaseError):
|
37
|
+
pass
|
38
|
+
|
39
|
+
|
40
|
+
class ProgrammingError(DatabaseError):
|
41
|
+
pass
|
gbase8sdb/lob.py
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
from . import __name__ as MODULE_NAME
|
4
|
+
from . import errors
|
5
|
+
from .driver import DB_TYPE_BLOB
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
class LOB(object):
|
10
|
+
__module__ = MODULE_NAME
|
11
|
+
|
12
|
+
def __str__(self):
|
13
|
+
return str(self.read())
|
14
|
+
|
15
|
+
def __del__(self):
|
16
|
+
self._cyobj.free_lob()
|
17
|
+
|
18
|
+
def __reduce__(self):
|
19
|
+
value = self.read()
|
20
|
+
return (type(value), (value,))
|
21
|
+
|
22
|
+
|
23
|
+
@classmethod
|
24
|
+
def _create_with_cyobj(cls, cyobj):
|
25
|
+
lob = cls.__new__(cls)
|
26
|
+
lob._cyobj = cyobj
|
27
|
+
return lob
|
28
|
+
|
29
|
+
def _check_value_to_write(self, value):
|
30
|
+
if isinstance(value, bytes):
|
31
|
+
return value
|
32
|
+
elif isinstance(value, unicode):
|
33
|
+
return value.encode('utf-8')
|
34
|
+
else:
|
35
|
+
raise TypeError("expecting string or bytes")
|
36
|
+
|
37
|
+
def close(self):
|
38
|
+
self._cyobj.close()
|
39
|
+
|
40
|
+
def getchunksize(self):
|
41
|
+
return self._cyobj.get_chunk_size()
|
42
|
+
|
43
|
+
def isopen(self):
|
44
|
+
return self._cyobj.get_is_open()
|
45
|
+
|
46
|
+
def open(self):
|
47
|
+
self._cyobj.open()
|
48
|
+
|
49
|
+
def read(self, offset=1, amount=None):
|
50
|
+
if amount is None:
|
51
|
+
amount = self._cyobj.get_max_amount()
|
52
|
+
if amount >= offset:
|
53
|
+
amount = amount - offset + 1
|
54
|
+
else:
|
55
|
+
amount = 1
|
56
|
+
elif amount <= 0:
|
57
|
+
errors.raise_error(errors.ERR_INVALID_LOB_AMOUNT)
|
58
|
+
if offset <= 0:
|
59
|
+
errors.raise_error(errors.ERR_INVALID_LOB_OFFSET)
|
60
|
+
return self._cyobj.read(offset, amount)
|
61
|
+
|
62
|
+
def size(self):
|
63
|
+
return self._cyobj.get_size()
|
64
|
+
|
65
|
+
def trim(self, new_size=0, newSize=None):
|
66
|
+
if newSize is not None:
|
67
|
+
if new_size != 0:
|
68
|
+
errors.raise_error(
|
69
|
+
errors.ERR_DUPLICATED_PARAMETER,
|
70
|
+
deprecated_name="newSize",
|
71
|
+
new_name="new_size",
|
72
|
+
)
|
73
|
+
new_size = newSize
|
74
|
+
self._cyobj.trim(new_size)
|
75
|
+
|
76
|
+
def write(self, data, offset=1):
|
77
|
+
self._cyobj.write(self._check_value_to_write(data), offset)
|
78
|
+
|
79
|
+
@property
|
80
|
+
def type(self):
|
81
|
+
return self._cyobj.dbtype
|
gbase8sdb/var.py
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
from .driver import DbType
|
4
|
+
|
5
|
+
|
6
|
+
class Var(object):
|
7
|
+
def __repr__(self):
|
8
|
+
value = self._cyobj.get_all_values()
|
9
|
+
if not self._cyobj.is_array and len(value) == 1:
|
10
|
+
value = value[0]
|
11
|
+
typ = self._type
|
12
|
+
return "<gbase8sdb.Var of type {} with value {}>".format(typ.name, repr(value))
|
13
|
+
|
14
|
+
@classmethod
|
15
|
+
def _create_with_cyobj(cls, impl, typ=None):
|
16
|
+
var = cls.__new__(cls)
|
17
|
+
var._cyobj = impl
|
18
|
+
if typ is not None:
|
19
|
+
var._type = typ
|
20
|
+
else:
|
21
|
+
var._type = impl.dbtype
|
22
|
+
return var
|
23
|
+
|
24
|
+
@property
|
25
|
+
def actual_elements(self):
|
26
|
+
if self._cyobj.is_array:
|
27
|
+
return self._cyobj.num_elements_in_array
|
28
|
+
return self._cyobj.num_elements
|
29
|
+
|
30
|
+
@property
|
31
|
+
def actualElements(self):
|
32
|
+
return self.actual_elements
|
33
|
+
|
34
|
+
@property
|
35
|
+
def buffer_size(self):
|
36
|
+
return self._cyobj.buffer_size
|
37
|
+
|
38
|
+
@property
|
39
|
+
def bufferSize(self):
|
40
|
+
return self.buffer_size
|
41
|
+
|
42
|
+
@property
|
43
|
+
def convert_nulls(self):
|
44
|
+
return self._cyobj.convert_nulls
|
45
|
+
|
46
|
+
def getvalue(self, pos=0):
|
47
|
+
return self._cyobj.get_value(pos)
|
48
|
+
|
49
|
+
@property
|
50
|
+
def inconverter(self):
|
51
|
+
return self._cyobj.inconverter
|
52
|
+
|
53
|
+
@property
|
54
|
+
def num_elements(self):
|
55
|
+
return self._cyobj.num_elements
|
56
|
+
|
57
|
+
@property
|
58
|
+
def numElements(self):
|
59
|
+
return self.num_elements
|
60
|
+
|
61
|
+
@property
|
62
|
+
def outconverter(self):
|
63
|
+
return self._cyobj.outconverter
|
64
|
+
|
65
|
+
def setvalue(self, pos, value):
|
66
|
+
self._cyobj.set_value(pos, value)
|
67
|
+
|
68
|
+
@property
|
69
|
+
def size(self):
|
70
|
+
return self._cyobj.size
|
71
|
+
|
72
|
+
@property
|
73
|
+
def type(self):
|
74
|
+
return self._type
|
75
|
+
|
76
|
+
@property
|
77
|
+
def values(self):
|
78
|
+
return self._cyobj.get_all_values()
|
gbase8sdb/version.py
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (C) 2025 GBASE Technologies Co.,Ltd.
|
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,96 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: gbase8sdb
|
3
|
+
Version: 0.2.1
|
4
|
+
Summary: Python interface to GBase 8s Database
|
5
|
+
Home-page: UNKNOWN
|
6
|
+
License: MIT
|
7
|
+
Keywords: GBase 8s,database
|
8
|
+
Platform: UNKNOWN
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
10
|
+
Classifier: Intended Audience :: Developers
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
12
|
+
Classifier: Natural Language :: English
|
13
|
+
Classifier: Operating System :: OS Independent
|
14
|
+
Classifier: Programming Language :: Python :: 2 :: Only
|
15
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
16
|
+
Classifier: Programming Language :: Cython
|
17
|
+
Classifier: Topic :: Database
|
18
|
+
Requires-Python: >=2.7
|
19
|
+
Description-Content-Type: text/markdown
|
20
|
+
|
21
|
+
# python-gbase8sdb
|
22
|
+
|
23
|
+
python-gbase8sdb 是一个 [Python 编程语言][python] 扩展模块,允许 Python 程序连接到 GBase 8s 数据库。
|
24
|
+
|
25
|
+
该模块符合 [Python 数据库 API 2.0 规范][pep249],并且包含大量扩展和少数排除项。
|
26
|
+
|
27
|
+
|
28
|
+
## 安装
|
29
|
+
|
30
|
+
运行 `python -m pip install gbase8sdb` 安装。
|
31
|
+
|
32
|
+
|
33
|
+
## 依赖和互操作性
|
34
|
+
|
35
|
+
- 支持的 Python 版本:2.7 。
|
36
|
+
|
37
|
+
- 支持的 GBase 8s 数据库版本:GBase 8s V8.8_3.6.2版本及以上。
|
38
|
+
|
39
|
+
- 支持的操作系统:Linux x86_64、 Windows 64位操作系统 。
|
40
|
+
|
41
|
+
- 依赖 GSDK 1.1 版本。
|
42
|
+
|
43
|
+
|
44
|
+
#### 使用说明
|
45
|
+
|
46
|
+
1. gbase8sdb驱动连接数据库依赖GSDK,所以您需要联系GBase 8s技术支持或通过官方渠道获取相应版本的GSDK,并安装到您的机器上, 并设置如下环境变量:
|
47
|
+
|
48
|
+
- Linux系统:
|
49
|
+
```bash
|
50
|
+
GSDK_PATH=/path/to/gsdk
|
51
|
+
export LD_LIBRARY_PATH=${GSDK_PATH}/lib:$LD_LIBRARY_PATH
|
52
|
+
export GBASEDBTDIR=${GSDK_PATH}/lib
|
53
|
+
```
|
54
|
+
|
55
|
+
- Windows系统:
|
56
|
+
|
57
|
+
```cmd
|
58
|
+
GSDK_PATH=\path\to\gsdk
|
59
|
+
set PATH=%GSDK_PATH%\lib;%PATH%
|
60
|
+
set GBASEDBTDIR=%GSDK_PATH%\lib
|
61
|
+
```
|
62
|
+
|
63
|
+
#### 入门
|
64
|
+
在您的Python应用程序中,可以通过以下方式连接到数据库:
|
65
|
+
```python
|
66
|
+
import gbase8sdb
|
67
|
+
|
68
|
+
# 生成dsn
|
69
|
+
dsn = gbase8sdb.makedsn(
|
70
|
+
server_name="ol_gbasedbt1210_2", # 数据库实例名称
|
71
|
+
db_name="testdbutf8", # 数据库名称
|
72
|
+
host="192.168.xxx.xxx", # 数据库实例所在服务器的IP地址或域名
|
73
|
+
port=9088, # 数据库实例的端口号
|
74
|
+
db_locale='zh_CN.utf8' # 数据库字符集
|
75
|
+
)
|
76
|
+
user = "gbasedbt" # 数据库用户名
|
77
|
+
password = "xxxxxx" # 数据库用户密码
|
78
|
+
|
79
|
+
# 连接数据库
|
80
|
+
conn = gbase8sdb.connect(dsn, user, password)
|
81
|
+
# 创建游标
|
82
|
+
cursor = conn.cursor()
|
83
|
+
# 执行SQL语句
|
84
|
+
cursor.execute("drop table if exists t")
|
85
|
+
cursor.execute("create table t (id int, name varchar(20))")
|
86
|
+
cursor.execute("insert into t values (?, ?)", (1, "zhangsan"))
|
87
|
+
cursor.execute("select * from t")
|
88
|
+
# 获取查询结果
|
89
|
+
print(cursor.fetchall())
|
90
|
+
# 关闭游标和连接
|
91
|
+
cursor.close()
|
92
|
+
conn.close()
|
93
|
+
```
|
94
|
+
|
95
|
+
|
96
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
gbase8sdb/__init__.py,sha256=bDUY5HF6kCtOExU1hw07DeEBdGgacLrYzcgrwOcv3JY,2896
|
2
|
+
gbase8sdb/column_metadata.py,sha256=v7_I1Pqv03b5tXHVtiX11jATMCHKdZrrNjeIreqbXOY,2728
|
3
|
+
gbase8sdb/connection.py,sha256=_kxbGfux0kU_GeQkM7Eb13_CqRRojm8kgkUYFjhl6QM,4406
|
4
|
+
gbase8sdb/constructors.py,sha256=XDhPMt2PBYWmtRQ3hWzyV0xWB9Xf_s4U8_U7o__dgp0,729
|
5
|
+
gbase8sdb/cursor.py,sha256=OC5xiGmu8LZUW8D1-k0QsdkaOvRw-pKI8XrufjAsNzI,11561
|
6
|
+
gbase8sdb/defaults.py,sha256=fao3XMkISfnDv0zHgV5BmZ9-6XjALylQfLex2LtM0ao,943
|
7
|
+
gbase8sdb/driver.so,sha256=P1qAi6fmn33rtKSNDwqCJdzxWN_mR7s4NwkURMSL3Yw,3374625
|
8
|
+
gbase8sdb/dsn.py,sha256=inkJK6MKhdi7ACwjftMSJRK3EwlEVeo1APfGNakXMIQ,1571
|
9
|
+
gbase8sdb/errors.py,sha256=LcxNHv0kh3mAqinGq5orZqi4nsy1vrObV0FZ6UbBe6M,11021
|
10
|
+
gbase8sdb/exceptions.py,sha256=SjWBklHYQDIcQ1asBU2FDbvx94x_O89P6rC-7gDfpPA,456
|
11
|
+
gbase8sdb/lob.py,sha256=RRzIhln8env6AtwKgh8z-urfZEUzquJlnQ1vygo3Ut0,2089
|
12
|
+
gbase8sdb/var.py,sha256=t_3jOnXl-eoKrgvktbEDEiSFdiLlEyQ2AWW9VOJXV_E,1758
|
13
|
+
gbase8sdb/version.py,sha256=KmUSBsPG3q90ARyQ63M792UgARfKGObOY74G8H11XIk,96
|
14
|
+
gbase8sdb-0.2.1.dist-info/LICENSE.txt,sha256=kDUGdWcTVtXFktGLHB-glp1LI92-VW5ipQlAVR4WKP4,1083
|
15
|
+
gbase8sdb-0.2.1.dist-info/METADATA,sha256=1kE3Jxxqvu7V9jsQT-ONq_gr8wDkqEVAufUcW2QNniQ,2809
|
16
|
+
gbase8sdb-0.2.1.dist-info/THIRD_PARTY_LICENSES.txt,sha256=88_Bn1SLiGFNZq9HNBedps7zemgR50FRat29TWtFkj4,28103
|
17
|
+
gbase8sdb-0.2.1.dist-info/WHEEL,sha256=OoQL-axGe9-57HgHP6IIeuGDTuG7GCIux9Mr13H3fwo,152
|
18
|
+
gbase8sdb-0.2.1.dist-info/top_level.txt,sha256=5M_P75jEB53qPfRObJmPBMDvuPGpZil5omAJAMlaqlI,10
|
19
|
+
gbase8sdb-0.2.1.dist-info/RECORD,,
|