[Baypiggies] Discussion for newbies/beginner night talks

Chad Netzer chad.netzer at gmail.com
Sat Feb 10 02:43:00 CET 2007


n 2/9/07, Dennis Reinhardt <DennisR at dair.com> wrote:
>
> To preserve SQL *and* Python structuring, I would write this as:
>
> class MyBizobj(...):
>      def getCustomerInfo(self, cust_id):
>         sql  = ""
>         sql += "select customers.name as name,\r\n"
>         sql += "        sum(invoices.amount) as amount_total,\r\n"
>         sql += "        blah as blah\r\n"
>         sql += "   from customers\r\n"
>         sql += "   left join invoices\r\n"
>         sql += "     on invoices.cust_id = customers.id\r\n"
>         sql += "  where customers.id = ?\r\n"
>          self.cur.execute(sql, (cust_id,))

Another alternative (which does the concatenation at compile time) is:

class MyBizobj(...):
    def getCustomerInfo(self, cust_id):
        sql  = (
            "select customers.name as name,\r\n"
            "        sum(invoices.amount) as amount_total,\r\n"
            "        blah as blah\r\n"
            "   from customers\r\n"
            "   etc..."
        )

Chad


More information about the Baypiggies mailing list