python文件存储过程_调用存储过程python

我正在编写一个脚本来提取/更新MsSQL服务器,我可以让我的一个存储过程调用工作,但不是我在updateDB函数中的第二个.这是我的代码脚本运行正常没有错误代码

import pyodbc

import json

import argparse

import cgi, cgitb

#GLOBALS

BUILDCODE = " "

deptCODE = 0

bldgCODE = " "

def getCodes(conn, building, department):

#just for testing

departmentt = 'COMPUTER SCIENCE'

buildingt = 'PEARCE HALL'

#geting the building code from db

cursorBuild = conn.cursor()

cursorBuild.execute("select * from dbo.building where name = '%s'" % buildingt)

bldgRow = cursorBuild.fetchall()

cursorBuild.close()

bldgCode = bldgRow.pop(0)

global bldgCODE

bldgCODE = bldgCode.code

#getting the dept code

cursorDept = conn.cursor()

cursorDept.execute("execute dbo.GetCode_ByDepartment @department = '%s'" % departmentt)

deptRow = cursorDept.fetchall()

cursorDept.close()

deptCode = deptRow.pop(0)

global deptCODE

deptCODE = deptCode.code

print type(deptCODE)

print deptCODE

#returning the values

return (bldgCode, deptCode)

def updateDB(conn, tag, room, updater):

#updating the database

updateCursor = conn.cursor()

print deptCODE

print bldgCODE

#this will pass params just has them hard codded for testing

conn.execute("exec dbo.UpdateCheck_In @room = '400', @building = 'PE', @department = 307, @global_id = 'bacon', @tag = '120420'")

if __name__ == "__main__":

#connectin to the db with SQL Authentification

conn = pyodbc.connect(driver = '{SQL Server}', server = '(local)',

database = 'Inventory', uid = 'sa', pwd = 'p@$$w0rd123')

#checking to see if you connected to the db or not

if (conn == False):

print "Error, did not connect to the database"

else:

#NEEDS THIS cgitb.enable

cgitb.enable()

# Create instance of FieldStorage

form = cgi.FieldStorage()

#get the data from the url that called it

tag = form.getvalue('tagnum')

building = form.getvalue('build')

roomNum = form.getvalue('room')

department = form.getvalue('dept')

updater = form.getvalue('update')

#check to see if item is in the db

itemIsThere = conn.cursor()

itemIsThere.execute("select * from dbo.check_in where tag = '120420';")

print itemIsThere

itemIsThere.close()

#if the item in in the inventory

if (itemIsThere != None):

#getting the codes

getCodes(conn, building, department)

#calling the update function

updateDB(conn, tag, roomNum, updater)

else :

pass

conn.close()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值