Hy can you help me what i do wrong?
I want compare two strings one sting is from SQL query and second string from textfield.
My code doesn’t work :((
barCode= self.getSibling("barCode").props.text
testName = system.db.runPrepQuery("SELECT name FROM maintenanceWarehouse WHERE name = ?",[name],"Technici")
testBarCode = system.db.runPrepQuery("SELECT barCode FROM maintenanceWarehouse WHERE barCode = ?",[barCode],"Technici")
#insert new data to qurie
if testBarCode[0][0] == barCode :
self.getSibling("Label_2").props.text='duplicita'
else :
self.getSibling("Label_2").props.text=str(testBarCode[0][0])
if it always goes to else and data from query and text are same
Thank you
You can’t use the array format to read your dataset query result, you need to use .getValueAt(0,0)
Unless you convert it to a pydataset with system.dataset.toPyDataSet
psst, runPrepQuery returns a pyDataSet.
Ha, so it does according to the user manual
Add some logging to help your debugging.
Try something like this:
barCode= self.getSibling("barCode").props.text
testName = system.db.runPrepQuery("SELECT name FROM maintenanceWarehouse WHERE name = ?",[name],"Technici")
testBarCode = system.db.runPrepQuery("SELECT barCode FROM maintenanceWarehouse WHERE barCode = ?",[barCode],"Technici")
# send to gateway logs
log = system.util.getLogger('DEBUG')
log.info(str(barCode))
log.info(str(testBarCode[0][0]))
#insert new data to qurie
if testBarCode[0][0] == barCode :
self.getSibling("Label_2").props.text='duplicita'
else :
self.getSibling("Label_2").props.text=str(testBarCode[0][0])
Thank you so much Now is working ok Thanks 
Interesting… I always thought runPrepQuery returned a dataset, and if that worked then maybe the user manual doco is wrong? I’m not at my pc to check anything
It’s always returned a PyDataSet (for me). Not sure how using .getValueAt(0,0) resolved the issue.
Oops, thanks. I updated the script in my other post.
testName = system.db.runPrepQuery("SELECT name FROM maintenanceWarehouse WHERE name = ?",[name],"Technici")
testBarCode = system.db.runPrepQuery("SELECT barCode FROM maintenanceWarehouse WHERE barCode = ?",[barCode],"Technici")
testBarCodeDataSet = system.dataset.toDataSet(testBarCode)
testNameDataSet = system.dataset.toDataSet(testName)
#insert new data to qurie
# send to gateway logs----------------------------------------
log = system.util.getLogger('DEBUG')
log.info(str(barCode))
log.info(str(testBarCodeDataSet.getValueAt(0,0)))
#-------------------------------------------------------
if testBarCodeDataSet.getValueAt(0,0).strip() == barCode.strip() :
self.getSibling("Label_2").props.text='duplicita'
else :
This code work good.
PyDataset implements the Dataset interface, so the getValueAt()
and related functions also work.
1 Like