Re: [Zope] python script + ZSQL
To check if a zsql method has returned a null record set , I use the following method in a python script
px = [] #Declaring an array pset = context.oms.Proj.Task.db.zsqlr_task(id = id1) #Calling the Zsql Method paassing a varible id for c in pset: px = px + [[c[0]]] #Inserting the value of the first field into the array if (px == []): print "No Record" #If the record set has no values It returns an empty array(Here i am just printing a message) else: print px #Else the first field value is printed out
I'd have used # this is the query -- returns a DB object res = container.query( ... ) # convert to a list of tuples (aka rows) res = res.tuples() # test for emptyness ... if( res == []): print "the query returned no rows" else: print 'the query returned " + len(res) " " rows."
participants (1)
-
Dennis Allison