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/__init__.py
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
"""
|
3
|
+
the package of gbase8sdb __init__ module
|
4
|
+
"""
|
5
|
+
|
6
|
+
import sys
|
7
|
+
import collections
|
8
|
+
|
9
|
+
apilevel = "2.0"
|
10
|
+
paramstyle = "qmark"
|
11
|
+
threadsafety = 2
|
12
|
+
|
13
|
+
# version info
|
14
|
+
from .version import __version__
|
15
|
+
version = __version__
|
16
|
+
|
17
|
+
from . import driver
|
18
|
+
|
19
|
+
from .driver import (
|
20
|
+
DB_TYPE_BINARY_DOUBLE,
|
21
|
+
DB_TYPE_BINARY_FLOAT,
|
22
|
+
DB_TYPE_BINARY_INTEGER,
|
23
|
+
DB_TYPE_BLOB,
|
24
|
+
DB_TYPE_CHAR,
|
25
|
+
DB_TYPE_CLOB,
|
26
|
+
DB_TYPE_CURSOR,
|
27
|
+
DB_TYPE_DATE, # map to TIMESTAMP
|
28
|
+
DB_TYPE_INTERVAL_DS,
|
29
|
+
DB_TYPE_INTERVAL_YM,
|
30
|
+
DB_TYPE_LONG_NVARCHAR,
|
31
|
+
DB_TYPE_NCHAR,
|
32
|
+
DB_TYPE_NCLOB,
|
33
|
+
DB_TYPE_NUMBER,
|
34
|
+
DB_TYPE_NVARCHAR,
|
35
|
+
DB_TYPE_TIMESTAMP,
|
36
|
+
DB_TYPE_TIMESTAMP_TZ,
|
37
|
+
DB_TYPE_VARCHAR,
|
38
|
+
# DB API
|
39
|
+
BINARY,
|
40
|
+
DATETIME,
|
41
|
+
NUMBER,
|
42
|
+
ROWID,
|
43
|
+
STRING,
|
44
|
+
)
|
45
|
+
|
46
|
+
|
47
|
+
from .exceptions import (
|
48
|
+
Warning as Warning,
|
49
|
+
Error as Error,
|
50
|
+
DatabaseError as DatabaseError,
|
51
|
+
DataError as DataError,
|
52
|
+
IntegrityError as IntegrityError,
|
53
|
+
InterfaceError as InterfaceError,
|
54
|
+
InternalError as InternalError,
|
55
|
+
NotSupportedError as NotSupportedError,
|
56
|
+
OperationalError as OperationalError,
|
57
|
+
ProgrammingError as ProgrammingError,
|
58
|
+
)
|
59
|
+
|
60
|
+
from .defaults import defaults
|
61
|
+
|
62
|
+
from .connection import connect, Connection
|
63
|
+
|
64
|
+
from .cursor import Cursor
|
65
|
+
|
66
|
+
from .lob import LOB
|
67
|
+
|
68
|
+
from .column_metadata import ColumnMetaData
|
69
|
+
|
70
|
+
from .var import Var
|
71
|
+
|
72
|
+
from .dsn import makedsn
|
73
|
+
|
74
|
+
from .driver import load_gsdk as __load_gsdk, clientversion
|
75
|
+
|
76
|
+
from .constructors import (
|
77
|
+
Binary as Binary,
|
78
|
+
Date as Date,
|
79
|
+
DateFromTicks as DateFromTicks,
|
80
|
+
Time as Time,
|
81
|
+
TimeFromTicks as TimeFromTicks,
|
82
|
+
Timestamp as Timestamp,
|
83
|
+
TimestampFromTicks as TimestampFromTicks,
|
84
|
+
)
|
85
|
+
|
86
|
+
|
87
|
+
IntervalYM = collections.namedtuple("IntervalYM", ["years", "months"])
|
88
|
+
|
89
|
+
|
90
|
+
package = sys.modules[__name__]
|
91
|
+
driver.init_driver(package)
|
92
|
+
|
93
|
+
|
94
|
+
del package
|
95
|
+
del sys
|
96
|
+
del driver, connection, constructors
|
97
|
+
del cursor, dsn, exceptions, column_metadata
|
98
|
+
del lob
|
99
|
+
del var
|
100
|
+
|
101
|
+
__load_gsdk()
|
102
|
+
|
103
|
+
|
104
|
+
__all__ = [
|
105
|
+
# defined in DB API
|
106
|
+
"apilevel", "paramstyle", "threadsafety",
|
107
|
+
"BINARY", "DATETIME", "NUMBER", "ROWID", "STRING",
|
108
|
+
"Binary", "Date", "DateFromTicks", "Time", "TimeFromTicks", "Timestamp", "TimestampFromTicks",
|
109
|
+
"Warning", "Error", "DatabaseError", "DataError", "IntegrityError", "InterfaceError",
|
110
|
+
"InternalError", "NotSupportedError", "OperationalError", "ProgrammingError",
|
111
|
+
"connect", "Connection",
|
112
|
+
# not define in DB API
|
113
|
+
"DB_TYPE_BINARY_DOUBLE", "DB_TYPE_BINARY_FLOAT", "DB_TYPE_BINARY_INTEGER", "DB_TYPE_BLOB",
|
114
|
+
"DB_TYPE_CHAR", "DB_TYPE_CLOB", "DB_TYPE_CURSOR", "DB_TYPE_DATE", "DB_TYPE_INTERVAL_DS",
|
115
|
+
"DB_TYPE_INTERVAL_YM", "DB_TYPE_LONG_NVARCHAR", "DB_TYPE_NCHAR", "DB_TYPE_NCLOB",
|
116
|
+
"DB_TYPE_NUMBER", "DB_TYPE_NVARCHAR", "DB_TYPE_TIMESTAMP", "DB_TYPE_TIMESTAMP_TZ", "DB_TYPE_VARCHAR",
|
117
|
+
"ColumnMetaData", "Var", "makedsn", "clientversion", "IntervalYM",
|
118
|
+
"defaults", "Cursor", "LOB", "version"
|
119
|
+
]
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
from . import __name__ as MODULE_NAME
|
3
|
+
|
4
|
+
from .driver import (
|
5
|
+
DbType,
|
6
|
+
DB_TYPE_NUMBER,
|
7
|
+
DB_TYPE_BINARY_INTEGER,
|
8
|
+
DB_TYPE_BINARY_DOUBLE,
|
9
|
+
DB_TYPE_BINARY_FLOAT,
|
10
|
+
DB_TYPE_TIMESTAMP_TZ,
|
11
|
+
DB_TYPE_TIMESTAMP_LTZ,
|
12
|
+
DB_TYPE_TIMESTAMP,
|
13
|
+
DB_TYPE_DATE,
|
14
|
+
|
15
|
+
)
|
16
|
+
|
17
|
+
|
18
|
+
class ColumnMetaData(object):
|
19
|
+
|
20
|
+
__module__ = MODULE_NAME
|
21
|
+
|
22
|
+
|
23
|
+
def __str__(self):
|
24
|
+
return str(tuple(self))
|
25
|
+
|
26
|
+
def __repr__(self):
|
27
|
+
return repr(tuple(self))
|
28
|
+
|
29
|
+
|
30
|
+
def __len__(self):
|
31
|
+
return 7
|
32
|
+
|
33
|
+
|
34
|
+
def __eq__(self, other):
|
35
|
+
return tuple(self) == other
|
36
|
+
|
37
|
+
def __getitem__(self, index):
|
38
|
+
description = (
|
39
|
+
self.name,
|
40
|
+
self.type_code,
|
41
|
+
self.display_size,
|
42
|
+
self.internal_size,
|
43
|
+
self.precision,
|
44
|
+
self.scale,
|
45
|
+
self.null_ok,
|
46
|
+
)
|
47
|
+
return description[index]
|
48
|
+
|
49
|
+
@classmethod
|
50
|
+
def _create_with_cyobj(cls, cyobj):
|
51
|
+
info = cls.__new__(cls)
|
52
|
+
info._type = None
|
53
|
+
info._cyobj = cyobj
|
54
|
+
return info
|
55
|
+
|
56
|
+
@staticmethod
|
57
|
+
def _is_date_type(dbtype):
|
58
|
+
return dbtype in {DB_TYPE_DATE, DB_TYPE_TIMESTAMP, DB_TYPE_TIMESTAMP_LTZ, DB_TYPE_TIMESTAMP_TZ}
|
59
|
+
|
60
|
+
@staticmethod
|
61
|
+
def _is_numeric_type(dbtype):
|
62
|
+
return dbtype in {DB_TYPE_BINARY_FLOAT, DB_TYPE_BINARY_DOUBLE, DB_TYPE_BINARY_INTEGER, DB_TYPE_NUMBER}
|
63
|
+
|
64
|
+
@property
|
65
|
+
def internal_size(self):
|
66
|
+
if self._cyobj.size > 0:
|
67
|
+
return self._cyobj.buffer_size
|
68
|
+
|
69
|
+
@property
|
70
|
+
def is_json(self):
|
71
|
+
return self._cyobj.is_json
|
72
|
+
|
73
|
+
@property
|
74
|
+
def name(self):
|
75
|
+
return self._cyobj.name
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
@property
|
80
|
+
def precision(self):
|
81
|
+
if self._cyobj.precision or self._cyobj.scale:
|
82
|
+
return self._cyobj.precision
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
@property
|
87
|
+
def type(self):
|
88
|
+
if self._type is None:
|
89
|
+
self._type = self._cyobj.dbtype
|
90
|
+
return self._type
|
91
|
+
|
92
|
+
@property
|
93
|
+
def type_code(self):
|
94
|
+
return self._cyobj.dbtype
|
95
|
+
|
96
|
+
@property
|
97
|
+
def display_size(self):
|
98
|
+
if self._cyobj.size > 0:
|
99
|
+
return self._cyobj.size
|
100
|
+
dbtype = self._cyobj.dbtype
|
101
|
+
if self._is_numeric_type(dbtype):
|
102
|
+
if self._cyobj.precision:
|
103
|
+
display_size = self._cyobj.precision + 1
|
104
|
+
if self._cyobj.scale > 0:
|
105
|
+
display_size += self._cyobj.scale + 1
|
106
|
+
else:
|
107
|
+
display_size = 127
|
108
|
+
return display_size
|
109
|
+
elif self._is_date_type(dbtype):
|
110
|
+
return 23
|
111
|
+
|
112
|
+
@property
|
113
|
+
def scale(self):
|
114
|
+
if self._cyobj.precision or self._cyobj.scale:
|
115
|
+
return self._cyobj.scale
|
116
|
+
|
117
|
+
@property
|
118
|
+
def null_ok(self):
|
119
|
+
return self._cyobj.nulls_allowed
|
gbase8sdb/connection.py
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
from . import __name__ as MODULE_NAME
|
4
|
+
from . import errors
|
5
|
+
from . import driver
|
6
|
+
from .cursor import Cursor
|
7
|
+
from .lob import LOB
|
8
|
+
from .driver import DB_TYPE_BLOB, DB_TYPE_CLOB, DB_TYPE_NCLOB, DbType
|
9
|
+
|
10
|
+
|
11
|
+
class Connection(object):
|
12
|
+
__module__ = MODULE_NAME
|
13
|
+
|
14
|
+
def __init__(self, dsn, user, password):
|
15
|
+
self._cyobj = None
|
16
|
+
self._version = None
|
17
|
+
cy_conn = driver.CyConnection(dsn, user, password)
|
18
|
+
cy_conn.connect()
|
19
|
+
self._cyobj = cy_conn
|
20
|
+
|
21
|
+
def __repr__(self):
|
22
|
+
cls_name = "{}.{}".format(self.__class__.__module__, self.__class__.__name__)
|
23
|
+
if self._cyobj is None:
|
24
|
+
return "<{cls_name} disconnected>".format(cls_name=cls_name)
|
25
|
+
return "<{cls_name} to {username}@{dsn}>".format(cls_name=cls_name, username=self.username, dsn=self.dsn)
|
26
|
+
|
27
|
+
def __del__(self):
|
28
|
+
if self._cyobj is not None:
|
29
|
+
self._cyobj.close(in_del=True)
|
30
|
+
self._cyobj = None
|
31
|
+
|
32
|
+
def __enter__(self):
|
33
|
+
self._verify_connected()
|
34
|
+
return self
|
35
|
+
|
36
|
+
def __exit__(self, exc_type, exc_value, exc_tb):
|
37
|
+
if self._cyobj is not None:
|
38
|
+
self._cyobj.close(in_del=True)
|
39
|
+
self._cyobj = None
|
40
|
+
|
41
|
+
def _verify_connected(self):
|
42
|
+
if self._cyobj is None:
|
43
|
+
errors.raise_error(errors.ERR_NOT_CONNECTED)
|
44
|
+
|
45
|
+
def close(self):
|
46
|
+
self._verify_connected()
|
47
|
+
self._cyobj.close()
|
48
|
+
self._cyobj = None
|
49
|
+
|
50
|
+
def commit(self):
|
51
|
+
self._verify_connected()
|
52
|
+
self._cyobj.commit()
|
53
|
+
|
54
|
+
def createlob(
|
55
|
+
self, lob_type, data=None
|
56
|
+
):
|
57
|
+
self._verify_connected()
|
58
|
+
if lob_type not in (DB_TYPE_CLOB, DB_TYPE_NCLOB, DB_TYPE_BLOB):
|
59
|
+
message = (
|
60
|
+
"lob type should be one of gbase8sdb.DB_TYPE_BLOB, "
|
61
|
+
"gbase8sdb.DB_TYPE_CLOB or gbase8sdb.DB_TYPE_NCLOB"
|
62
|
+
)
|
63
|
+
raise TypeError(message)
|
64
|
+
impl = self._cyobj.create_temp_lob_impl(lob_type)
|
65
|
+
lob = LOB._create_with_cyobj(impl)
|
66
|
+
if data:
|
67
|
+
lob.write(data)
|
68
|
+
return lob
|
69
|
+
|
70
|
+
def cursor(self):
|
71
|
+
self._verify_connected()
|
72
|
+
return Cursor(self)
|
73
|
+
|
74
|
+
def ping(self):
|
75
|
+
self._verify_connected()
|
76
|
+
self._cyobj.ping()
|
77
|
+
|
78
|
+
def rollback(self):
|
79
|
+
self._verify_connected()
|
80
|
+
self._cyobj.rollback()
|
81
|
+
|
82
|
+
def cancel(self):
|
83
|
+
self._verify_connected()
|
84
|
+
self._cyobj.cancel()
|
85
|
+
|
86
|
+
@property
|
87
|
+
def autocommit(self):
|
88
|
+
self._verify_connected()
|
89
|
+
return self._cyobj.autocommit
|
90
|
+
|
91
|
+
@autocommit.setter
|
92
|
+
def autocommit(self, value):
|
93
|
+
self._verify_connected()
|
94
|
+
self._cyobj.autocommit = value
|
95
|
+
|
96
|
+
@property
|
97
|
+
def dsn(self):
|
98
|
+
self._verify_connected()
|
99
|
+
return self._cyobj.dsn
|
100
|
+
|
101
|
+
@property
|
102
|
+
def inputtypehandler(self):
|
103
|
+
self._verify_connected()
|
104
|
+
return self._cyobj.inputtypehandler
|
105
|
+
|
106
|
+
@inputtypehandler.setter
|
107
|
+
def inputtypehandler(self, value):
|
108
|
+
self._verify_connected()
|
109
|
+
self._cyobj.inputtypehandler = value
|
110
|
+
|
111
|
+
|
112
|
+
@property
|
113
|
+
def outputtypehandler(self):
|
114
|
+
self._verify_connected()
|
115
|
+
return self._cyobj.outputtypehandler
|
116
|
+
|
117
|
+
@outputtypehandler.setter
|
118
|
+
def outputtypehandler(self, value):
|
119
|
+
self._verify_connected()
|
120
|
+
self._cyobj.outputtypehandler = value
|
121
|
+
|
122
|
+
@property
|
123
|
+
def transaction_in_progress(self):
|
124
|
+
self._verify_connected()
|
125
|
+
return self._cyobj.get_transaction_in_progress()
|
126
|
+
|
127
|
+
@property
|
128
|
+
def username(self):
|
129
|
+
self._verify_connected()
|
130
|
+
return self._cyobj.username
|
131
|
+
|
132
|
+
@property
|
133
|
+
def version(self):
|
134
|
+
if self._version is None:
|
135
|
+
self._verify_connected()
|
136
|
+
self._version = ".".join(str(c) for c in self._cyobj.server_version)
|
137
|
+
return self._version
|
138
|
+
|
139
|
+
@property
|
140
|
+
def warning(self):
|
141
|
+
self._verify_connected()
|
142
|
+
return self._cyobj.warning
|
143
|
+
|
144
|
+
|
145
|
+
def connect(dsn, user, password):
|
146
|
+
"""
|
147
|
+
创建数据库连接,并返回连接对象
|
148
|
+
"""
|
149
|
+
if len(dsn) == 0 or len(user) == 0 or len(password) == 0:
|
150
|
+
raise errors.raise_error(errors.ERR_INVALID_CONNECT_PARAMS)
|
151
|
+
if isinstance(dsn, unicode):
|
152
|
+
dsn = dsn.encode("utf-8")
|
153
|
+
if isinstance(user, unicode):
|
154
|
+
user = user.encode("utf-8")
|
155
|
+
if isinstance(password, unicode):
|
156
|
+
password = password.encode("utf-8")
|
157
|
+
return Connection(dsn=dsn, user=user, password=password)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
"""
|
4
|
+
Database API functions
|
5
|
+
"""
|
6
|
+
import datetime
|
7
|
+
from . import errors
|
8
|
+
|
9
|
+
|
10
|
+
def Date(year, month, day):
|
11
|
+
return datetime.date(year, month, day)
|
12
|
+
|
13
|
+
def Time(hour, minute, second):
|
14
|
+
errors.raise_error(errors.ERR_TIME_NOT_SUPPORTED)
|
15
|
+
|
16
|
+
def Timestamp(year, month, day, hour, minute, second):
|
17
|
+
return datetime.datetime(year, month, day, hour, minute, second)
|
18
|
+
|
19
|
+
def DateFromTicks(ticks):
|
20
|
+
return datetime.date.fromtimestamp(ticks)
|
21
|
+
|
22
|
+
|
23
|
+
def TimeFromTicks(ticks):
|
24
|
+
errors.raise_error(errors.ERR_TIME_NOT_SUPPORTED)
|
25
|
+
|
26
|
+
|
27
|
+
def TimestampFromTicks(ticks):
|
28
|
+
return datetime.datetime.fromtimestamp(ticks)
|
29
|
+
|
30
|
+
|
31
|
+
def Binary(value):
|
32
|
+
if isinstance(value, unicode):
|
33
|
+
return value.encode('utf-8')
|
34
|
+
return bytes(value)
|