<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PlanetMysql.ru - информация о СУБД MySQL &#187; myconnpy</title>
	<atom:link href="http://planetmysql.ru/category/myconnpy/feed/" rel="self" type="application/rss+xml" />
	<link>http://planetmysql.ru</link>
	<description>Блог о самой популярной СУБД MySQL</description>
	<lastBuildDate>Thu, 29 Jul 2010 23:40:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MySQL Connector/Python 0.1.5 release: critical bug fix</title>
		<link>http://geert.vanderkelen.org/2010/05/mysql-connectorpython-015-release.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=mysql-connectorpython-0-1-5-release-critical-bug-fix</link>
		<comments>http://geert.vanderkelen.org/2010/05/mysql-connectorpython-015-release.html#comments</comments>
		<pubDate>Thu, 27 May 2010 09:50:24 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">tag:blogger.com,1999:blog-7603704315097619422.post-5572935448913790756</guid>
		<description><![CDATA[We just released MySQL Connector/Python 0.1.5 which includes a critical bug fix. It was impossible to read big result sets. The files for 0.1.4-release have been removed.You can download MySQL Connector/Python from Launchpad.Highlights:It was impossible to retrieve big result sets. (bug lp:551533 and lp:586003)
Changing copyright from Sun to Oracle (also fixing silly typo)
A very Big Thanks goes to the reporters of bug lp:551533 and lp:586003. Apologies for not being able to reproduce the bug earlier, before releasing 0.1.4.About MySQL Connector/Python: MySQL Connector/Python is implementing the MySQL Client/Server protocol completely in Python. No MySQL libraries are needed, and no compilation is necessary to run this Python DB API v2.0 compliant driver. It is compatible with Python v2.5 and later as well as Python v3.1 and later.]]></description>
			<content:encoded><![CDATA[<p>We just released <b><a href="http://launchpad.net/myconnpy">MySQL Connector/Python 0.1.5</a></b> which includes a critical bug fix. It was impossible to read big result sets. The files for 0.1.4-release have been removed.</p><p>You can <b>download MySQL Connector/Python</b> from <a href="https://launchpad.net/myconnpy/+download">Launchpad</a>.</p><p>Highlights:</p><ul><li>It was impossible to retrieve big result sets. (bug lp:551533 and lp:586003)</li>
<li>Changing copyright from Sun to Oracle (also fixing silly typo)</li>
</ul><p>A very <b>Big Thanks</b> goes to the reporters of bug <a href="https://bugs.launchpad.net/myconnpy/+bug/551533">lp:551533</a> and <a href="https://bugs.launchpad.net/bugs/586003">lp:586003</a>. Apologies for not being able to reproduce the bug earlier, before releasing 0.1.4.</p><p><b>About MySQL Connector/Python:</b> <i>MySQL Connector/Python is implementing the MySQL Client/Server protocol completely in Python. No MySQL libraries are needed, and no compilation is necessary to run this Python DB API v2.0 compliant driver. It is compatible with Python v2.5 and later as well as Python v3.1 and later.</i></p><div><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/7603704315097619422-5572935448913790756?l=geert.vanderkelen.org" alt="" /></div><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=24879&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=24879&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://geert.vanderkelen.org/2010/05/mysql-connectorpython-015-release.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Connector/Python 0.1.4-devel available</title>
		<link>http://geert.vanderkelen.org/2010/05/mysql-connectorpython-014-devel.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=mysql-connectorpython-0-1-4-devel-available</link>
		<comments>http://geert.vanderkelen.org/2010/05/mysql-connectorpython-014-devel.html#comments</comments>
		<pubDate>Fri, 21 May 2010 08:07:24 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">tag:blogger.com,1999:blog-7603704315097619422.post-8407378719963557049</guid>
		<description><![CDATA[Next development release 0.1.4 of MySQL Connector/Python is now available for download. This will be the last in the 0.1-series as we move on to 0.2. The aim is to release more often to get to v1.0. Hurray!Highlights:Reading from network was broken for bigger packages.
Reimplementing protocol.MySQLProtocol marking simpler and easier to maintain.
It is now possible to send multiple statements to MySQL using MySQLCursor.execute(). The results are accessible by calling the method next_resultset().
MySQLCursor.callproc() will now store all result sets as a MySQLCursorBuffered. They are accessible using the next_proc_resultset() method. The result of the stored procedure is returned by callproc() itself as defined by PEP249.
MySQL DATETIME conversion to Python datetime.datetime is now much faster.
Some overall performance improvements.
Copyright notice changes.
Big thanks to everyone using and reporting bugs found in MySQL Connector/Python. Don't hesitate to ask questions and report problems or feature requests using Launchpad.
About MySQL Connector/Python: MySQL Connector/Python is implementing the MySQL Client/Server protocol completely in Python. No MySQL libraries are needed, and no compilation is necessary to run this Python DB API v2.0 compliant driver. It is compatible with Python v2.5 and later as well as Python v3.1 and later.]]></description>
			<content:encoded><![CDATA[<p><b>Next development release 0.1.4 of <a href="http://launchpad.net/myconnpy/">MySQL Connector/Python</a></b> is now available for <a href="https://launchpad.net/myconnpy/+download">download</a>. This will be the last in the 0.1-series as we move on to 0.2. The aim is to release more often to get to v1.0. Hurray!</p><p><b>Highlights</b>:</p><ul><li>Reading from network was broken for bigger packages.</li>
<li>Reimplementing protocol.MySQLProtocol marking simpler and easier to maintain.</li>
<li>It is now possible to send multiple statements to MySQL using MySQLCursor.execute(). The results are accessible by calling the method next_resultset().</li>
<li>MySQLCursor.callproc() will now store all result sets as a MySQLCursorBuffered. They are accessible using the next_proc_resultset() method. The result of the stored procedure is returned by callproc() itself as defined by PEP249.</li>
<li>MySQL DATETIME conversion to Python datetime.datetime is now much faster.</li>
<li>Some overall performance improvements.</li>
<li>Copyright notice changes.</li>
</ul><p><b>Big thanks</b> to everyone using and reporting bugs found in MySQL Connector/Python. Don't hesitate to <a href="https://answers.launchpad.net/myconnpy">ask questions</a> and <a href="https://bugs.launchpad.net/myconnpy">report problems or feature requests</a> using Launchpad.<br />
<p><b>About MySQL Connector/Python</b>: <i>MySQL Connector/Python is implementing the MySQL Client/Server protocol completely in Python. No MySQL libraries are needed, and no compilation is necessary to run this Python DB API v2.0 compliant driver. It is compatible with Python v2.5 and later as well as Python v3.1 and later.</i></p><div><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/7603704315097619422-8407378719963557049?l=geert.vanderkelen.org" alt="" /></div><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=24831&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=24831&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://geert.vanderkelen.org/2010/05/mysql-connectorpython-014-devel.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simulating server-side cursors with MySQL Connector/Python</title>
		<link>http://geert.vanderkelen.org/2010/04/simulating-server-side-cursors-with.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=simulating-server-side-cursors-with-mysql-connectorpython</link>
		<comments>http://geert.vanderkelen.org/2010/04/simulating-server-side-cursors-with.html#comments</comments>
		<pubDate>Mon, 26 Apr 2010 13:09:24 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[hacking]]></category>
		<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[pyhon]]></category>

		<guid isPermaLink="false">tag:blogger.com,1999:blog-7603704315097619422.post-87433650665512154</guid>
		<description><![CDATA[Last week, my colleague Massimo and I discussed how to handle big result sets coming from MySQL in Python. The problem is that MySQL doesn't support server-side cursors, so you need to select everything and then read it. You can do it either buffered or not. MySQL Connector/Python defaults to non-buffered, meaning that you need to fetch all rows after issuing a SELECT statement. You can also turn on the buffering, mimicking what MySQL for Python (MySQLdb) does.For big result sets, it's better to limit your search. You can do this using an integer primary key or some temporal field for example. Or you can use the LIMIT keyword. The latter solution is what is used in the MySQLCursorServerSide cursor-class. Using the SELECT it creates a temporary table from which the fetch-methods will get the information. It is something people have probably implemented in their applications, but I hope this new class will make it easier since it's done transparently.The code is not pushed yet, but expect it to be available in next release. Here is an example how you could use it. This code selects cities staring with Z, loops over the result getting the country (yes, this is a simple join made difficult):cnx = db.connect(user='root',db='world')
    cur = cnx.cursor()
    curCity = cnx.cursor(db.cursor.MySQLCursorServerSide)
    
    curCity.execute("SELECT ID,Name,CountryCode FROM City "\
        "WHERE NAME LIKE 'Z%' ORDER BY ID")
    
    for city in curCity:
        cur.execute("SELECT Code,Name FROM Country WHERE CODE = %s",
            (city[2],))
        country = cur.fetchone()
        print "%s (%s)" % (city[1], country[1])
    
    cur.close()
    cnx.close()
I guess the main advantage is that you can use two or more cursor objects with the same connection without the need of buffering everything in Python. On the MySQL side, the temporary table could go to disk when to big. It's maybe slower, but keeping big result sets in memory ain't good either.Comments are welcome!]]></description>
			<content:encoded><![CDATA[<p>Last week, my colleague Massimo and I discussed <strong>how to handle big result sets</strong> coming from <a href="http://dev.mysql.com">MySQL</a> in <a href="http://www.python.org">Python</a>. The problem is that MySQL doesn't support server-side cursors, so you need to select everything and then read it. You can do it either buffered or not. <a href="http://launchpad.net/myconnpy">MySQL Connector/Python</a> defaults to non-buffered, meaning that you need to fetch all rows after issuing a <tt>SELECT</tt> statement. You can also turn on the buffering, mimicking what <a href="http://sourceforge.net/projects/mysql-python/files/">MySQL for Python</a> (MySQLdb) does.</p><p>For big result sets, <strong>it's better to limit your search</strong>. You can do this using an integer primary key or some temporal field for example. Or you can use the <tt>LIMIT</tt> keyword. The latter solution is what is used in the <tt>MySQLCursorServerSide</tt> cursor-class. Using the <tt>SELECT</tt> it creates a temporary table from which the fetch-methods will get the information. It is something people have probably implemented in their applications, but I hope this new class will make it easier since it's done transparently.</p><p><strong>The code is not pushed yet</strong>, but expect it to be available in next release. Here is an example how you could use it. This code selects cities staring with <tt>Z</tt>, loops over the result getting the country (yes, this is a simple join made difficult):</p><pre>cnx = db.connect(user='root',db='world')
    cur = cnx.cursor()
    curCity = cnx.cursor(db.cursor.MySQLCursorServerSide)
    
    curCity.execute("SELECT ID,Name,CountryCode FROM City "\
        "WHERE NAME LIKE 'Z%' ORDER BY ID")
    
    for city in curCity:
        cur.execute("SELECT Code,Name FROM Country WHERE CODE = %s",
            (city[2],))
        country = cur.fetchone()
        print "%s (%s)" % (city[1], country[1])
    
    cur.close()
    cnx.close()
</pre><p>I guess <strong>the main advantage</strong> is that you can use two or more cursor objects with the same connection without the need of buffering everything in Python. On the MySQL side, the temporary table could go to disk when to big. It's maybe slower, but keeping big result sets in memory ain't good either.</p><p>Comments are welcome!</p><div><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/7603704315097619422-87433650665512154?l=geert.vanderkelen.org" alt="" /></div><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=24510&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=24510&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://geert.vanderkelen.org/2010/04/simulating-server-side-cursors-with.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple result sets in MySQL Connector/Python</title>
		<link>http://geert.vanderkelen.org/2010/04/multiple-result-sets-in-mysql.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=multiple-result-sets-in-mysql-connectorpython</link>
		<comments>http://geert.vanderkelen.org/2010/04/multiple-result-sets-in-mysql.html#comments</comments>
		<pubDate>Sat, 24 Apr 2010 17:04:24 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[pyhon]]></category>

		<guid isPermaLink="false">tag:blogger.com,1999:blog-7603704315097619422.post-673514254876652832</guid>
		<description><![CDATA[Latest code of MySQL Connector/Python on launchpad has support for multiple result sets when you execute a stored procedure. We also changed the way the actual result of the routine is returned to conform to PEP249.Here is some example code: it creates a stored procedure which generates 2 result sets. You can get the result by calling next_resultset(), which is returning a MySQLCursorBuffered.    cur = cnx.cursor()

    cur.execute("DROP PROCEDURE IF EXISTS multi")
    proc = """
      CREATE PROCEDURE multi(IN pFac1 INT, IN pFac2 INT, OUT pProd INT)
      BEGIN
        SELECT 1,'a' as FooBar;
        SELECT 2;
        SET pProd := pFac1 * pFac2;
      END"""

    cur.execute(proc)
    result = cur.callproc("multi", (5, 6, 0))
    print "Result:", result
    
    extcur = cur.next_resultset()
    i = 1
    while extcur:
        rows = extcur.fetchall()
        print "Result set #%d:" % i
        print rows
        extcur = cur.next_resultset()
        i += 1
        
    cur.close()
The output:Result: ('5', '6', 30)
Result set #1:
[(1, u'a')]
Result set #2:
[(2,)]
As mentioned above: this will be part of 0.1.4-devel release due next week. Comments are welcome through the associated bug report.]]></description>
			<content:encoded><![CDATA[<p>Latest code of <a href="http://dev.mysql.com">MySQL</a> C<a href="http://launchpad.net/myconnpy">onnector/Python</a> on launchpad has support for <a href="http://dev.mysql.com/doc/refman/5.1/en/stored-routines-syntax.html">multiple result sets</a> when you execute a stored procedure. We also changed the way the actual result of the routine is returned to conform to <a href="http://www.python.org/dev/peps/pep-0249/">PEP249</a>.</p><p>Here is some example code: it creates a stored procedure which generates 2 result sets. You can get the result by calling <tt>next_resultset()</tt>, which is returning a <tt>MySQLCursorBuffered</tt>.</p><pre>    cur = cnx.cursor()

    cur.execute("DROP PROCEDURE IF EXISTS multi")
    proc = """
      CREATE PROCEDURE multi(IN pFac1 INT, IN pFac2 INT, OUT pProd INT)
      BEGIN
        SELECT 1,'a' as FooBar;
        SELECT 2;
        SET pProd := pFac1 * pFac2;
      END"""

    cur.execute(proc)
    result = cur.callproc("multi", (5, 6, 0))
    print "Result:", result
    
    extcur = cur.next_resultset()
    i = 1
    while extcur:
        rows = extcur.fetchall()
        print "Result set #%d:" % i
        print rows
        extcur = cur.next_resultset()
        i += 1
        
    cur.close()
</pre><p>The output:</p><pre>Result: ('5', '6', 30)
Result set #1:
[(1, u'a')]
Result set #2:
[(2,)]
</pre><p>As mentioned above: this will be part of 0.1.4-devel release due next week. Comments are welcome through the <a href="https://bugs.launchpad.net/myconnpy/+bug/569254">associated bug report</a>.</p><div><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/7603704315097619422-673514254876652832?l=geert.vanderkelen.org" alt="" /></div><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=24496&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=24496&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://geert.vanderkelen.org/2010/04/multiple-result-sets-in-mysql.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Status report No.2 on SQLAlchemy and MySQL Connector/Python</title>
		<link>http://geert.vanderkelen.org/2010/02/status-report-no2-on-sqlalchemy-and.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=status-report-no-2-on-sqlalchemy-and-mysql-connectorpython</link>
		<comments>http://geert.vanderkelen.org/2010/02/status-report-no2-on-sqlalchemy-and.html#comments</comments>
		<pubDate>Fri, 19 Feb 2010 11:18:24 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">tag:blogger.com,1999:blog-7603704315097619422.post-2566033305462324251</guid>
		<description><![CDATA[Few days ago, the folks at SQLAlchemy pushed some proposed modification to the MySQL Connector/Python dialect. Before this patch, previous report yielded 72 errors and 11 failures. Now we got down to 9 errors, but the failures are still lingering. Is this an improvement? Yes and no, failures should go down, but there are some SQLAlchemy tests I just can't figure out, yet.. clues are welcome!Here are some detailed results which also included MySQLdb and oursql. I used SQLAlchemy revision 6788 (i.e. from svn trunk) which has now 2143 unittests:mysql.connector rev216: SKIP=1, errors=9, failures=11 (355.707s)
MySQLdb 1.2.3c1: SKIP=2, errors=8, failures=1 (315.884s)
oursql 0.9.1: SKIP=1, errors=8, failures=2 (322.318s)
Software used: MacOSX v10.6.2, MySQL v5.1.42 and Python v2.6.1.Using SQLAlchemy might not be the best way to messure how mature MySQL Connector/Python is, but it sure helps lots.]]></description>
			<content:encoded><![CDATA[<p>Few days ago, the folks at <a href="http://sqlalchemy.org">SQLAlchemy</a> pushed <a href="http://www.sqlalchemy.org/trac/ticket/1668">some proposed modification</a> to the <a href="https://launchpad.net/myconnpy">MySQL Connector/Python</a> dialect. Before this patch, <a href="http://geert.vanderkelen.org/2010/01/small-status-on-sqlalchemy-and-mysql.html">previous report</a> yielded 72 errors and 11 failures. Now we got down to 9 errors, but the failures are still lingering. Is this an improvement? Yes and no, failures should go down, but there are some SQLAlchemy tests I just can't figure out, yet.. clues are welcome!</p><p>Here are some detailed results which also included <a href="http://sourceforge.net/projects/mysql-python/files/">MySQLdb</a> and <a href="https://launchpad.net/oursql">oursql</a>. I used SQLAlchemy revision 6788 (i.e. from <a href="http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk">svn trunk</a>) which has now 2143 unittests:</p><ul><li><strong>mysql.connector rev216</strong>: SKIP=1, errors=9, failures=11 (355.707s)</li>
<li><strong>MySQLdb 1.2.3c1</strong>: SKIP=2, errors=8, failures=1 (315.884s)</li>
<li><strong>oursql 0.9.1</strong>: SKIP=1, errors=8, failures=2 (322.318s)</li>
</ul><p>Software used: MacOSX v10.6.2, MySQL v5.1.42 and Python v2.6.1.</p><p>Using SQLAlchemy might not be the best way to messure how mature MySQL Connector/Python is, but it sure helps lots.</p><div><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/7603704315097619422-2566033305462324251?l=geert.vanderkelen.org" alt="" /></div><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23579&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23579&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://geert.vanderkelen.org/2010/02/status-report-no2-on-sqlalchemy-and.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stuffing the gaps in the COLLATIONS table using a stored procedure</title>
		<link>http://geert.vanderkelen.org/2010/02/stuffing-gaps-in-collations-table-using.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=stuffing-the-gaps-in-the-collations-table-using-a-stored-procedure</link>
		<comments>http://geert.vanderkelen.org/2010/02/stuffing-gaps-in-collations-table-using.html#comments</comments>
		<pubDate>Wed, 17 Feb 2010 11:52:00 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">tag:blogger.com,1999:blog-7603704315097619422.post-3147198065371087259</guid>
		<description><![CDATA[To far fetched (pun inteded), some might think.. Below you'll find a procedure to get a list of MySQL supported character sets and their collations. The output is Python and can be used to build a (big) tuple.The problem is that character set IDs in MySQL have 'gaps'. For example hebrew has ID 16, and the next character set in the COLLATIONS-table, tis620, has ID 18. Not a big problem, just a bit annoying. This list is hardcoded in MySQL Connector/Python and I needed something to easily maintain it.Solutions were using text editing skills, parsing it in Python to produce a list, etc.. But why not a Stored Routine? The following stored procedure is looping over a cursor, calculating the number of rows the gap has, and inserts blanks as needed.DROP PROCEDURE IF EXISTS python_getcharsets;
DELIMITER //
CREATE PROCEDURE python_getcharsets()
BEGIN
  DECLARE i,diff,cid,done INT DEFAULT 0;
  DECLARE chname,coname VARCHAR(32);
  DECLARE cur CURSOR FOR SELECT ID,CHARACTER_SET_NAME,
    COLLATION_NAME FROM INFORMATION_SCHEMA.COLLATIONS
    ORDER BY ID;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
  OPEN cur;
  loop_cur: LOOP
    FETCH cur INTO cid,chname,coname;
    IF done THEN LEAVE loop_cur; END IF;
    SET i = i + 1; SET diff = cid - i;
    WHILE diff DO
      SELECT "None,";
      SET diff = diff - 1; SET i = i + 1;
    END WHILE;
    SELECT CONCAT('("',chname,'","',coname,'"), # ',cid);
  END LOOP loop_cur;
  CLOSE cur;
END//
DELIMITER ;

CALL python_getcharsets();
DROP PROCEDURE IF EXISTS python_getcharsets;
You would save the above to a file called getcharsets.sql for example, and execute it like this:shell&#62; mysql -N test &#60; getcharsets.sql 
..
(&#34;cp1251&#34;,&#34;cp1251_bulgarian_ci&#34;), # 14
(&#34;latin1&#34;,&#34;latin1_danish_ci&#34;), # 15
(&#34;hebrew&#34;,&#34;hebrew_general_ci&#34;), # 16
None,
(&#34;tis620&#34;,&#34;tis620_thai_ci&#34;), # 18
(&#34;euckr&#34;,&#34;euckr_korean_ci&#34;), # 19
..
I&#039;ll spare you the complete output, but as you can see from above sample: the gap has been stuffed with a None-Python value. Taking this output, you&#039;ll inserted it your code:desc = (
    None,
    (&#34;big5&#34;,&#34;big5_chinese_ci&#34;), # 1
    (&#34;latin2&#34;,&#34;latin2_czech_cs&#34;), # 2
    (&#34;dec8&#34;,&#34;dec8_swedish_ci&#34;), # 3
    (&#34;cp850&#34;,&#34;cp850_general_ci&#34;), # 4
..
Silly? Definitely basic stuff, but I got my code a bit faster, and cleaner!]]></description>
			<content:encoded><![CDATA[<p>To far fetched (pun inteded), some might think.. Below you'll find a procedure to get a list of <a href="http://dev.mysql.com">MySQL</a> supported <a href="http://dev.mysql.com/doc/refman/5.1/en/charset.html">character sets</a> and their collations. The output is <a href="http://python.org">Python</a> and can be used to build a (big) <tt>tuple</tt>.</p><p><strong>The problem</strong> is that character set IDs in MySQL have 'gaps'. For example <tt>hebrew</tt> has ID 16, and the next character set in the <tt>COLLATIONS</tt>-table, <tt>tis620</tt>, has ID 18. Not a big problem, just a bit annoying. This list is hardcoded in <a href="https://launchpad.net/myconnpy">MySQL Connector/Python</a> and I needed something to easily maintain it.</p><p><strong>Solutions</strong> were using text editing skills, parsing it in Python to produce a list, etc.. But why not a <a href="http://dev.mysql.com/doc/refman/5.1/en/stored-programs-views.html">Stored Routine</a>? The following stored procedure is looping over a cursor, calculating the number of rows the gap has, and inserts blanks as needed.</p><pre>DROP PROCEDURE IF EXISTS python_getcharsets;
DELIMITER //
CREATE PROCEDURE python_getcharsets()
BEGIN
  DECLARE i,diff,cid,done INT DEFAULT 0;
  DECLARE chname,coname VARCHAR(32);
  DECLARE cur CURSOR FOR SELECT ID,CHARACTER_SET_NAME,
    COLLATION_NAME FROM INFORMATION_SCHEMA.COLLATIONS
    ORDER BY ID;
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
  OPEN cur;
  loop_cur: LOOP
    FETCH cur INTO cid,chname,coname;
    IF done THEN LEAVE loop_cur; END IF;
    SET i = i + 1; SET diff = cid - i;
    WHILE diff DO
      SELECT "None,";
      SET diff = diff - 1; SET i = i + 1;
    END WHILE;
    SELECT CONCAT('("',chname,'","',coname,'"), # ',cid);
  END LOOP loop_cur;
  CLOSE cur;
END//
DELIMITER ;

CALL python_getcharsets();
DROP PROCEDURE IF EXISTS python_getcharsets;
</pre><p>You would save the above to a file called <tt>getcharsets.sql</tt> for example, and execute it like this:</p><pre>shell> <strong>mysql -N test < getcharsets.sql</strong> 
..
("cp1251","cp1251_bulgarian_ci"), # 14
("latin1","latin1_danish_ci"), # 15
("hebrew","hebrew_general_ci"), # 16
None,
("tis620","tis620_thai_ci"), # 18
("euckr","euckr_korean_ci"), # 19
..
</pre><p>I'll spare you the complete output, but as you can see from above sample: the gap has been stuffed with a <tt>None</tt>-Python value. Taking this output, you'll inserted it your code:</p><pre>desc = (
    None,
    ("big5","big5_chinese_ci"), # 1
    ("latin2","latin2_czech_cs"), # 2
    ("dec8","dec8_swedish_ci"), # 3
    ("cp850","cp850_general_ci"), # 4
..
</pre><p>Silly? Definitely basic stuff, but I got my code a bit faster, and cleaner!</p><div><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/7603704315097619422-3147198065371087259?l=geert.vanderkelen.org" alt="" /></div><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23516&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23516&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://geert.vanderkelen.org/2010/02/stuffing-gaps-in-collations-table-using.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t forget the COMMIT in MySQL</title>
		<link>http://blog.some-abstract-type.com/2010/02/dont-forget-commit-in-mysql.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=dont-forget-the-commit-in-mysql</link>
		<comments>http://blog.some-abstract-type.com/2010/02/dont-forget-commit-in-mysql.html#comments</comments>
		<pubDate>Mon, 08 Feb 2010 22:29:24 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">tag:blogger.com,1999:blog-5702936365231918674.post-8120553126411850327</guid>
		<description><![CDATA[Yes, MySQL has transactions if you use InnoDB or NDB Cluster for example. Using these transactional storage engines, you'll have to commit (or roll back) your inserts, deletes or updates.I've seen it a few times now with people being surprised that no data is going into the tables. It's not so a silly problem in the end. If you are used to the defaults in MySQL you don't have to commit anything since it is automatically done for you.Take the Python Database Interfaces for MySQL. PEP-249 says that, by default, auto-commit should be turned off. You could turn it back on, but it's good practice to be explicit and commit in your code. Remember the Zen of Python!Here is just a small example to show it. Uses MySQL Connector/Python, but it does work also with others:import mysql.connectorcnx = mysql.connector.connect(db='test')cur = cnx.cursor()cur.execute("""CREATE TABLE innodb_t1 (  id INT UNSIGNED NOT NULL,  c1 VARCHAR(128),  PRIMARY KEY (id)) ENGINE=InnoDB""")ins = "INSERT INTO innodb_t1 (id,c1) VALUES (%s,%s)"cur.execute(ins,  (1,'MySQL Support Team _is_ already the best',))cnx.commit()cur.close()cnx.close()]]></description>
			<content:encoded><![CDATA[<p>Yes, <a href="http://dev.mysql.com">MySQL</a> has transactions if you use <a href="http://dev.mysql.com/doc/refman/5.1/en/innodb.html">InnoDB</a> or <a href="http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster.html">NDB Cluster</a> for example. Using these transactional storage engines, you'll have <a href="http://dev.mysql.com/doc/refman/5.1/en/commit.html">to commit</a> (or roll back) your inserts, deletes or updates.</p><p>I've seen it a few times now with people being surprised that no data is going into the tables. It's not so a silly problem in the end. If you are used to the defaults in MySQL you don't have to commit anything since it is automatically done for you.</p><p>Take the <a href="http://python.org">Python</a> Database Interfaces for MySQL. <a href="http://www.python.org/dev/peps/pep-0249/">PEP-249</a> says that, by default, auto-commit should be turned off. You could turn it back on, but it's good practice to be explicit and commit in your code. Remember <a href="http://www.python.org/dev/peps/pep-0020/">the Zen of Python</a>!<p>Here is just a small example to show it. Uses <a href="https://launchpad.net/myconnpy">MySQL Connector/Python</a>, but it does work also with others:</p><pre><br />import mysql.connector<br />cnx = mysql.connector.connect(db='test')<br />cur = cnx.cursor()<br />cur.execute("""CREATE TABLE innodb_t1 (<br />  id INT UNSIGNED NOT NULL,<br />  c1 VARCHAR(128),<br />  PRIMARY KEY (id)<br />) ENGINE=InnoDB""")<br />ins = "INSERT INTO innodb_t1 (id,c1) VALUES (%s,%s)"<br />cur.execute(ins,<br />  (1,'MySQL Support Team _is_ already the best',))<br />cnx.commit()<br />cur.close()<br />cnx.close()<br /></pre><div><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/5702936365231918674-8120553126411850327?l=blog.some-abstract-type.com" alt="" /></div><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23391&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23391&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://blog.some-abstract-type.com/2010/02/dont-forget-commit-in-mysql.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FOSDEM: &#8216;Connecting MySQL and Python&#8217;, handout &amp; wrap-up</title>
		<link>http://blog.some-abstract-type.com/2010/02/fosdem-connecting-mysql-and-python.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=fosdem-connecting-mysql-and-python-handout-wrap-up</link>
		<comments>http://blog.some-abstract-type.com/2010/02/fosdem-connecting-mysql-and-python.html#comments</comments>
		<pubDate>Sun, 07 Feb 2010 14:54:00 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[fosdem]]></category>
		<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[talk]]></category>

		<guid isPermaLink="false">tag:blogger.com,1999:blog-5702936365231918674.post-3344461649327831856</guid>
		<description><![CDATA[Apparently, my talk at FOSDEM 2010 about Connecting MySQL and Python was the only one about Python? There should be more, or?I have a hand-out ready in PDF. The slides are not usable without my chatter. It contains a few examples and links. Any comments, corrections, criticism.. are welcome!The longer version of this talk will be given at the O'Reilly MySQL Conference&#38;Expo 2010 in Santa Clara, California (USA).]]></description>
			<content:encoded><![CDATA[<p>Apparently, my talk at <a href="http://fosdem.org">FOSDEM</a> 2010 about <a href="http://forge.mysql.com/wiki/FOSDEM_2010_Developer_Room">Connecting MySQL and Python</a> was the only one about <a href="http://python.org">Python</a>? There should be more, or?</p><p>I have a <a href="http://tr.im/NbMt">hand-out ready in PDF</a>. The slides are not usable without my chatter. It contains a few examples and links. Any comments, corrections, criticism.. are welcome!</p><p>The longer version of this talk will be given at the <a href="http://en.oreilly.com/mysql2010/">O'Reilly MySQL Conference&Expo 2010</a> in Santa Clara, California (USA).</p><div><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/5702936365231918674-3344461649327831856?l=blog.some-abstract-type.com" alt="" /></div><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23369&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23369&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://blog.some-abstract-type.com/2010/02/fosdem-connecting-mysql-and-python.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FOSDEM: &#8216;Connecting MySQL and Python&#8217;, handout &amp; wrap-up</title>
		<link>http://blog.some-abstract-type.com/2010/02/fosdem-connecting-mysql-and-python.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=fosdem-connecting-mysql-and-python-handout-wrap-up</link>
		<comments>http://blog.some-abstract-type.com/2010/02/fosdem-connecting-mysql-and-python.html#comments</comments>
		<pubDate>Sun, 07 Feb 2010 14:54:00 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[fosdem]]></category>
		<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[talk]]></category>

		<guid isPermaLink="false">tag:blogger.com,1999:blog-5702936365231918674.post-3344461649327831856</guid>
		<description><![CDATA[Apparently, my talk at FOSDEM 2010 about Connecting MySQL and Python was the only one about Python? There should be more, or?I have a hand-out ready in PDF. The slides are not usable without my chatter. It contains a few examples and links. Any comments, corrections, criticism.. are welcome!The longer version of this talk will be given at the O'Reilly MySQL Conference&#38;Expo 2010 in Santa Clara, California (USA).]]></description>
			<content:encoded><![CDATA[<p>Apparently, my talk at <a href="http://fosdem.org">FOSDEM</a> 2010 about <a href="http://forge.mysql.com/wiki/FOSDEM_2010_Developer_Room">Connecting MySQL and Python</a> was the only one about <a href="http://python.org">Python</a>? There should be more, or?</p><p>I have a <a href="http://tr.im/NbMt">hand-out ready in PDF</a>. The slides are not usable without my chatter. It contains a few examples and links. Any comments, corrections, criticism.. are welcome!</p><p>The longer version of this talk will be given at the <a href="http://en.oreilly.com/mysql2010/">O'Reilly MySQL Conference&Expo 2010</a> in Santa Clara, California (USA).</p><div><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/5702936365231918674-3344461649327831856?l=blog.some-abstract-type.com" alt="" /></div><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23369&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23369&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://blog.some-abstract-type.com/2010/02/fosdem-connecting-mysql-and-python.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Connector/Python 0.1.3-devel available</title>
		<link>http://blog.some-abstract-type.com/2010/01/mysql-connectorpython-013-devel.html?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=mysql-connectorpython-0-1-3-devel-available</link>
		<comments>http://blog.some-abstract-type.com/2010/01/mysql-connectorpython-013-devel.html#comments</comments>
		<pubDate>Thu, 28 Jan 2010 16:01:00 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[pyhon]]></category>

		<guid isPermaLink="false">tag:blogger.com,1999:blog-5702936365231918674.post-2858680403251443565</guid>
		<description><![CDATA[MySQL Connector/Python v0.1.3-devel is now available for download from Launchpad.org. Please note that this is a development (i.e. alpha, unstable, ..) release and we welcome everyone to test and report problems.Highlights for this v0.1.3-devel:Important memory leak fixed when closing cursors.Warnings can now be raised as exceptions.Fixing unicode usage and broken error message when MySQL chops themClient flags can now be set correctly when connectingConversion fixes for BIT/YEARSET and Python to DATE/DATETIMEAdding MySQL Client Errors and raising better exceptions based on errno.Enjoy!]]></description>
			<content:encoded><![CDATA[<p><a href="https://launchpad.net/myconnpy">MySQL Connector/Python</a> v0.1.3-devel is now <a href="https://launchpad.net/myconnpy/+download">available for download</a> from Launchpad.org. Please note that this is a development (i.e. alpha, unstable, ..) release and we welcome everyone to test and <a href="https://bugs.launchpad.net/myconnpy">report problems</a>.</p><p>Highlights for this v0.1.3-devel:</p><ul><li>Important memory leak fixed when closing cursors.</li><li>Warnings can now be raised as exceptions.</li><li>Fixing unicode usage and broken error message when MySQL chops them</li><li>Client flags can now be set correctly when connecting</li><li>Conversion fixes for BIT/YEARSET and Python to DATE/DATETIME</li><li>Adding MySQL Client Errors and raising better exceptions based on errno.</li></ul><p>Enjoy!</p><div><img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/5702936365231918674-2858680403251443565?l=blog.some-abstract-type.com" alt="" /></div><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23212&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23212&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://blog.some-abstract-type.com/2010/01/mysql-connectorpython-013-devel.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
