[Finally reviewing some older postings]
On 7/2/11 5:20 AM, Ed Leafe wrote:
> If you have some custom SQL that needs to be executed for specific
> tasks, normally you would use the bizobj's executeSafe() method, passing in
> the desired SQL
Here's my approach to this problem, which is fundamentally the same but I like
the
syntax better:
{{{
class MyBizobj(...):
...
def getCustomerStatus(self):
sql = """
select status
from customers
where customers.id = ?"""
cur = self.getTempCursor(sql, (self.Record.customer_id,))
return cur.Record.status
}}}
If there weren't any customers that matched the customer id, that's exceptional
and
will thus raise dabo.NoRecordsException. If in your case you want to swallow
it, just
wrap it in a try/except:
{{{
try:
return cur.Record.status
except dabo.NoRecordsException:
return None
}}}
Note the "?" in the sql will get converted to whatever the
parameter-placeholder
character is on whatever backend database you are using, by Dabo, so standard
sql
written here using "?" as the placeholder will work on any backend. My app must
currently run on MySQL and SQLite, but using this technique I don't have to
manage
two codebases.
Paul
_______________________________________________
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]