<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Managing a simple database with Python, SQLite and wxPython, 7 (includes a question)</title>
	<atom:link href="http://python.genedrift.org/2009/04/20/managing-a-simple-database-with-python-sqlite-and-wxpython-7-includes-a-question/feed/" rel="self" type="application/rss+xml" />
	<link>http://python.genedrift.org/2009/04/20/managing-a-simple-database-with-python-sqlite-and-wxpython-7-includes-a-question/</link>
	<description>a step-by-step guide to create Python applications in bioinformatics</description>
	<lastBuildDate>Mon, 22 Feb 2010 18:22:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=3.0-alpha</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Paulo Nuin</title>
		<link>http://python.genedrift.org/2009/04/20/managing-a-simple-database-with-python-sqlite-and-wxpython-7-includes-a-question/comment-page-1/#comment-26991</link>
		<dc:creator>Paulo Nuin</dc:creator>
		<pubDate>Wed, 22 Apr 2009 00:57:51 +0000</pubDate>
		<guid isPermaLink="false">http://python.genedrift.org/2009/04/20/managing-a-simple-database-with-python-sqlite-and-wxpython-7-includes-a-question/#comment-26991</guid>
		<description>The suggestion worked really well, thanks a lot. I&#039;m posting the new code after some testing.</description>
		<content:encoded><![CDATA[<p>The suggestion worked really well, thanks a lot. I&#8217;m posting the new code after some testing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paulo Nuin</title>
		<link>http://python.genedrift.org/2009/04/20/managing-a-simple-database-with-python-sqlite-and-wxpython-7-includes-a-question/comment-page-1/#comment-26986</link>
		<dc:creator>Paulo Nuin</dc:creator>
		<pubDate>Tue, 21 Apr 2009 17:23:10 +0000</pubDate>
		<guid isPermaLink="false">http://python.genedrift.org/2009/04/20/managing-a-simple-database-with-python-sqlite-and-wxpython-7-includes-a-question/#comment-26986</guid>
		<description>Adomas, indeed it really looks ugly, and that&#039;s the main reason for my question. :-)

As Richard mentioned, SQLAlchemy would be overkill here. I really like SQLAlchemy, but here we have one database with one table.

Thanks everyone for the suggestions, I&#039;m trying the placeholders now.</description>
		<content:encoded><![CDATA[<p>Adomas, indeed it really looks ugly, and that&#8217;s the main reason for my question. <img src='http://python.genedrift.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>As Richard mentioned, SQLAlchemy would be overkill here. I really like SQLAlchemy, but here we have one database with one table.</p>
<p>Thanks everyone for the suggestions, I&#8217;m trying the placeholders now.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Hall</title>
		<link>http://python.genedrift.org/2009/04/20/managing-a-simple-database-with-python-sqlite-and-wxpython-7-includes-a-question/comment-page-1/#comment-26982</link>
		<dc:creator>Richard Hall</dc:creator>
		<pubDate>Tue, 21 Apr 2009 08:27:15 +0000</pubDate>
		<guid isPermaLink="false">http://python.genedrift.org/2009/04/20/managing-a-simple-database-with-python-sqlite-and-wxpython-7-includes-a-question/#comment-26982</guid>
		<description>I agree with Mike - use named placeholders.  The update statement is then easy to construct using something like

bind = {&#039;foo&#039;:1, &#039;bar&#039;:2}
insert = &#039;,&#039;.join([&#039;%s=:%s&#039;%(y,y) for y in bind])
cu.execute(&#039;update mytable set %s where id=:id&#039;%insert, bind)

this assumes your column names are equivalent to the keys in your dictionary.  Alternatively, google for &#039;object relational mappers&#039; (sqlalchemy is probably the best known mapepr for python) - this is exactly the sort of thing they do well, but might be overkill for your application.</description>
		<content:encoded><![CDATA[<p>I agree with Mike &#8211; use named placeholders.  The update statement is then easy to construct using something like</p>
<p>bind = {&#8216;foo&#8217;:1, &#8216;bar&#8217;:2}<br />
insert = &#8216;,&#8217;.join(['%s=:%s'%(y,y) for y in bind])<br />
cu.execute(&#8216;update mytable set %s where id=:id&#8217;%insert, bind)</p>
<p>this assumes your column names are equivalent to the keys in your dictionary.  Alternatively, google for &#8216;object relational mappers&#8217; (sqlalchemy is probably the best known mapepr for python) &#8211; this is exactly the sort of thing they do well, but might be overkill for your application.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adomas</title>
		<link>http://python.genedrift.org/2009/04/20/managing-a-simple-database-with-python-sqlite-and-wxpython-7-includes-a-question/comment-page-1/#comment-26980</link>
		<dc:creator>Adomas</dc:creator>
		<pubDate>Tue, 21 Apr 2009 07:21:31 +0000</pubDate>
		<guid isPermaLink="false">http://python.genedrift.org/2009/04/20/managing-a-simple-database-with-python-sqlite-and-wxpython-7-includes-a-question/#comment-26980</guid>
		<description>The update statement looks really ugly here. Why not use SQLAlchemy or some kind of a mapper? For the start, you could generate the SQL on the fly yourself (i.e. &quot;%s = ?&quot; % name for all keys in the passed dict).</description>
		<content:encoded><![CDATA[<p>The update statement looks really ugly here. Why not use SQLAlchemy or some kind of a mapper? For the start, you could generate the SQL on the fly yourself (i.e. &#8220;%s = ?&#8221; % name for all keys in the passed dict).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://python.genedrift.org/2009/04/20/managing-a-simple-database-with-python-sqlite-and-wxpython-7-includes-a-question/comment-page-1/#comment-26972</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Mon, 20 Apr 2009 21:18:50 +0000</pubDate>
		<guid isPermaLink="false">http://python.genedrift.org/2009/04/20/managing-a-simple-database-with-python-sqlite-and-wxpython-7-includes-a-question/#comment-26972</guid>
		<description>Try using named placeholders in the SQL statments

import sqlite3

con = sqlite3.connect(&quot;:memory:&quot;)
cur = con.cursor()
cur.execute(&quot;create table people (name text, age real)&quot;)

data = {&quot;who&quot;:&quot;Yeltsin&quot;, &quot;age&quot;:72}

# using (:who,:age) pulls values from the dictionary
cur.execute(&quot;insert into people values (:who, :age)&quot;, data)

cur.execute(&quot;select * from people&quot;)
print cur.fetchone()
#prints (u&#039;Yeltsin&#039;, 72.0)

data[&quot;age&quot;] = 90.0
cur.execute(&quot;UPDATE people SET age=:age WHERE name=:who&quot;, data)

cur.execute(&quot;select * from people&quot;)
print cur.fetchone()
prints (u&#039;Yeltsin&#039;, 90.0)

con.close()</description>
		<content:encoded><![CDATA[<p>Try using named placeholders in the SQL statments</p>
<p>import sqlite3</p>
<p>con = sqlite3.connect(&#8220;:memory:&#8221;)<br />
cur = con.cursor()<br />
cur.execute(&#8220;create table people (name text, age real)&#8221;)</p>
<p>data = {&#8220;who&#8221;:&#8221;Yeltsin&#8221;, &#8220;age&#8221;:72}</p>
<p># using (:who,:age) pulls values from the dictionary<br />
cur.execute(&#8220;insert into people values (:who, :age)&#8221;, data)</p>
<p>cur.execute(&#8220;select * from people&#8221;)<br />
print cur.fetchone()<br />
#prints (u&#8217;Yeltsin&#8217;, 72.0)</p>
<p>data["age"] = 90.0<br />
cur.execute(&#8220;UPDATE people SET age=:age WHERE name=:who&#8221;, data)</p>
<p>cur.execute(&#8220;select * from people&#8221;)<br />
print cur.fetchone()<br />
prints (u&#8217;Yeltsin&#8217;, 90.0)</p>
<p>con.close()</p>
]]></content:encoded>
	</item>
</channel>
</rss>

