import time
from . import GBaseLogger
global GBASELOGGER
from GBaseConnector.GBaseCursor import GBaseCursor
from GBaseConnector.GBaseSocket import GBaseSocket
from GBaseConnector.GBaseProtocol import GBaseProtocol
from GBaseConnector.GBaseConstants import (ClientFlag, ServerCmd, flag_is_set,
ServerFlag, CharacterSet)
from GBaseConnector import GBaseError
class GBaseConnection(object):
'''
************************************************************
Module : GBaseConnection
Function : Create connection to GBase server
Corporation : General Data Technology CO,. Ltd.
Team : DMD, Interface Team
Author : wq
Date : 2013-7
Version : v1.0
Description : Create connection to GBase server. And execute
SQL and fetch rows.
************************************************************
'''
def __init__(self, **kwargs):
'''
************************************************************
Function : __init__
Arguments : 1) **kwargs (dict) : connection arguments
{ 'user': gbase,
'port': 5258 }
Return :
Description : GBaseConnection construct function
************************************************************
'''
self._host = '127.0.0.1'
self._user = ''
self._password = ''
self._database = ''
self._port = 5258
self.charset = None
self._use_unicode = True
self._collation = None
self._connection_timeout = 30
self._autocommit = True
self._time_zone = None
self._sql_mode = None
self._get_warnings = False
self._raise_on_warnings = False
self._client_flags = ClientFlag.get_default()
self._charset_id = 33 # utf8
self._socket = None
self._protocol = None
self._hello_res = None
self._server_version = None
self._have_next_result = False
self._unread_result = False
# Initial log system
GBaseLogger.InitLog(**kwargs)
if len(kwargs) > 0:
self.connect(**kwargs)
def parsecfg(self, **kwargs):
'''
************************************************************
Function : parsecfg
Arguments : 1) **kwargs (dict) : connection arguments
{ 'user': gbase,
'port': 5258 }
Return :
Description : Parse config arguments and get values.
************************************************************
'''
GBASELOGGER.debug('Enter: parsecfg')
config = kwargs.copy()
# dsn
if 'dsn' in config:
GBASELOGGER.error('Not support dsn key word.')
raise GBaseError.NotSupportedError('Not support dsn key word.')
# host
if 'host' in config:
if config['host'] != None and len(config['host']) > 0: # Bug #2857
self._host = config['host']
del config['host']
# user
if 'user' in config:
self._user = config['user']
del config['user']
# Compatible other key
compatible_keys = [
('db', 'database'),
('passwd', 'password'),
('connect_timeout', 'connection_timeout'),
]
for comp_key, full_key in compatible_keys:
try:
if full_key not in config:
config[full_key] = config[comp_key]
del config[comp_key]
except KeyError:
pass # Missing compat argument is OK
# password
if 'password' in config:
self._password = config['password']
del config['password']
# port
if 'port' in config:
try:
self._port = int(config['port'])
del config['port']
except KeyError:
pass # Missing port argument is OK
except ValueError:
raise ValueError(
"TCP/IP port number should be an integer")
if 'connection_timeout' in config:
self.connection_timeout = config['connection_timeout']
del config['connection_timeout']
if 'autocommit' in config:
self._autocommit = config['autocommit']
del config['autocommit']
if 'sql_mode' in config:
self.sql_mode = config['sql_mode']
del config['sql_mode']
if 'get_warnings' in config:
self.get_warnings = config['get_warnings']
del config['get_warnings']
# Configure client flags
try:
default = ClientFlag.get_default()
self.set_client_flags(config['client_flags'] or default)
del config['client_flags']
except KeyError:
pass # Missing client_flags-argument is OK
# Configure character set and collation
if ('charset' in config or 'collation' in config):
try:
self.charset = config['charset']
del config['charset']
except KeyError:
self.charset = None
try:
collation = config['collation']
del config['collation']
except KeyError:
collation = None
self._charset_id = CharacterSet.get_charset_info(self.charset, collation)[0]
if 'raise_on_warnings' in config:
self.raise_on_warnings = config['raise_on_warnings']
del config['raise_on_warnings']
if 'use_unicode' in config:
self.use_unicode = config["use_unicode"]
del config['use_unicode']
# Other configuration
for k, v in list(config.items()):
# TRACE Configuration
if k.startswith('trace'):
continue
try:
self.DEFAULT_CONFIG[k]
except KeyError:
raise AttributeError("The argument is not support. '%s'" % k)
attribute = '_' + k
try:
setattr(self, attribute, v.strip())
except AttributeError:
setattr(self, attribute, v)
GBASELOGGER.debug('Exit: parsecfg')
@property
def port(self):
'''
************************************************************
Function : port
Arguments :
Return : int
Description : Return current port.
************************************************************
'''
return self._port
@property
def user(self):
'''
************************************************************
Function : user
Arguments :
Return : string
Description : Return current user.
************************************************************
'''
return self._user
@property
def host(self):
'''
************************************************************
Function : host
Arguments :
Return : string
Description : Return current
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共16个文件
py:14个
readme:1个
pkg-info:1个
python 连接Gbase8a 的驱动程序, 资源比较稀缺; 安装步骤: tar -zxvf gbase-connector-python-3.0.1.tar.gz -C /usr/local/src/ cd /usr/local/src/gbase-connector-python-3.0.1 python3 setup.py install from GBaseConnector import connect, GBaseError config = {'host': '192.168.195.128', 'user': 'root', 'passwd': 'root', 'port': 5258, 'db': 'gbase'} try: conn = connect() conn.connect(**config) cur = conn.cursor() cur.execute("SELECT TABLE_NAME, ENGINE,TABLE_ROWS FROM
资源推荐
资源详情
资源评论
收起资源包目录
gbase-connector-python-3.0.1.tar.gz (16个子文件)
gbase-connector-python-3.0.1
README 213B
GBaseConnector
__init__.py 265B
GBaseConstants.py 24KB
GBaseCursor.py 32KB
errmsg
__init__.py 1KB
eng
__init__.py 1B
client_errmsg.py 5KB
GBaseError.py 6KB
GBaseErrorCode.py 30KB
GBaseUtils.py 16KB
GBaseConnection.py 51KB
GBaseSocket.py 9KB
GBaseProtocol.py 15KB
GBaseLogger.py 15KB
setup.py 1KB
PKG-INFO 383B
共 16 条
- 1
资源评论
- 魏水华2023-07-25尽管这个文件没有深入探讨这个驱动的高级用法,但它提供了足够的基础知识,让人能够开始使用和探索gbase8a数据库的潜力。
- 傅融2023-07-25这个文件解释了Python在与gbase8a的交互方面的一些关键概念,让人容易理解和上手。
- 高工-老罗2023-07-25这个文件提供了很实用的关于Python与gbase8a的驱动的信息,对于需要使用这个驱动的人来说是一个很好的参考。
- 奔跑的楠子2023-07-25作者对于gbase8a驱动的用法进行了详细的介绍,让人在使用中能够尽快解决问题,避免了一些常见的错误。
- 練心2023-07-25对于那些想要学习如何使用Python与gbase8a进行数据操作的人来说,这个文件是一个很好的起点,内容简洁明了。
敬天爱人小白
- 粉丝: 7
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功