在我看來,我調用了一個存儲過程,該存儲過程返回了它創建的條目的ID。如何使用python解析(小數('str'),)
我需要使用此ID作爲另一個存儲過程的參數。
我的問題是,第一個查詢的結果是:(十進制('1046')),當然不適合作爲第二個過程的參數。
我該如何解析它才能得到'1046'?
編輯:
View.py:Python中
def dictfetchall(cursor):
columns = [col[0] for col in cursor.description]
return [
dict(zip(columns, row))
for row in cursor.fetchall()
]
def mouvementCreation(request):
idMI = 0
especes = TbEspece.objects.order_by('id')
#Get Mouvement informations
#Connection to 'erp-site' DB
cursor = connections['erp-site'].cursor()
try:
#Get Produits list from Espece
query = "{CALL SP_webGET_PRODUIT_FROM_ESPECE(%s,%s,%s,%s,%s)}"
arguments = (2016, 'C', 0, 10, 'A',)
cursor.execute(query, arguments)
produits = dictfetchall(cursor)
#Get Transporters list
cursor.execute("{CALL SP_webGET_TRANSPORT}")
transporters = dictfetchall(cursor)
#Get Livreur list
cursor.execute("{CALL SP_webGET_LIVREUR}")
livreurs = dictfetchall(cursor)
finally:
cursor.close()
cursor = connections['site'].cursor()
try:
#Get Circuit list
cursor.execute("{CALL SP_webGET_CIRCUIT_FOR_MVT}")
circuits = dictfetchall(cursor)
#Get Source list
cursor.execute("{CALL SP_webGET_SOURCE_FOR_MVT}")
mvtsources = dictfetchall(cursor)
#Get Dest list
cursor.execute("{CALL SP_webGET_DEST_FOR_MVT}")
destinations = dictfetchall(cursor)
#Get PontBascule list
cursor.execute("{CALL SP_webGET_PBASCULE}")
pontBascules = dictfetchall(cursor)
finally:
cursor.close()
reg_normes = TbRegauxnormes.objects.all()
ordreexecs = TbOrdreexecution.objects.all()
if request.method == 'POST':
typemouvement = request.POST.get('typemouvement')
soustype = request.POST.get('soustype')
recolte = request.POST.get('recolte')
groupe = request.POST.get('groupe')
categorie = request.POST.get('categorie')
code = request.POST.get('code')
collecte = request.POST.get('collecte')
vente = request.POST.get('vente')
stock = request.POST.get('stock')
achat = request.POST.get('achat')
transporteur = request.POST.get('transporteur')
blLivreur = request.POST.get('blLivreur', '')
contratClient = request.POST.get('contratClient')
pont1 = request.POST.get('pont1') # BIGINT
numTicket = request.POST.get('numTicket') # INT
dateheure1 = request.POST.get('dateheure1') # DATETIME
poid1 = request.POST.get('poid1') # INT
dsd1 = request.POST.get('dsd1') # INT
pont2 = request.POST.get('pont2') # BIGINT
dateheure2 = request.POST.get('dateheure2') # DATETIME
poid2 = request.POST.get('poid2') # INT
dsd2 = request.POST.get('dsd2') # INT
p1p2 = request.POST.get('p1p2') # INT
livreur = request.POST.get('idlivreur') # BIGINT
vehicule = request.POST.get('vehicule') # VARCHAR
comTicket = request.POST.get('comTicket') # VARCHAR
comLogiciel = request.POST.get('comLogiciel') # VARCHAR
espece = request.POST.get('espece') # BIGINT
produit = request.POST.get('produit') # BIGINT
#Connection to 'erp-site' DB
cursor = connections['pontbascule'].cursor()
try:
query = "{CALL SP_webADD_MANUAL_PESEE(%s,%s,%s,%s,%s, %s,%s,%s,%s,%s, %s,%s,%s,%s,%s,%s,%s)}"
arguments = (pont1, numTicket, dateheure1, poid1, dsd1,pont2, numTicket, dateheure2, poid2, dsd2, p1p2,livreur, vehicule,comTicket, comLogiciel,espece, produit)
cursor.execute(query, arguments)
#Here i recieve the (Decimal('1046'),)
s = cursor.fetchone()
idCreatedPesee = s[0]
finally:
cursor.close()
cursor = connections['site'].cursor()
try:
#Here im supposed to send it as argument to this procedure
query = "{CALL SP_webCREATE_MVT_INIT(%s)}"
arguments = (idCreatedPesee)
cursor.execute(query, arguments)
idCreatedMVT = dictfetchall(cursor)
finally:
cursor.close()
return render(request, 'mouvementCreation.html', {'especes' : especes, 'produits' : produits, 'transporters' : transporters, 'livreurs' : livreurs, 'circuits' : circuits, 'mvtsources' : mvtsources, 'destinations' : destinations, 'pontBascules' : pontBascules})
你能給我們你的實際代碼嗎?我們不知道什麼'Decimal'意思是 – HyperNeutrino
@HyperNeutrino:它在標準庫中... https://docs.python.org/3/library/decimal.html – RemcoGerlich
@RemcoGerlich哦哎呦我的壞xD – HyperNeutrino