Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 20D212E0032 for ; Sun, 27 Apr 2008 16:23:47 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 82662-10 for ; Sun, 27 Apr 2008 16:23:40 -0300 (ADT) X-Greylist: delayed 01:00:00.868007 by SQLgrey-1.7.5 Received: from vms044pub.verizon.net (vms044pub.verizon.net [206.46.252.44]) by developer.postgresql.org (Postfix) with ESMTP id 211272E005D for ; Sun, 27 Apr 2008 16:23:44 -0300 (ADT) Received: from [192.168.2.5] ([71.180.197.65]) by vms044.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0JZZ0070KXR97EO4@vms044.mailsrvcs.net> for pgsql-sql@postgresql.org; Sun, 27 Apr 2008 13:23:34 -0500 (CDT) Date: Sun, 27 Apr 2008 14:25:06 -0400 From: Joe Subject: Re: Protection from SQL injection In-reply-to: <20080427191840.494b6bf7@dawn.webthatworks.it> To: Ivan Sergio Borgonovo Cc: pgsql-sql@postgresql.org Message-id: <4814C502.7070604@freedomcircle.net> MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII; format=flowed Content-transfer-encoding: 7bit References: <5f211bd50804260932l7a63618jca64858271ff269f@mail.gmail.com> <13670.1209267734@sss.pgh.pa.us> <20080427123848.5c841788@dawn.webthatworks.it> <20080427142253.449de600@dawn.webthatworks.it> <4814A1E6.1070200@freedomcircle.net> <20080427191840.494b6bf7@dawn.webthatworks.it> User-Agent: Mozilla-Thunderbird 2.0.0.9 (X11/20080110) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/206 X-Sequence-Number: 30745 Ivan Sergio Borgonovo wrote: > That's better than nothing but it is still a lot of code duplication. > You've to write column names in the sql statement and in the array > and... column values are not contextual to the statement. > The apparent duplication in the example stems for its tutorial nature. In a real program, the namedict "array" (it's actually a Python tuple--an immutable array) would normally be constructed programmatically from user or other input. Note also that although Joshua chose to use dictionary keys named identical to the PG column names, they could be named differently, like "first" and "last". > That's easy... while what I wrote above does look as requiring a > really special parser. > > Furthermore from the example it looks as if all this is going to > miss the scope to prevent sql injection since it doesn't support > prepared statements. > I assume you didn't check the PEP 249 (http://www.python.org/dev/peps/pep-0249/). The execute() and executemany() Cursor object methods are precisely to prepare and execute database operations. Joe