<?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, 24 May 2012 22:24:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Automatic reconnect in MySQL Connector/Python?</title>
		<link>http://geert.vanderkelen.org/post/842/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=automatic-reconnect-in-mysql-connectorpython</link>
		<comments>http://geert.vanderkelen.org/post/842/#comments</comments>
		<pubDate>Fri, 16 Dec 2011 16:22:38 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://geert.vanderkelen.org/?p=842</guid>
		<description><![CDATA[There have been some request to have some reconnect possibilities in Connector/Python. I&#8217;m wondering now whether there should be some automatic reconnect on certain errors within the database driver.
My personal feeling is to have no automatic reconnect within Connector/Python and the programmer has to come up with retrying transactions herself.
For example:

	cnx.disconnect() # For testing..
	tries = 2
	while tries &#62; 0:
		tries -= 1
		try:
			cursor.execute(&#34;INSERT INTO t1 (c1) VALUES ('ham')&#34;)
			cnx.commit()
		except mysql.connector.InterfaceError:
			if tries == 0:
				print &#34;Failed inserting data after retrying&#34;
				break
			else:
				print &#34;Reconnecting..&#34;
				cnx.reconnect()
		else:
			break

The above mimics how you would handle transactions and trying them reconnecting. I have ideas how to get this into Connector/Python, but it would not really fit PEP-249.
Would the above use case of reconnecting be enough?]]></description>
			<content:encoded><![CDATA[<p>There have been some request to have some reconnect possibilities in <a href="http://launchpad.net/myconnpy" >Connector/Python</a>. I&#8217;m wondering now whether there should be some automatic reconnect on certain errors within the database driver.</p>
<p>My personal feeling is to have no automatic reconnect within Connector/Python and the programmer has to come up with retrying transactions herself.</p>
<p>For example:</p>
<pre>
	cnx.disconnect() # For testing..
	tries = 2
	while tries &gt; 0:
		tries -= 1
		try:
			cursor.execute(&quot;INSERT INTO t1 (c1) VALUES ('ham')&quot;)
			cnx.commit()
		except mysql.connector.InterfaceError:
			if tries == 0:
				print &quot;Failed inserting data after retrying&quot;
				break
			else:
				print &quot;Reconnecting..&quot;
				cnx.reconnect()
		else:
			break
</pre>
<p>The above mimics how you would handle transactions and trying them reconnecting. I have ideas how to get this into Connector/Python, but it would not really fit <a href="http://www.python.org/dev/peps/pep-0249/" >PEP-249</a>.</p>
<p>Would the above use case of reconnecting be enough?</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=31333&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=31333&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2011/12/16/automatic-reconnect-in-mysql-connectorpython/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Connector/Python available through the Python Package Index</title>
		<link>http://geert.vanderkelen.org/post/825/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-connectorpython-available-through-the-python-package-index</link>
		<comments>http://geert.vanderkelen.org/post/825/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 11:33:58 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://geert.vanderkelen.org/?p=825</guid>
		<description><![CDATA[Today we&#8217;ve registered MySQL Connector/Python with the Python Package Index (PyPI). It makes installing your favorite connector even easier (provided you installed setuptools first):

shell&#62; easy_install mysql-connector

Please report problems either using Launchpad or MySQL Bugs website.]]></description>
			<content:encoded><![CDATA[<p>Today we&#8217;ve registered <a href="http://launchpad.net/myconnpy">MySQL Connector/Python</a> with the <a href="http://pypi.python.org/pypi/MySQL-Connector/">Python Package Index</a> (PyPI). It makes installing your favorite connector even easier (provided you installed <a href="http://pypi.python.org/pypi/setuptools">setuptools</a> first):</p>
<pre>
shell&gt; easy_install mysql-connector
</pre>
<p>Please report problems either using <a href="https://bugs.launchpad.net/myconnpy">Launchpad</a> or <a href="http://bugs.mysql.com">MySQL Bugs website</a>.</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=30583&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=30583&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2011/11/03/mysql-connectorpython-available-through-the-python-package-index/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Connector/Python bug category on bugs.mysql.com</title>
		<link>http://geert.vanderkelen.org/post/819/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-connectorpython-bug-category-on-bugs-mysql-com</link>
		<comments>http://geert.vanderkelen.org/post/819/#comments</comments>
		<pubDate>Tue, 01 Nov 2011 18:38:59 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://geert.vanderkelen.org/?p=819</guid>
		<description><![CDATA[In addition to reporting MySQL Connector/Python bugs on Launchpad, it is now also possible to enter them using http://bugs.mysql.com.]]></description>
			<content:encoded><![CDATA[<p>In addition to reporting <a href="http://launchpad.net/myconnpy" >MySQL Connector/Python</a> bugs on Launchpad, it is now also possible to enter them using <a href="http://bugs.mysql.com" >http://bugs.mysql.com</a>.</p>
<p><img alt="" src="http://geert.vanderkelen.org/media/MyConnPy_BugsMySQLCom.png" class="aligncenter" width="305" height="109" /></p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=30563&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=30563&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2011/11/01/mysql-connectorpython-bug-category-on-bugs-mysql-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My New Job at Oracle: Working on MySQL Connector/Python</title>
		<link>http://geert.vanderkelen.org/post/817/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=my-new-job-at-oracle-working-on-mysql-connectorpython</link>
		<comments>http://geert.vanderkelen.org/post/817/#comments</comments>
		<pubDate>Fri, 28 Oct 2011 09:56:34 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://geert.vanderkelen.org/?p=817</guid>
		<description><![CDATA[After more than 6 years doing MySQL Support for MySQL AB, Sun Microsystems, and Oracle, it&#8217;s time for a change. Time to get back to development!
As of November 2011 I&#8217;ll be working full-time on MySQL Connector/Python and other goodies within the MySQL development team at Oracle. Before, this was more or less a pet project done after working hours. However, with the birth of our son Tomas more than a year ago, I&#8217;ve been slacking and family got priority.
The idea is to make MySQL Connector/Python the best choice for connecting to MySQL from within your Python code. We still got a long road ahead of us, but I&#8217;m confident that we are on the right track.]]></description>
			<content:encoded><![CDATA[<p>After more than 6 years doing MySQL Support for <a href="http://www.mysql.com">MySQL</a> AB, <a href="http://en.wikipedia.org/wiki/Sun_Microsystems">Sun Microsystems</a>, and <a href="http://www.oracle.com">Oracle</a>, it&#8217;s time for a change. Time to get back to development!</p>
<p>As of November 2011 I&#8217;ll be working full-time on <a href="http://launchpad.net/myconnpy">MySQL Connector/Python</a> and other goodies within the MySQL development team at Oracle. Before, this was more or less a pet project done after working hours. However, with the <a href="http://geert.vanderkelen.org/post/245/">birth of our son Tomas</a> more than a year ago, I&#8217;ve been slacking and family got priority.</p>
<p>The idea is to make MySQL Connector/Python the best choice for connecting to MySQL from within your <a href="http://python.org">Python</a> code. We still got a long road ahead of us, but I&#8217;m confident that we are on the right track.</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=30533&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=30533&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2011/10/28/my-new-job-at-oracle-working-on-mysql-connectorpython/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Refactored: Poor man’s MySQL replication monitoring</title>
		<link>http://geert.vanderkelen.org/post/678/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=refactored-poor-man%25e2%2580%2599s-mysql-replication-monitoring</link>
		<comments>http://geert.vanderkelen.org/post/678/#comments</comments>
		<pubDate>Thu, 07 Apr 2011 06:53:49 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://geert.vanderkelen.org/?p=678</guid>
		<description><![CDATA[This is a reply to the blog post Poor man’s MySQL replication monitoring. Haidong Ji had a few problems using MySQLdb (could use the &#8216;dict&#8217; cursor) and apparently he doesn&#8217;t want to much dependencies. I agree that using the mysql client tool is a nice alternative if you don&#8217;t want to use any 3rd party Python modules. And the MySQL client tools are usually and should be installed with the server.
However, since MySQL Connector/Python only needs itself and Python, dependencies are reduced to a minimum. Here you&#8217;ll find a refactored version of Haidong&#8217;s version (can of course be made much more sophisticated) using the connector:

import sys
from socket import gethostname
import smtplib
import mysql.connector

emailSubject = &#34;Replication problem on slave %s&#34;
emailTo = &#34;recipient@example.com&#34;
emailFrom = &#34;monitor-tool@example.com&#34;

def runCmd(cmd):
    cnx = mysql.connector.connect(user='root',
                                  unix_socket='/path/to/mysql.sock')
    cur = cnx.cursor(buffered=True)
    cur.execute(cmd)
    columns = tuple( [d[0].decode('utf8') for d in cur.description] )
    row = cur.fetchone()
    if row is None:
        raise StandardError(&#34;MySQL Server not configured as Slave&#34;)
    result = dict(zip(columns, row))
    cur.close()
    cnx.close()
    return result

try:
    slave_status = runCmd(&#34;SHOW SLAVE STATUS&#34;)
except mysql.connector.Error, e:
    print &#62;&#62; sys.stderr, &#34;There was a MySQL error:&#34;, e
    sys.exit(1)
except StandardError, e:
    print &#62;&#62; sys.stderr, &#34;There was an error:&#34;, e
    sys.exit(1)

if (slave_status['Slave_IO_Running'] == 'Yes' and
    slave_status['Slave_SQL_Running'] == 'Yes' and
    slave_status['Last_Errno'] == 0):
    print &#34;Cool&#34;
else:
    emailBody = [
        &#34;From: %s&#34; % emailFrom,
        &#34;To: %s&#34; % emailTo,
        &#34;Subject: %s&#34; % (emailSubject %  gethostname()),
        &#34;&#34;,
        '\n'.join([ k + ' : ' + str(v) for k,v in slave_status.iteritems()]),
        &#34;\r\n&#34;,
        ]
    server = smtplib.SMTP(&#34;localhost&#34;)
    server.sendmail(emailFrom, [emailTo], '\r\n'.join(emailBody))
    server.quit()]]></description>
			<content:encoded><![CDATA[<p>This is a reply to the blog post <a href="http://www.haidongji.com/2011/04/06/poor-mans-mysql-replication-monitoring/">Poor man’s MySQL replication monitoring</a>. Haidong Ji had a few problems using <a href="http://sourceforge.net/projects/mysql-python/files/">MySQLdb</a> (could use the &#8216;dict&#8217; cursor) and apparently he doesn&#8217;t want to much dependencies. I agree that using the <tt><a href="http://dev.mysql.com/doc/refman/5.5/en/mysql.html">mysql</a></tt> client tool is a nice alternative if you don&#8217;t want to use any 3rd party <a href="http://python.org">Python</a> modules. And the <a href="http://dev.mysql.com">MySQL</a> client tools are usually and should be installed with the server.</p>
<p>However, since <a href="http://launchpad.net/myconnpy">MySQL Connector/Python</a> only needs itself and Python, dependencies are reduced to a minimum. Here you&#8217;ll find a refactored version of Haidong&#8217;s version (can of course be made much more sophisticated) using the connector:</p>
<pre>
import sys
from socket import gethostname
import smtplib
import mysql.connector

emailSubject = &quot;Replication problem on slave %s&quot;
emailTo = &quot;recipient@example.com&quot;
emailFrom = &quot;monitor-tool@example.com&quot;

def runCmd(cmd):
    cnx = mysql.connector.connect(user='root',
                                  unix_socket='/path/to/mysql.sock')
    cur = cnx.cursor(buffered=True)
    cur.execute(cmd)
    columns = tuple( [d[0].decode('utf8') for d in cur.description] )
    row = cur.fetchone()
    if row is None:
        raise StandardError(&quot;MySQL Server not configured as Slave&quot;)
    result = dict(zip(columns, row))
    cur.close()
    cnx.close()
    return result

try:
    slave_status = runCmd(&quot;SHOW SLAVE STATUS&quot;)
except mysql.connector.Error, e:
    print &gt;&gt; sys.stderr, &quot;There was a MySQL error:&quot;, e
    sys.exit(1)
except StandardError, e:
    print &gt;&gt; sys.stderr, &quot;There was an error:&quot;, e
    sys.exit(1)

if (slave_status['Slave_IO_Running'] == 'Yes' and
    slave_status['Slave_SQL_Running'] == 'Yes' and
    slave_status['Last_Errno'] == 0):
    print &quot;Cool&quot;
else:
    emailBody = [
        &quot;From: %s&quot; % emailFrom,
        &quot;To: %s&quot; % emailTo,
        &quot;Subject: %s&quot; % (emailSubject %  gethostname()),
        &quot;&quot;,
        '\n'.join([ k + ' : ' + str(v) for k,v in slave_status.iteritems()]),
        &quot;\r\n&quot;,
        ]
    server = smtplib.SMTP(&quot;localhost&quot;)
    server.sendmail(emailFrom, [emailTo], '\r\n'.join(emailBody))
    server.quit()
</pre><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=27906&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=27906&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2011/04/07/refactored-poor-man%e2%80%99s-mysql-replication-monitoring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Connector/Python v0.3.1-devel released</title>
		<link>http://geert.vanderkelen.org/post/505/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-connectorpython-v0-3-1-devel-released</link>
		<comments>http://geert.vanderkelen.org/post/505/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 13:21:59 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://geert.vanderkelen.org/?p=505</guid>
		<description><![CDATA[MySQL Connector/Python 0.3.1, a development release, is available for download:
https://launchpad.net/myconnpy/+download
Disclaimer: Since version 0.3.1 is still a development release, or ‘alpha’, it is not
recommended to run this in production.
MySQL Connector/Python 0.3.1-devel is a maintenance release fixing following bugs:

lp:695514 &#8211; Infinite recursion when setting connection client_flags
lp:691836 &#8211; Incorrect substitution by cursor.execute when tuple args contains &#8216;%s&#8217;

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.4 and later as well as
Python v3.1 and later.]]></description>
			<content:encoded><![CDATA[<p><strong><a href="https://launchpad.net/myconnpy">MySQL Connector/Python</a> <a href="https://launchpad.net/myconnpy/0.3/0.3.1">0.3.1</a>, a development release</strong>, is available for download:<br />
<a href="https://launchpad.net/myconnpy/+download">https://launchpad.net/myconnpy/+download</a></p>
<p>Disclaimer: Since version 0.3.1 is still a development release, or ‘alpha’, it is not<br />
recommended to run this in production.</p>
<p>MySQL Connector/Python 0.3.1-devel is a maintenance release <strong>fixing following bugs</strong>:</p>
<ul>
<li><a href="https://launchpad.net/bugs/695514">lp:695514</a> &#8211; Infinite recursion when setting connection client_flags</li>
<li><a href="https://launchpad.net/bugs/691836">lp:691836</a> &#8211; Incorrect substitution by cursor.execute when tuple args contains &#8216;%s&#8217;</li>
</ul>
<p><strong>About MySQL Connector/Python</strong>: MySQL Connector/Python is implementing the<br />
MySQL Client/Server protocol completely in Python. No MySQL libraries<br />
are needed, and no compilation is necessary to run this Python DB API v2.0<br />
compliant driver. It is compatible with Python v2.4 and later as well as<br />
Python v3.1 and later.</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26940&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26940&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2011/01/07/mysql-connectorpython-v0-3-1-devel-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Settings client flags with MySQL Connector/Python</title>
		<link>http://geert.vanderkelen.org/post/488/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=settings-client-flags-with-mysql-connectorpython</link>
		<comments>http://geert.vanderkelen.org/post/488/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 11:06:09 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://geert.vanderkelen.org/?p=488</guid>
		<description><![CDATA[Setting client flags with MySQL Connector/Python works a bit differently than the other MySQL Python drivers. This blog post describes how to set and unset flags, like the CLIENT_FOUND_ROWS.
The default client flags for the MySQL Client/Server protocol can be retrieved using the constants.ClientFlag class:

&#62;&#62;&#62; from mysql.connector.constants import ClientFlag
&#62;&#62;&#62; defaults = ClientFlag.get_default()
&#62;&#62;&#62; print ClientFlag.get_bit_info(defaults)
['SECURE_CONNECTION', 'TRANSACTIONS', 'CONNECT_WITH_DB',
 'PROTOCOL_41', 'LONG_FLAG', 'MULTI_RESULTS',
 'MULTI_STATEMENTS', 'LONG_PASSWD']

To set an extra flag when connecting to MySQL you use the client_flags argument of connect()-method. For example, you&#8217;d like to have the CLIENT_FOUND_ROWS set:

import mysql.connector
from mysql.connector.constants import ClientFlag
extra_flags = [ClientFlag.FOUND_ROWS]
cnx = mysql.connector.connect(client_flags=extra_flags)

Similar, you can unset a flag passing a list of negative values, or all at the same time. For example, you&#8217;d like the CLIENT_FOUND_ROWS set, but you don&#8217;t want CLIENT_MULTI_STATEMENTS:

import mysql.connector
from mysql.connector.constants import ClientFlag
extra_flags = [ClientFlag.FOUND_ROWS, -ClientFlag.MULTI_STATEMENTS]
cnx = mysql.connector.connect(client_flags=extra_flags)

It is also possible to pass the client_flags an integer, but you need to get first the defaults, and do bitwise operations to set/unset flags yourself. At the moment of writing, there is a bug about this, see lp:695514, but I recommend using the list-method.]]></description>
			<content:encoded><![CDATA[<p>Setting <a href="http://dev.mysql.com/doc/refman/5.1/en/mysql-real-connect.html">client flags</a> with <a href="https://launchpad.net/myconnpy">MySQL Connector/Python</a> works a bit differently than the other MySQL Python drivers. This blog post describes how to set and unset flags, like the <tt>CLIENT_FOUND_ROWS</tt>.</p>
<p>The <strong>default client flags</strong> for the MySQL Client/Server protocol can be retrieved using the <tt>constants.ClientFlag</tt> class:</p>
<pre>
&gt;&gt;&gt; from mysql.connector.constants import ClientFlag
&gt;&gt;&gt; defaults = ClientFlag.get_default()
&gt;&gt;&gt; print ClientFlag.get_bit_info(defaults)
['SECURE_CONNECTION', 'TRANSACTIONS', 'CONNECT_WITH_DB',
 'PROTOCOL_41', 'LONG_FLAG', 'MULTI_RESULTS',
 'MULTI_STATEMENTS', 'LONG_PASSWD']
</pre>
<p><strong>To set an extra flag</strong> when connecting to MySQL you use the <tt>client_flags</tt> argument of <tt>connect()</tt>-method. For example, you&#8217;d like to have the <tt>CLIENT_FOUND_ROWS</tt> set:</p>
<pre>
import mysql.connector
from mysql.connector.constants import ClientFlag
extra_flags = [ClientFlag.FOUND_ROWS]
cnx = mysql.connector.connect(client_flags=extra_flags)
</pre>
<p>Similar, you can<strong> unset a flag</strong> passing a list of negative values, or all at the same time. For example, you&#8217;d like the <tt>CLIENT_FOUND_ROWS</tt> set, but you don&#8217;t want <tt>CLIENT_MULTI_STATEMENTS</tt>:</p>
<pre>
import mysql.connector
from mysql.connector.constants import ClientFlag
extra_flags = [ClientFlag.FOUND_ROWS, -ClientFlag.MULTI_STATEMENTS]
cnx = mysql.connector.connect(client_flags=extra_flags)
</pre>
<p>It is also possible to pass the <tt>client_flags</tt> an integer, but you need to get first the defaults, and do bitwise operations to set/unset flags yourself. At the moment of writing, there is a bug about this, see <a href="https://bugs.launchpad.net/myconnpy/+bug/695514">lp:695514</a>, but I recommend using the list-method.</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26915&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26915&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2011/01/05/settings-client-flags-with-mysql-connectorpython/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Connector/Python 0.3.0 has been released!</title>
		<link>http://geert.vanderkelen.org/post/435/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mysql-connectorpython-0-3-0-has-been-released</link>
		<comments>http://geert.vanderkelen.org/post/435/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 11:49:20 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://geert.vanderkelen.org/?p=435</guid>
		<description><![CDATA[MySQL Connector/Python 0.3.0, a development release, is available for download:
 https://launchpad.net/myconnpy/+download
Since version 0.3.0 is still a development release, or &#8216;alpha&#8217;, it is not
recommended to run this in production.
MySQL Connector/Pyhton 0.3.0 adds following features:

Python v2.4 support is back.
Support for compressed protocol.
Support for SSL connections (when Python&#8217;s ssl module is available).
Support for packets which are bigger than 16MB.
Max allowed packetsize defaults to 1GB.
Some performance improvements.

See the ChangeLog for extra details.
Please report bugs and comments using the bug tracker on Launchpad:
 https://bugs.launchpad.net/myconnpy
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.4 and later as well as
Python v3.1 and later.]]></description>
			<content:encoded><![CDATA[<p><strong><a href="http://launchpad.net/myconnpy">MySQL Connector/Python</a> 0.3.0, a development release</strong>, is available for download:<br />
 <a href="https://launchpad.net/myconnpy/+download">https://launchpad.net/myconnpy/+download</a></p>
<p>Since version 0.3.0 is still a development release, or &#8216;alpha&#8217;, it is not<br />
recommended to run this in production.</p>
<p>MySQL Connector/Pyhton <strong>0.3.0 adds following features</strong>:</p>
<ul>
<li>Python v2.4 support is back.</li>
<li>Support for compressed protocol.</li>
<li>Support for SSL connections (when Python&#8217;s ssl module is available).</li>
<li>Support for packets which are bigger than 16MB.</li>
<li>Max allowed packetsize defaults to 1GB.</li>
<li>Some performance improvements.</li>
</ul>
<p>See the <a href="https://launchpad.net/myconnpy/0.3/0.3.0">ChangeLog</a> for extra details.</p>
<p>Please report bugs and comments using the bug tracker on Launchpad:<br />
 <a href="https://bugs.launchpad.net/myconnpy">https://bugs.launchpad.net/myconnpy</a></p>
<p><strong>About MySQL Connector/Python</strong>: MySQL Connector/Python is implementing the<br />
MySQL Client/Server protocol completely in Python. No MySQL libraries<br />
are needed, and no compilation is necessary to run this Python DB API v2.0<br />
compliant driver. It is compatible with Python v2.4 and later as well as<br />
Python v3.1 and later.</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26704&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26704&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/12/10/mysql-connectorpython-0-3-0-has-been-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Query caching with MySQL Connector/Python</title>
		<link>http://geert.vanderkelen.org/post/412/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=query-caching-with-mysql-connectorpython</link>
		<comments>http://geert.vanderkelen.org/post/412/#comments</comments>
		<pubDate>Mon, 22 Nov 2010 20:53:50 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://geert.vanderkelen.org/?p=412</guid>
		<description><![CDATA[This blog post shows how to create a cursor class for MySQL Connector/Python which will allow you to cache queries. It will hold the query itself and the result in a global variable.
Note: this is a proof of concept and is only meant as a demonstration on how to extend MySQL Connector/Python.
Why query caching?
You are doing lots of queries that have the same result. It would be expensive to always run the same exact query. MySQL has already a query cache, and there is also memcached. But you like MySQL Connector/Python so much you&#8217;d like to do it yourself.
A cursor caching queries and their result
To demonstrate a simple implementation of a query cache, we inherit from an existing class: MySQLCursorBuffered. It will save the executed operation with their results in a &#8216;global&#8217; variable. We call this cursor MySQLCursorQueryCache.
We take the buffered cursor because we&#8217;d like to save the result right away. Below you see we only changed two methods for MySQLCursorBuffered:

.execute(): it will now first check using an md5 checksum whether we executed the query before. If we did, we set the make the cached result active. If not, we simply executed.
._handle_resultset(): called when .execute() did an operation which has a result set. The result we know save in the QUERY_CACHE global dict.


from hashlib import md5
import mysql.connector

QUERY_CACHE = dict()

class MySQLCursorQueryCache(mysql.connector.cursor.MySQLCursorBuffered):
    def execute(self, operation, params=None):
        self._qmd5 = md5(operation).digest()
        if QUERY_CACHE.has_key(self._qmd5):
            (self._rows, eof) = QUERY_CACHE[self._qmd5]
            self.rowcount = len(self._rows)
            self._handle_eof(eof)
            self._next_row = 0
        else:
            super(MySQLCursorQCache, self).execute(operation, params)

    def _handle_resultset(self):
        (self._rows, eof) = self.db().protocol.get_rows()
        self.rowcount = len(self._rows)
        self._handle_eof(eof)
        self._next_row = 0
        QUERY_CACHE[self._qmd5] = (self._rows, eof)
        try:
            self.db().unread_result = False
        except:
            pass
        self._qmd5 = None

The above code is a proof of concept, there is lots of room for improvement. For example, you need something to invalidate entries in the query cache.
How to use MySQLCursorQueryCache

def main():

    cnx = mysql.connector.connect(database='test')
    cur = cnx.cursor(cursor_class=MySQLCursorQueryCache)

    cur.execute("SELECT NOW()")
    print cur.fetchone()
    time.sleep(2)
    cur.execute("SELECT NOW()")
    print cur.fetchone()

    cur.close()
    cnx.close()

When you would use the default cursor, both executed SQL statements would produce a different result. The above produces the following output:

(datetime.datetime(2010, 11, 22, 21, 20, 4),)
(datetime.datetime(2010, 11, 22, 21, 20, 4),)

When you&#8217;d like to have some statements cached, and some not, just create a second cursor cursor_class=MySQLCursorBuffered (see Buffering results with MySQL Connector/Python).]]></description>
			<content:encoded><![CDATA[<p>This blog post shows how to create a cursor class for <a href="http://launchpad.net/myconnpy">MySQL Connector/Python</a> which will allow you to cache queries. It will hold the query itself and the result in a global variable.</p>
<p><strong>Note</strong>: this is a <strong>proof of concept</strong> and is only meant as a demonstration on how to extend MySQL Connector/Python.</p>
<h3>Why query caching?</h3>
<p>You are doing lots of queries that have the same result. It would be expensive to always run the same exact query. MySQL has already a <a href="http://dev.mysql.com/doc/refman/5.1/en/query-cache.html">query cache</a>, and there is also <a href="http://www.memcached.org/">memcached</a>. But you like MySQL Connector/Python so much you&#8217;d like to do it yourself.</p>
<h3>A cursor caching queries and their result</h3>
<p>To demonstrate a simple implementation of a query cache, we inherit from an existing class: <tt>MySQLCursorBuffered</tt>. It will save the executed operation with their results in a &#8216;global&#8217; variable. We call this cursor <tt>MySQLCursorQueryCache</tt>.</p>
<p>We take the buffered cursor because we&#8217;d like to save the result right away. Below you see we only changed two methods for <tt>MySQLCursorBuffered</tt>:</p>
<ul>
<li><tt>.execute()</tt>: it will now first check using an <i>md5 checksum</i> whether we executed the query before. If we did, we set the make the cached result active. If not, we simply executed.</li>
<li><tt>._handle_resultset()</tt>: called when <tt>.execute()</tt> did an operation which has a result set. The result we know save in the <tt>QUERY_CACHE</tt> global <tt>dict</tt>.</li>
</ul>
<pre>
from hashlib import md5
import mysql.connector

QUERY_CACHE = dict()

class MySQLCursorQueryCache(mysql.connector.cursor.MySQLCursorBuffered):
    def execute(self, operation, params=None):
        self._qmd5 = md5(operation).digest()
        if QUERY_CACHE.has_key(self._qmd5):
            (self._rows, eof) = QUERY_CACHE[self._qmd5]
            self.rowcount = len(self._rows)
            self._handle_eof(eof)
            self._next_row = 0
        else:
            super(MySQLCursorQCache, self).execute(operation, params)

    def _handle_resultset(self):
        (self._rows, eof) = self.db().protocol.get_rows()
        self.rowcount = len(self._rows)
        self._handle_eof(eof)
        self._next_row = 0
        QUERY_CACHE[self._qmd5] = (self._rows, eof)
        try:
            self.db().unread_result = False
        except:
            pass
        self._qmd5 = None
</pre>
<p>The above code is a <i>proof of concept</i>, there is lots of room for improvement. For example, you need something to invalidate entries in the query cache.</p>
<h3>How to use MySQLCursorQueryCache</h3>
<pre>
def main():

    cnx = mysql.connector.connect(database='test')
    <strong>cur = cnx.cursor(cursor_class=MySQLCursorQueryCache)</strong>

    cur.execute("SELECT NOW()")
    print cur.fetchone()
    time.sleep(2)
    cur.execute("SELECT NOW()")
    print cur.fetchone()

    cur.close()
    cnx.close()
</pre>
<p>When you would use the default cursor, both executed SQL statements would produce a different result. The above produces the following output:</p>
<pre>
(datetime.datetime(2010, 11, 22, 21, 20, 4),)
(datetime.datetime(2010, 11, 22, 21, 20, 4),)
</pre>
<p>When you&#8217;d like to have some statements cached, and some not, just create a second cursor <tt>cursor_class=MySQLCursorBuffered</tt> (<a href="http://geert.vanderkelen.org/post/388/">see Buffering results with MySQL Connector/Python</a>).</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26543&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26543&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/11/22/query-caching-with-mysql-connectorpython/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Buffering results with MySQL Connector/Python</title>
		<link>http://geert.vanderkelen.org/post/388/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=buffering-results-with-mysql-connectorpython</link>
		<comments>http://geert.vanderkelen.org/post/388/#comments</comments>
		<pubDate>Sun, 21 Nov 2010 22:54:27 +0000</pubDate>
		<dc:creator>Geert Vanderkelen</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[myconnpy]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://geert.vanderkelen.org/?p=388</guid>
		<description><![CDATA[MySQL Connector/Python doesn&#8217;t buffer results by default. This means you have to fetch the rows when you issued a SELECT. This post describes how you can change this behavior.
Why buffering result sets?
Buffering or storing the result set on the client side is handy when you, for example, would like to use multiple cursors per connection and you&#8217;de like to traverse each one interleaved.
Keep in mind that with bigger result sets, the client side will use more memory. You just need to find out for yourself what&#8217;s best. When you know result sets are mostly small, you might opt to buffer.
MySQLdb by default buffers results and you need to use a different cursor to disable it. oursql does not buffer by default. This is good to know when you start using a different MySQL DB API for Python.
Use case: 1 connection, fetch from 2 cursors
You want to fetch data from two tables and process the data using one connection. If you do it without buffering, you would run into the following:

&#62;&#62;&#62; cnx = mysql.connector.connect(database='test')
&#62;&#62;&#62; cur1 = cnx.cursor()
&#62;&#62;&#62; cur2 = cnx.cursor()
&#62;&#62;&#62; cur1.execute("SELECT c1 FROM t1")
-1
&#62;&#62;&#62; cur2.execute("SELECT c1 FROM t1")
..
mysql.connector.errors.InternalError: Unread result found.

MySQL Connector/Python offers two ways to turn buffering on or off. Either per connection or per cursor using the buffered argument set to True
Set buffering per connection
If you want all the cursors for a particular connection to be buffered, you can turn it on when connecting to MySQL setting the buffered-argument to True.

&#62;&#62;&#62; import mysql.connector
&#62;&#62;&#62; cnx = mysql.connector.connect(database='test',buffered=True)
&#62;&#62;&#62; cur1 = cnx.cursor()
&#62;&#62;&#62; cur1.__class__

&#62;&#62;&#62; cur2 = cnx.cursor()
&#62;&#62;&#62; cur1.execute("SELECT c1 FROM t1")
3
&#62;&#62;&#62; cur2.execute("SELECT c1 FROM t1")
3
&#62;&#62;&#62; cur1.fetchone()
(u'Geert',)
&#62;&#62;&#62; cur2.fetchone()

Set buffering per cursor
You can request a buffering cursor buffering from the connection object. Do this use the buffered-argument set to True:

&#62;&#62;&#62; import mysql.connector
&#62;&#62;&#62; cnx = mysql.connector.connect(database='test')
&#62;&#62;&#62; cur1 = cnx.cursor(buffered=True)
&#62;&#62;&#62; cur1.__class__


Note: the above should work with MySQL Connector/Python v0.2 or greater]]></description>
			<content:encoded><![CDATA[<p><a href="https://launchpad.net/myconnpy">MySQL Connector/Python</a> doesn&#8217;t buffer results by default. This means you have to fetch the rows when you issued a <tt>SELECT</tt>. This post describes how you can change this behavior.</p>
<h3>Why buffering result sets?</h3>
<p>Buffering or storing the result set on the client side is handy when you, for example, would like to use multiple cursors per connection and you&#8217;de like to traverse each one interleaved.</p>
<p>Keep in mind that with bigger result sets, the client side will use more memory. You just need to find out for yourself what&#8217;s best. When you know result sets are mostly small, you might opt to buffer.</p>
<p><a href="http://mysql-python.sourceforge.net/">MySQLdb</a> by default buffers results and you need to use a different cursor to disable it. <a href="https://launchpad.net/oursql">oursql</a> does not buffer by default. This is good to know when you start using a different MySQL DB API for Python.</p>
<h3>Use case: 1 connection, fetch from 2 cursors</h3>
<p>You want to fetch data from two tables and process the data using one connection. If you do it without buffering, you would run into the following:</p>
<pre>
>>> cnx = mysql.connector.connect(database='test')
>>> cur1 = cnx.cursor()
>>> cur2 = cnx.cursor()
>>> cur1.execute("SELECT c1 FROM t1")
-1
>>> cur2.execute("SELECT c1 FROM t1")
..
<strong>mysql.connector.errors.InternalError: Unread result found.</strong>
</pre>
<p>MySQL Connector/Python offers two ways to turn buffering on or off. Either per connection or per cursor using the <tt>buffered</tt> argument set to <tt>True</tt></p>
<h3>Set buffering per connection</h3>
<p>If you want all the cursors for a particular connection to be buffered, you can turn it on when connecting to MySQL setting the <tt>buffered</tt>-argument to <tt>True</tt>.</p>
<pre>
>>> import mysql.connector
>>> <strong>cnx = mysql.connector.connect(database='test',buffered=True</strong>)
>>> cur1 = cnx.cursor()
>>> cur1.__class__
<class 'mysql.connector.cursor.MySQLCursorBuffered'>
>>> cur2 = cnx.cursor()
>>> cur1.execute("SELECT c1 FROM t1")
3
>>> cur2.execute("SELECT c1 FROM t1")
3
>>> cur1.fetchone()
(u'Geert',)
>>> cur2.fetchone()
</pre>
<h3>Set buffering per cursor</h3>
<p>You can request a buffering cursor buffering from the connection object. Do this use the <tt>buffered</tt>-argument set to <tt>True</tt>:</p>
<pre>
>>> import mysql.connector
>>> cnx = mysql.connector.connect(database='test')
>>> <strong>cur1 = cnx.cursor(buffered=True)</strong>
>>> cur1.__class__
<class 'mysql.connector.cursor.MySQLCursorBuffered'>
</pre>
<p><i>Note: the above should work with MySQL Connector/Python v0.2 or greater</i></p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26522&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26522&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/11/22/buffering-results-with-mysql-connectorpython/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

