pyodbc是否会对数据库造成影响
用pyodbc 执行更新语句的时候发现,如果不commit(),然后去查数据库这个表,一直查不出来,是不是数据库的表被锁了。
大神能不能帮我看看下面
求大神帮忙看看这个代码是不是会有问题,主要是会不会有执行到update而不commit()的可能。谢谢,谢谢。
大神能不能帮我看看下面
def hz_channelorder():
showbill_hz.delete(1.0,"end")
#正式库
conn=pyodbc.connect(r'DRIVER={SQL Server Native Client 10.0};SERVER=localhost;DATABASE=KFT;UID=test;PWD=test##')
#测试库
#conn=pyodbc.connect(r'DRIVER={SQL Server Native Client 10.0};SERVER=localhost;DATABASE=KFT_TEST;UID=md;PWD=123')
cur=conn.cursor()
#获取输入值
cd=str(t_hz.get("1.0","end"))
cd=cd.strip()
if (cd==''):
mes.showerror("贴心小提示","未输入单号")
else:
billnos=re.findall(r'\w{2}\d{6}-\d{4}',cd)
#print(billno)
for billno in billnos:
type=billno[0:2]
if (type=='KH'):
select_sql="select billstate from kft_applynew where billno='%s'"%(str(billno))
elif (type=='WX'):
select_sql="select billstate from kft_repair where billno='%s'"%(str(billno))
else:
select_sql="select billstate from kft_exchange where billno='%s'"%(str(billno))
#print(select_sql)
cur.execute(select_sql)
test=cur.fetchone()
if (test is None):
info="%s单据在系统未找到,请检查单据是否输入错误"%(str(billno))
hz_print_info(info)
save_log(info)
else:
billstate=str(test[0])
#if (billstate=='150' or billstate=='330' or billstate=='430' or billstate=='130'):
if (billstate in ('150','130','330','430','-100','140','-300','-400')):
#可能会中断循环操作
#mes.showerror("拒绝操作","%s单据是已完成或已撤单状态,无法撤单"%(str(billno)))
info="%s单据是已完成或已撤单状态,无法撤单"%(str(billno))
hz_print_info(info)
save_log(info)
else:
update_sql="exec cd '%s'"%(str(billno))
#print(update_sql)
cur.execute(update_sql)
conn.commit()
info="%s单据已撤单"%(str(billno))
hz_print_info(info)
save_log(info)
cur.close()
conn.close()这段代码有没有问题。最后执行的update_sql是个存储过程,代码如下:CREATE procedure cd(@billno varchar(50))
as
begin
declare @type varchar(20),@table varchar(50),@sql nvarchar(max),@billstate varchar(50)
set @type=left(@billno,2)
if @type='TJ' or @type='HJ' or @type='YJ' or @type='TH'
begin
set @table='kft_exchange'
set @billstate='-400'
end
else if @type='WX'
begin
set @table='kft_repair'
set @billstate='-300'
end
else if @type='KH'
begin
set @table='kft_applynew'
set @billstate='-100'
update KFT_AccountCards set IsOpen=0,OpenDate=null where CardCode in (select CardCode from kft_applynew where BillNo=@billno)
end
else
begin
print 'error:单号输入错误'
end
set @sql='update '+@table+' set billstate='+@billstate+' where billno='''+@billno+''''
exec sp_executesql @sql
end求大神帮忙看看这个代码是不是会有问题,主要是会不会有执行到update而不commit()的可能。谢谢,谢谢。
...全文
相关推荐
安装包-pyodbc-4.0.1-cp27-cp27m-win32.whl.zip
因此,开发者在开发过程中需要对pyodbc进行管理时,需要特别注意其版本与操作系统环境是否匹配。在数据库编程实践中,使用pyodbc可以方便地构建数据库连接、执行SQL语句、处理结果集以及管理事务。
安装包-pyodbc-4.0.11-cp36-cp36m-win32.whl.zip
通过pyodbc,开发人员可以使用标准的Python DB API 2.0接口与数据库进行交互。使用pyodbc库可以方便地执行SQL语句、进行事务处理、管理数据库连接等。
python连接sqlserver数据库自己写的盲注sqlserver的python脚本。
threads.append(t) t.start()# 等待所有线程完成for t in threads: t.join()```盲注SQL Server是指在没有返回完整结果的情况下,通过判断查询是否影响了数据库的状态
dmPython.zip
**连接DM7**:安装完成后,你可以通过以下代码测试dmPython是否成功连接到DM7数据库: ```python import pyodbc conn_str = ( 'DRIVER={dmPython
城市经纬度数据库(mdb和xls两个版本)
数据完整性:检查所有城市和地区是否都有完整无误的坐标,避免缺失或错误的数据影响分析结果。3.


