Ai
1 Star 0 Fork 0

opengauss_sharding/pipeline_script

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test_psycopg2.py 1.14 KB
一键复制 编辑 原始数据 按行查看 历史
周斌 提交于 2023-11-13 11:31 +08:00 . add orm
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
description: please input using description
author: justbk
date: 2022/7/26
modify_records:
- 2022/7/26 justbk create this file
"""
import os
import sys
PSYCOPG2_ROOT = '/home/zhoubin/code/openGauss-connector-python-psycopg2/output/'
sys.path.insert(0, PSYCOPG2_ROOT)
import psycopg2
connector_args = {
'database': 'postgres',
'user': 'test',
'password': 'Zhoubin@123',
'host': '20.20.20.52',
'port': '10101'
}
tinyint_type = psycopg2.extensions.new_type((5545,), 'tinyint', lambda s, conn_or_curs: int(s))
psycopg2.extensions.register_type(tinyint_type, None)
def test_connect():
conn = None
try:
conn = psycopg2.connect(**connector_args)
curs = conn.cursor()
curs.execute('drop table if exists t1;')
curs.execute('create table t1(col tinyint);')
curs.execute('insert into t1 values (%s);', (255,))
curs.execute('select * from t1;')
x = curs.fetchone()
print(type(x[0]), x)
except Exception as exp:
print('print error:%s'%(exp))
finally:
if conn is not None:
conn.close()
test_connect()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/opengauss_sharding/pipeline_script.git
git@gitee.com:opengauss_sharding/pipeline_script.git
opengauss_sharding
pipeline_script
pipeline_script
master

搜索帮助