为了方便调试,我将PyPB关于pb的核心代码部分提取出来放到pbcore模块,当前支持版本是pbvm90
数据库基本操作
import pbcore.plus as pb
def main():
_db = pb.Transaction()
# 或者直接使用 pb.sqlca
_db.dbms = "MSS Microsoft SQL Server 6.x"
_db.servername = "127.0.0.1,8829"
_db.database = "hive"
_db.logid = "sa"
_db.logpass = "593106"
err = _db.connect()
if err != '':
raise Exception("数据库连接失败..", err)
with pb.Trans(_db, messagebox=pb.messagebox) as t:
# 创建表,循环插入数据 更新某个指定数据
_db.execSql("if object_id('t_tab') is not null create table t_tab(t_id varchar(10),name varchar(255))")
for i in range(1000):
_db.execSql("insert into t_tab(t_id,name) values ('{}','{}')".format(i,"nnn"))
_db.execSql("update t_tab set name='111' where t_id = 1")
# 查整个表的数据
print("返回值", _db.selectStr("select * from t_tab",column=["t_id","name"]) )
with pb.Trans(_db, messagebox=pb.messagebox) as t:
# 删除表的所有数据
_db.execSql("delete t_tab")
pb.RUN(__name__,__file__,main)