Showing entries 31 to 40 of 69
« 10 Newer Entries | 10 Older Entries »
Displaying posts with tag: myconnpy (reset)
Fetching rows as dictionaries with MySQL Connector/Python (revised)

It is possible with MySQL Connector/Python to define your own cursor classes. A very good use case is to return rows as dictionary instead of tuples. This post shows how to do this using MySQL Connector/Python v1.0 and is an update for an older blog entry.

In the example below we are subclassing the MySQLCursor class to create a new class called MySQLCursorDict. We change the _row_to_python() method to return a dictionary instead of a tuple. The keys of the dictionary will be (unicode) column names.

from pprint import pprint
import mysql.connector

class MySQLCursorDict(mysql.connector.cursor.MySQLCursor):
    def _row_to_python(self, rowdata, desc=None):
        row = super(MySQLCursorDict, self)._row_to_python(rowdata, desc)
        if …
[Read more]
MySQL Connector/Python Launchpad entry updated

We finally got the MySQL Connector/Python repositories reorganised on Launchpad. The following changes have been made:

  • Old, unmaintained repositories have been marked as obsolete.
  • Downloadable source distributions of obsolete versions have been removed, use the MySQL download website.
  • Connector/Python v1.0 source has been uploaded to Launchpad up till v1.0.5b1.
  • URLs point to the MySQL website.
  • Maintainer is now ‘Oracle/MySQL Engineering’, the team I (Geert Vanderkelen) am part of.
MySQL Connector/Python 1.0.5 beta available through PyPI

Yesterday we announced the availability of MySQL Connector/Python v1.0.5 beta. Today I’ve made it available on PyPI so it can be easily installed. Note that I did remove the old development release and when you upgrade or try v1.0.5, you should check the ChangeLog.

shell> pip install mysql-connector-python

For those wondering why the name includes ‘python’: it’s just to align it with other MySQL connectors and to keep the name consistent with other distribution types.

We welcome and appreciate feedback and comments for this first beta release through the forum and the …

[Read more]
MySQL Connector/Python v1.0.5 beta available for download

MySQL Connector/Python v1.0.5 beta is now available for download from the MySQL website. This version is feature complete and we welcome and appreciate feedback and bug reports.

We’re also interested in hearing your feedback for future enhancements. Let us know how you’re using the connector too, especially if you are using it with Django, SQLAlchemy and similar Python technologies.

A few things have changed since the last development releases and we hope the manual shipping with the Connector/Python distribution (and also available online soon) will help you get up to speed.

Here are a few important changes that might be incompatible with current scripts using the now obsolete development releases v0.3.2 and …

[Read more]
Naming a Python package for distribution?

I’m currently figuring out how to name the MySQL Connector/Python distributions so it works well with PyPi. Source archives would be named like mysql-connector-python-X.Y.Z.tar.gz.

The ‘name’ metadata would be ‘MySQL Connector Python’, thus without any underscores or dashes. This works OK, but if people have objections, please leave a comment.

Invalid dates returning None, or raise error using Connector/Python?

In this blog we discuss invalid dates in MySQL, how to retrieve them using Connector/Python and we raise the question: Should Connector/Python raise an error or just keep returning None on invalid dates?

If you run MySQL without proper SQL Modes, you will be able to update and
read invalid dates such as ’2012-06-00′. If you’ve payed attention the past decade, you’ll know that you can prevent this configuring your MySQL server setting SQL Mode to ‘TRADITIONAL’.

Now, the problem if this is allowed, how do we get invalid dates using MySQL Connector/Python?

Lets look at an example inserting an invalid date and trying to read it again using MySQL Connector/Python:

>>> cur = …
[Read more]
MySQL Connector/Python bugs reports on bugs.mysql.com

We have moved bugs for MySQL Connector/Python from Launchpad to the MySQL Bugs website http://bugs.mysql.com. Reports which are (probably) fixed in newer code were not taken with. If there is a bug which you really want to get tracked: please report it again.

Please use the MySQL Bugs website to report problems using MySQL Connector/Python. To see a list of active reports, click here.

[Read more]
Automatic reconnect in MySQL Connector/Python?

There have been some request to have some reconnect possibilities in Connector/Python. I’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 > 0:
                tries -= 1
                try:
                        cursor.execute("INSERT INTO t1 (c1) VALUES ('ham')")
                        cnx.commit()
                except mysql.connector.InterfaceError:
                        if tries == 0:
                                print "Failed inserting data after retrying"
                                break
                        else:
                                print …
[Read more]
MySQL Connector/Python available through the Python Package Index

Today we registered MySQL Connector/Python with the Python Package Index (PyPI). It makes installing your favorite connector even easier (provided you first install setuptools or pip):

shell> easy_install mysql-connector
shell> pip install mysql-connector

Please report problems either using Launchpad or MySQL Bugs website.

[Read more]
MySQL Connector/Python bug category on bugs.mysql.com

In addition to reporting MySQL Connector/Python bugs on Launchpad, it is now also possible to enter them using http://bugs.mysql.com.

Showing entries 31 to 40 of 69
« 10 Newer Entries | 10 Older Entries »