On Sep 26, 2010, at 9:30 AM, Jim Byrnes wrote:
> I need to detect the results of a UserSQL query for further processing.
> I can see in the status bar of the form if 1 or 0 records was returned
> but I can't figure out how to detect that in my code.
>
> In a buttons onHit I do: namesBiz = self.Form.getBizobj('names')
> phonenum = self.Form.phoneTB.Value
> phonenumCheck = namesBiz.checkPhoneNum(phonenum)
> self.Form.requery(dataSource = 'names')
>
> Then: def checkPhoneNum(self, phonenum) :
> """ Query phone number to see if it is already in the db """
> self.UserSQL = """select * from names
> where phone_num = '%s'""" % phonenum
>
> 'names' is not the primary bizObj. I am using it to work with an
> another table in the db.
Generally it's not a good idea to run ad-hoc queries against your
bizobj, as that will delete the data set, and probably mess up some of your
data bindings. If you need to do something like you describe above, it's much
better to use the 'executeSafe()' method of the bizobj.
executeSafe() takes SQL and runs it with a separate auxilliary cursor,
so that the results don't overwrite the bizobj's main data. It returns the
cursor, which you can then inspect to see the returned values. Here's a rewrite
of your check method:
def checkPhoneNum(self, phonenum) :
""" Query phone number to see if it is already in the db """
testSQL = """select * from names
where phone_num = %s"""
crs = self.executeSafe(sql, (phonenum, ))
isDupe = (crs.RowCount > 0)
-- Ed Leafe
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message:
http://leafe.com/archives/byMID/[email protected]