12345678910111213141516171819202122232425262728293031323334353637383940 |
- from django.db import connection, transaction
- '''执行django原始sql语句 并返回一个数组对象'''
- # b = 'MO1505000001'
- # sql = ("SELECT TOP 5 MO_NO FROM MF_MO WHERE MO_NO='%s'"%(b))
- # print(sql)
- #
- # b1 = 1
- # sql1 = ("SELECT TOP 5 MO_NO FROM MF_MO WHERE MO_NO=%d"%(b1))
- # print(sql1)
- def executeQuery(sql):
- """"
- sql:sql语句
- """
- with connection.cursor() as cursor:
- print(sql)
- dep_data = cursor.execute(sql, []).fetchall()
- col_names = [desc[0] for desc in cursor.description]
- result = []
- for row in dep_data:
- objDict = {}
- # 把每一行的数据遍历出来放到Dict中
- for index, value in enumerate(row):
- objDict[col_names[index]] = value
- result.append(objDict)
- return result
- def IseUpDelQuery(sql):
- """"
- sql:要执行增加删除的sql语句
- """
- with connection.cursor() as cursor:
- cursor.execute(sql)
- def rpoold(sql):
- """用于判断单号是否重复"""
- with connection.cursor() as cursor:
- data = cursor.execute(sql, []).fetchall()[0][0]
- return data
|