PYODBC Множественные курсоры
Надеюсь, у тебя все хорошо
Я пишу приложение django на py3.9.1 и хочу выполнить несколько курсоров на сервере mssql.
Вот мое подключение к базе данных mssql
conn = pypyodbc.connect("....")
cursor = conn.cursor()
cursor1 = conn.cursor()
Вот мой views.py
@login_required(login_url="user:login")
@allowed_users(allowed_permissions=["Management Perm","Boss Perm","Account Perm"])
def bills(request):
keyword = request.GET.get("keyword")
header = "Faturalar | Mavis Development"
company = UserCompany.objects.filter(user = request.user).values_list("company__company",flat=True)[0]
role = request.user.groups.all()[0].name
if keyword:
bills_for_acc = cursor.execute("Select * From bills where mancheck = 0 and acccheck = 0 and company = ? and title = ? order by created_date",(company,keyword,))
bills_for_man = cursor1.execute("Select * From bills where mancheck = 0 and acccheck = 1 and company = ? and title = ? order by last_checked_date",(company,keyword))
content = {
"bills_for_man":bills_for_man,
"bills_for_acc":bills_for_acc,
"header":header,
"role":role,
}
return render(request,"bills.html",content)
bills_for_acc = cursor.execute("Select * From bills where (acccheck = 0 and mancheck = 0) and company = ? order by created_date",(company,))
bills_for_man = cursor1.execute("Select * From bills where (mancheck = 0 and acccheck = 1) and company = ? order by last_checked_date",(company,))
content = {
"bills_for_man":bills_for_man,
"bills_for_acc":bills_for_acc,
"header":header,
"role":role,
}
return render(request,"bills.html",content)
Когда я пытаюсь показать bills.html, я получаю '('HY000', '[HY000] [Microsoft][ODBC SQL Server Driver]'Connection is busy with results for another hstmt'')
С другой стороны, когда я выполняю 2 разных оператора на одном курсоре
bills_for_acc = cursor.execute("Select * From bills where (acccheck = 0 and mancheck = 0) and company = ? order by created_date",(company,))
bills_for_man = cursor.execute("Select * From bills where (mancheck = 0 and acccheck = 1) and company = ? order by last_checked_date",(company,))
Результат этих переменных будет одинаковым
Мой вопрос в том, как я могу выполнить несколько курсоров