Reputation: 49
I am trying to return 4 up to 100 rows from ladon/python but it is only returning the first row in the for loop. Currently it returns
EDIT: The For loop works if I just do
**for row in cursor:
RSOID = row.RSO_ID
ALIAS=row.ALIAS
Qty=row.QTY
print(RSOID)
print(ALIAS)
print(Qty)**
ItemNum-1234-ItemNum
Quant-1-Quant
RSOID-1-RSOID
Here is my code:
class OrderLookUpResponse(LadonType):
RSOID = str
ItemNum = str
Quant = str
@ladonize(str,rtype=OrderLookUpResponse)
def LookupOrder(self,OrderID):
cursor.execute("SELECT ALIAS,QTY,RSO_ID FROM RSK_DETAIL WHERE RSO_ID IN(SELECT RSO_ID FROM RSK_ORDER WHERE ACCT_CODE = 'SCRUBBED')")
rows=cursor.fetchall()
for row in rows:
RSOID = row.RSO_ID
ALIAS=row.ALIAS
Qty=row.QTY
result = OrderLookUpResponse()
result.RSOID=RSOID
result.ItemNum=ALIAS
result.Quant=Qty
return result
Upvotes: 0
Views: 56
Reputation: 2677
You have the return inside the for loop. As a result the function will exit during the first loop and thus you will get only the first result. My advice : remove the extra tabs before the command "return".
You should consider appending to a list all the results:
from ladon.ladonizer import ladonize
from ladon.types.ladontype import LadonType
class OrderLookUpResponse(LadonType):
RSOID = str
ItemNum = str
Quant = str
@ladonize(str,rtype=[OrderLookUpResponse])
def LookupOrder(self,OrderID):
results=[]
cursor.execute("SELECT ALIAS,QTY,RSO_ID FROM RSK_DETAIL WHERE RSO_ID IN(SELECT RSO_ID FROM RSK_ORDER WHERE ACCT_CODE = 'SCRUBBED')")
rows=cursor.fetchall()
for row in rows:
RSOID = row.RSO_ID
ALIAS=row.ALIAS
Qty=row.QTY
result = OrderLookUpResponse()
result.RSOID=RSOID
result.ItemNum=ALIAS
result.Quant=Qty
results.append(result)
return results
Summary of changes (in order to be easier to follow):
1) added tabs to class 'OrderLookUpResponse' body
2) removed one tab before return.
3) added a list called "results"
4) changed rtype=OrderLookUpResponse to rtype=[OrderLookUpResponse]
Upvotes: 1
Reputation: 45
You may be running into a problem because the for
loop is iterating over the value cursor.fetchall()
. That is why your code stops after the first line. If you change your rows
value into a list, (e.g []
) this should help.
Upvotes: 0