Giter Site home page Giter Site logo

pymysql's Introduction

Documentation Status codecov

PyMySQL

This package contains a pure-Python MySQL client library, based on PEP 249.

Requirements

  • Python -- one of the following:
  • MySQL Server -- one of the following:

Installation

Package is uploaded on PyPI.

You can install it with pip:

$ python3 -m pip install PyMySQL

To use "sha256_password" or "caching_sha2_password" for authenticate, you need to install additional dependency:

$ python3 -m pip install PyMySQL[rsa]

To use MariaDB's "ed25519" authentication method, you need to install additional dependency:

$ python3 -m pip install PyMySQL[ed25519]

Documentation

Documentation is available online: https://pymysql.readthedocs.io/

For support, please refer to the StackOverflow.

Example

The following examples make use of a simple table

CREATE TABLE `users` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `email` varchar(255) COLLATE utf8_bin NOT NULL,
    `password` varchar(255) COLLATE utf8_bin NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
AUTO_INCREMENT=1 ;
import pymysql.cursors

# Connect to the database
connection = pymysql.connect(host='localhost',
                             user='user',
                             password='passwd',
                             database='db',
                             cursorclass=pymysql.cursors.DictCursor)

with connection:
    with connection.cursor() as cursor:
        # Create a new record
        sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
        cursor.execute(sql, ('[email protected]', 'very-secret'))

    # connection is not autocommit by default. So you must commit to save
    # your changes.
    connection.commit()

    with connection.cursor() as cursor:
        # Read a single record
        sql = "SELECT `id`, `password` FROM `users` WHERE `email`=%s"
        cursor.execute(sql, ('[email protected]',))
        result = cursor.fetchone()
        print(result)

This example will print:

{'password': 'very-secret', 'id': 1}

Resources

License

PyMySQL is released under the MIT License. See LICENSE for more information.

pymysql's People

Contributors

bbigras avatar boglin avatar cclauss avatar clarkevans avatar clelland avatar cleure avatar elemount avatar grooverdan avatar hannosch avatar jamadden avatar jcotton1123 avatar jvankoten avatar klondi avatar lecram avatar martinthoma avatar methane avatar mlongtin0 avatar nothing4you avatar petehunt avatar renovate[bot] avatar rfk avatar rjollos avatar timgates42 avatar urk avatar vtermanis avatar wiggzz avatar worldexception avatar wraziens avatar yoriksar avatar zzzeek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pymysql's Issues

Old-style MySQL passwords

Originally filed by quzhengping on 2010-04-21T11:02:13

What steps will reproduce the problem?

  1. connection to mysql db using passwd

What is the expected output? What do you see instead?
errno = 1156
Traceback (most recent call last):
File "memcon.py", line 123, in ?
check()
File "memcon.py", line 54, in check
sc=sqlcon.db()
File "/root/bpo_sprinkler/production/monitor/sqlcon.py", line 32, in init
self.conn = pymysql.connect(host=self.host,
unix_socket=self.unix_socket, user=self.user, passwd=self.passwd, db=self.db)
File "/root/bpo_sprinkler/production/monitor/pymysql/init.py", line
55, in Connect
return Connection(_args, *_kwargs)
File "/root/bpo_sprinkler/production/monitor/pymysql/connections.py",
line 344, in init
self.autocommit(False)
File "/root/bpo_sprinkler/production/monitor/pymysql/connections.py",
line 356, in autocommit
self.read_packet()
File "/root/bpo_sprinkler/production/monitor/pymysql/connections.py",
line 417, in read_packet
packet.check_error()
File "/root/bpo_sprinkler/production/monitor/pymysql/connections.py",
line 245, in check_error
raise_mysql_exception(self.__data)
File "/root/bpo_sprinkler/production/monitor/pymysql/exceptions.py", line
130, in raise_mysql_exception
_check_mysql_exception(errinfo)
File "/root/bpo_sprinkler/production/monitor/pymysql/exceptions.py", line
126, in _check_mysql_exception
raise InternalError, ""
pymysql.exceptions.InternalError

What version of the product are you using? On what operating system?
current version

Please provide any additional information below.

Connect( ) fails on server version 5.147

Originally filed by [email protected] on 2010-08-22T08:37:30

What steps will reproduce the problem?
pymysql.connect() on a 5.147 community build fails with an InternalError.

What version of the product are you using? On what operating system?
Using the latest 2.5 branch.

Please provide any additional information below.
Information was verified correct using MySQLWorkbench

Allocate a variable to return when the exception handler is permissive

Originally filed by [email protected] on 2010-02-18T11:28:28

What steps will reproduce the problem?

  1. conn.errorhandler = lambda cursor, errorclass, errorvalue: None
  2. cur.execute( "create table t( n int )" )
  3. cur.execute( "create table t( n int )" )

What is the expected output? What do you see instead?

Expected: The error on attempting to create an existing table should be
ignored.
Saw instead: An exception due to cursor.execute() returning a
non-allocated variable "result".

What version of the product are you using? On what operating system?
Trunk.

Please provide any additional information below.

I believe the variable was not allocated because the expected SQL exception
prevented from assigning to it.

--- pymysql/cursor.py (revision 4)
+++ pymysql/cursor.py (working copy)
@@ -73,6 +73,7 @@
if args is not None:
query = query % conn.escape(args)

  •    result = 0
     try:
         result = self._query(query)
     except:
    

Primary Key and Index error when selecting data

Originally filed by [email protected] on 2010-01-07T16:10:07

Thanks for this pure python MySQL client. Very useful.

What steps will reproduce the problem?

  1. Create this table :
    mysql> CREATE TABLE test (station int(10) NOT NULL DEFAULT '0', dh
    datetime NOT NULL DEFAULT '0000-00-00 00:00:00', echeance int(1) NOT NULL
    DEFAULT '0', me double DEFAULT NULL, mo double DEFAULT NULL, PRIMARY
    KEY (station,dh,echeance)) ENGINE=MyISAM DEFAULT CHARSET=latin1;
  2. Select data with python :

    conn = pymysql.connect(host="localhost", user="xxx", passwd="xxx",
    db="xxx")
    curs = conn.cursor()
    curs.execute("SELECT * FROM test")
    0

It's ok, no result returned.

  1. Alter table (add index) in MySQL :
    mysql> ALTER TABLE test ADD INDEX idx_station (station);

  2. Redo the step 2 to select data :

    curs.execute("SELECT * FROM test")
    Traceback (most recent call last):
    File "", line 1, in
    File
    "/usr/local/lib/python2.6/dist-packages/PyMySQL-0.2-py2.6.egg/pymysql/cursor.py",
    line 82, in execute
    File
    "/usr/local/lib/python2.6/dist-packages/PyMySQL-0.2-py2.6.egg/pymysql/connections.py",
    line 96, in defaulterrorhandler
    ValueError: invalid literal for int() with base 10: '00B'

What is the expected output? What do you see instead?
Expected 0 instead of an error.

What version of the product are you using? On what operating system?
Python 2.6.4, MySQL 5.1.37, Ubuntu 9.10

Please provide any additional information below.

query should be expanded before perform character encoding

Originally filed by [email protected] on 2010-04-07T15:42:22

What steps will reproduce the problem?

  1. insert some values with utf-8 encoding to a table
  2. UnicodeDecodeError found

What is the expected output? What do you see instead?
UnicodeDecodeError found

What version of the product are you using? On what operating system?
MacOS snow leopard

Please provide any additional information below.

Fix:

def execute(self, query, args=None):
    from sys import exc_info

    conn = self._get_db()
    charset = conn.charset
    del self.messages[:]

expand the query before perform character encoding

    if args is not None:
        query = query % conn.escape(args)
    if isinstance(query, unicode):
        query = query.encode(charset)

can't handle large result fields

Originally filed by [email protected] on 2010-04-05T19:54:11

What steps will reproduce the problem?

  1. issue a select query on a text field whose length is longer than a few thousand bytes. In my
    case, a text field of length 18K causes the two problems detailed below. I've not gone looking for
    the shortest field length that causes the bug, this may be installation dependent.

SYMPTOMS:
There are (at least) 2 bugs, with different symptoms.

  1. TypeError: unsupported operand type(s) for +: 'int' and 'tuple'
    This happens when the length is marker is UNSIGNED_SHORT_COLUMN in _get_field_length. To
    fix this,
    length = struct.unpack('<H', data[pos:pos+UNSIGNED_SHORT_LENGTH])
    should be:
    length = struct.unpack('<H', data[pos:pos+UNSIGNED_SHORT_LENGTH])[0]

  2. TypeError: ord() expected a character, but string of length 0 found
    This happens when the result is longer than the packet size being
    returned by mysql. (I'm not sure how that varies from installation to installation, so I won't be
    more specific). In my case, I have a text field of 18K chars, but the length of data returned by the
    socket.recv() call in _read_and_check_packet() is 4251 bytes. There's no logic to continue reading
    from the socket if the first recv() call does not get all the result bytes. The error occurs down in
    _read_rowdata_packet, because self.position is allowed to roll beyond the end of self.data

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?

Please provide any additional information below.

Jython support

Originally filed by [email protected] on 2009-07-23T21:06:30

What steps will reproduce the problem?

  1. I am on a ubuntu laptop with mysql-client-5.0 with Jython 2.5.0
  2. When I connect to the DB with:
    conn = pymysql.connect(host='127.0.0.1', user='myusr', passwd='mypass',
    db='mydb')
    I get:
    Traceback (most recent call last):
    File "", line 1, in
    File "pymysql/init.py", line 53, in Connect
    return Connection(_args, *_kwargs)
    File "pymysql/connections.py", line 118, in init
    self._connect()
    File "pymysql/connections.py", line 191, in _connect
    self._request_authentication()
    File "pymysql/connections.py", line 242, in _request_authentication
    self._send_authentication()
    File "pymysql/connections.py", line 264, in _send_authentication
    self._check_auth_packet(auth_msg)
    File "pymysql/connections.py", line 268, in _check_auth_packet
    self._check_error(recv_data)
    File "pymysql/connections.py", line 226, in _check_error
    raise_mysql_exception(recv_data)
    File "pymysql/exceptions.py", line 130, in raise_mysql_exception
    _check_mysql_exception(errinfo)
    File "pymysql/exceptions.py", line 126, in _check_mysql_exception
    raise InternalError, ""
    pymysql.exceptions.InternalError

What is the expected output? What do you see instead?
I expected the connection to be made.

What version of the product are you using? On what operating system?
I am using the SVN latest version

Please provide any additional information below.

packet header wasn't fully received.

Originally filed by [email protected] on 2010-02-19T16:39:11

I'm using this on a large amount of data, and ran into a problem on line
123 of connections.py

4 bytes requested, but fewer were received.

this was my fix (added after line 123:"packet_header = socket.recv(4)")

while len(packet_header) < 4:
    packet_header += socket.recv(4 - len(packet_header))

typo in converters.py

Originally filed by [email protected] on 2010-04-06T16:26:38

What steps will reproduce the problem?

  1. escape an int/long value with the escape_item(value) or
    escape_object(value) methods in pymysql.converters

print pymysql.converters.escape_item(1L)

What is the expected output? What do you see instead?

Expected output is 1

What I see instead:

File "build\bdist.win32\egg\pymysql\converters.py", line 11, in
escape_item
File "build\bdist.win32\egg\pymysql\converters.py", line 31, in
escape_object
NameError: global name 'val' is not defined

What version of the product are you using? On what operating system?

Revision 4 (from the SVN source) on Windows XP / Windows Web Server 2008 R2

Please provide any additional information below.

A typo exists in converters.py (line 31) within the escape_object(...)
method. Change 'val' to 'value'.

diff patch attached.

blobs exceeding 16M raises exceptions

Originally filed by [email protected] on 2010-09-09T17:45:21

What steps will reproduce the problem?

  1. Create a table holding a large blob value:

CREATE TABLE blob_test (
id int,
data mediumblob
);

  1. Insert a > 16M blob

    import MySQLdb
    connection = MySQLdb.connect(user='root')
    cursor = connection.cursor()
    datum = 'a'_1024_1024*64
    cursor.execute('INSERT INTO test.blob_test VALUES (1, %s)', datum)
    1L

  2. Try to select using pymysql

    import pymysql
    connection = pymysql.connect(user='root')
    cursor = connection.cursor()
    cursor.execute('select * from test.blob_test')
    Traceback (most recent call last):
    File "", line 1, in
    File "pymysql/cursors.py", line 102, in execute
    self.errorhandler(self, exc, value)
    File "pymysql/connections.py", line 173, in defaulterrorhandler
    raise Error(errorclass, errorvalue)
    pymysql.err.Error: (<type 'exceptions.AssertionError'>, AssertionError('Result length not requested length:\nExpected=16777215. Actual=16777209. Position: 6. Data Length: 16777215',))

What is the expected output? What do you see instead?

Expected:

cursor.execute('select * from test.blob_test')
1L

Actual:

cursor.execute('select * from test.blob_test')
Traceback (most recent call last):
File "", line 1, in
File "pymysql/cursors.py", line 102, in execute
self.errorhandler(self, exc, value)
File "pymysql/connections.py", line 173, in defaulterrorhandler
raise Error(errorclass, errorvalue)
pymysql.err.Error: (<type 'exceptions.AssertionError'>, AssertionError('Result length not requested length:\nExpected=16777215. Actual=16777209. Position: 6. Data Length: 16777215',))

What version of the product are you using? On what operating system?
pymysql r35 using python2.6.4 on fedora13 with mysql 5.1.48

Please provide any additional information below.

Sending large blobs also fails:

import pymysql
connection = pymysql.connect(user='root')
cursor = connection.cursor()
datum = 'a'_1024_1024*64
cursor.execute('INSERT INTO test.blob_test VALUES (1, %s)', datum)
Traceback (most recent call last):
File "", line 1, in
File "pymysql/cursors.py", line 102, in execute
self.errorhandler(self, exc, value)
File "pymysql/connections.py", line 175, in defaulterrorhandler
raise errorclass, errorvalue
pymysql.err.InternalError: (1156, u'Got packets out of order')

Python 3 support

Originally filed by [email protected] on 2010-06-08T09:31:41

What steps will reproduce the problem?

  1. Download subversion read-only copy
  2. Run \python31\python setup.py install

What is the expected output? What do you see instead?

I expected the program to install. Saw:

C:\Users\sholden\pymysql-read-only>\python31\python setup.py install
Traceback (most recent call last):
File "setup.py", line 4, in
version_tuple = import('pymysql').VERSION
File "C:\Users\sholden\pymysql-read-only\pymysql__init__.py", line 5, in
from pymysql.converters import escape_dict, escape_sequence, escape_string
File "C:\Users\sholden\pymysql-read-only\pymysql\converters.py", line 214, in

long: escape_object,
NameError: name 'long' is not defined

What version of the product are you using? On what operating system?

V 0.2 on Windows Vista with Python 3.1.

Please provide any additional information below.

Nothing else to add, but I thought I remembered reading that pymysql qas available for 3.1 - was I mistaken?

Can't retrieve TIMESTAMP fields

Originally filed by [email protected] on 2009-08-04T23:50:08

What steps will reproduce the problem?

  1. select a TIMESTAMP field from a table row

What is the expected output? What do you see instead?
Expected a formatted datetime value. Instead, connections.py raises
ValueError: invalid literal for int(): E1

What version of the product are you using? On what operating system?
pymysql 0.2 on python 2.4.4 connecting to mysql 5.0.51b

undefined methods datetime_or_None, date_or_None

Originally filed by [email protected] on 2009-07-25T22:20:52

What steps will reproduce the problem?

  1. retrieve a date/time-related field having a value of None (or an invalid value)

What is the expected output? What do you see instead?
Exception raised for undefined method datetime_or_None or date_or_None

What version of the product are you using? On what operating system?

Please provide any additional information below.
Appears that during a wholesale renaming of converter methods, a few got left behind. Corrected
version of converters.py is attached.

Comprehensive test suite

Originally filed by [email protected] on 2010-07-26T19:52:30

PyMySQL currently relies on the Django, MySQLdb, and a private, hacked MySQL Connector/Python test suite. It should really have its own set of comprehensive tests.

Backport unicode features from Py3k branch

Originally filed by [email protected] on 2010-08-03T14:04:32

In the course of implementing the Py3k branch I noticed that there are several places where I should be doing an explicit decode from the charset. This has not shown up in any test case, and likely will not ever show up since SQL keywords and server version information are just straight ASCII, however, it "should" be fixed at some point. Just doing a diff between the two branches and searching for encode() and decode() should be enough of an indicator.

sets DeprecationWarning in Python 2.6

Originally filed by [email protected] on 2010-01-11T03:48:27

When importing an svn build of pymysql, I get the following error on Python 2.6 (OSX):

DeprecationWarning: the sets module is deprecated
files listed as 'execfile ='.

This does not occur in the release version.

pymysql.connect(..., charset='utf8') fails to set charset correctly

Originally filed by [email protected] on 2010-09-04T07:16:11

What steps will reproduce the problem?

  1. use the charset='utf8' parameter when connecting with pymysql
  2. read a resultset with utf8 data

What is the expected output? What do you see instead?
Expected utf8 decoded data but got '????' instead.

What version of the product are you using? On what operating system?

python -V

Python 2.3.4

python

import pymysql
pymysql.VERSION
(0, 3, None)
$ cat /etc/redhat-release
Red Hat Enterprise Linux ES release 4 (Nahant Update 8)

Please provide any additional information below.

Used the following script to test utf8 encoded database names on 5.0.91 on rhel4:

!/usr/bin/env python

import pprint
import pymysql

c = pymysql.connect(user='root', passwd='P@$$w0RD#', port=3307, charset='utf8')
z = c.cursor()
z.execute('SHOW DATABASES')

pprint.pprint([db for db in z])

The problem appears to be in pymysql/connections.py:set_charset_set, as self.charset always == charset in this case. As a workaround, I could just use a separate set_charset_set to switch from latin1 -> utf8 that would work, but I was testing pymysql as a replacement for MySQLdb and didn't want to change all the code that used charset='utf8' :)

I used the following hastily constructed patch, but there are probably better solutions:

--- a/pymysql/connections.py
+++ b/pymysql/connections.py
@@ -582,7 +582,7 @@ class Connection(object):
def set_charset_set(self, charset):
try:
sock = self.socket

  •        if charset and self.charset != charset:
    
  •        if charset:
             self._execute_command(COM_QUERY, "SET NAMES %s" %
                                   self.escape(charset))
             self.read_packet()
    

PyMySQL does not intepret unicode data the same as MySQLdb

Originally filed by [email protected] on 2010-12-27T21:36:13

I understand one of the goals of PyMySQL is to be 100% compatible with MySQLdb. If this is the case, attached is a test program which fails for PyMySQL, comparing the results to those of MySQLdb:

coding: utf-8

import MySQLdb
import pymysql

def test(conn, encode):
cur = conn.cursor()

unicodedata = u"Alors vous imaginez ma surprise, au lever du jour, quand "\
                u"une drôle de petite voix m’a réveillé. "\
                u"Elle disait: « S’il vous plaît… dessine-moi un mouton! »"

if encode:
    cur.execute("SELECT %s", unicodedata.encode('utf-8'))
    assert cur.fetchone()[0] == unicodedata.encode('utf-8')
else:
    cur.execute("SELECT %s", unicodedata)
    assert cur.fetchone()[0] == unicodedata

for dialect in (MySQLdb, pymysql):
for encode in (False, True):

    conn = dialect.connect(host='127.0.0.1', user='scott', passwd='tiger', db='test', use_unicode=not encode, charset='utf8')
    try:
        print "Testing dialect", dialect, "applying manual encoding:", encode
        test(conn, encode)
        print "Passed."
    except Exception, e:
        print "Failed: ", e

output:

Testing dialect <module 'MySQLdb' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.5-fat3.egg/MySQLdb/init.pyc'> applying manual encoding: False
Passed.
Testing dialect <module 'MySQLdb' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.5-fat3.egg/MySQLdb/init.pyc'> applying manual encoding: True
Passed.
Testing dialect <module 'pymysql' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymysql/init.pyc'> applying manual encoding: False
Passed.
Testing dialect <module 'pymysql' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pymysql/init.pyc'> applying manual encoding: True
test.py:16: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
assert cur.fetchone()[0] == unicodedata.encode('utf-8')
Failed:

MySQLdb compliance

Originally filed by [email protected] on 2010-12-10T09:57:37

PyMySQL gets everyday closer to being a perfect drop-in replacement for MySQLdb, but there are places where we could improve on MySQLdb's behaviour.

I propose we introduce a new connection flag (e.g. mysqldb_mode) that would initially default to True to be able to diverge from MySQLdb's behavior when we require it.

"No database selected" on Jython

Originally filed by [email protected] on 2010-07-27T18:54:55

What steps will reproduce the problem?

  1. Run examples under Jython 2.2.1 or 2.5.1 (Ubuntu 10)

What is the expected output? What do you see instead?

Expected output is a list of users and hosts. Actual output is an InternalError: (1046, u"No database selected")

Please use labels and text to provide additional information.

cursor.execute() loops indefinitely when connection unexpectedly lost

Originally filed by [email protected] on 2010-09-04T20:17:32

What steps will reproduce the problem?

  1. Start a long running query
  2. Make mysql crash
  3. Watch pymysql loop infinitely

What is the expected output? What do you see instead?

Expected:
OperationalError: (2013, 'Lost connection to MySQL server during query')

Actual behavior (from strace):
...
recvfrom(3, "", 4, 0, NULL, NULL) = 0
recvfrom(3, "", 4, 0, NULL, NULL) = 0
recvfrom(3, "", 4, 0, NULL, NULL) = 0
recvfrom(3, "", 4, 0, NULL, NULL) = 0
...

What version of the product are you using? On what operating system?
Using latest pymysql svn checkout on rhel5 w/ python2.6 from EPEL.

Please provide any additional information below.

query on information_schema.tables fails

Originally filed by [email protected] on 2009-11-17T19:17:40

What steps will reproduce the problem?

  1. select * from information_schema.tables

What is the expected output? What do you see instead?

con.get_server_info()
'5.1.37-2'
cur.execute('select * from information_schema.tables')
Traceback (most recent call last):
File "", line 1, in
File
"/home/randall/.local/lib/python2.6/site-packages/PyMySQL-0.2-py2.6.egg/pymysql/cursor.py",
line 82, in execute
self.errorhandler(self, exc, value)
File
"/home/randall/.local/lib/python2.6/site-packages/PyMySQL-0.2-py2.6.egg/pymysql/connections.py",
line 96, in defaulterrorhandler
raise errorclass, errorvalue
TypeError: ord() expected a character, but string of length 0 found

support Connection.kill()

Originally filed by [email protected] on 2010-09-07T16:11:38

This is just a feature request for parity with MySQLdb, as I (and I suspect others) have this behavior builtin to a few DBA scripts.

I've attached a patch for an initial implementation.

Add display size field to descriptor tuple.

Originally filed by [email protected] on 2010-08-03T14:05:57

For now, the description tuple does conform to the DB-API 2.0 spec, however, the display size field is currently missing (None), whereas in MySQLdb it is present. So far this has not affected a single test case, so it is low-priority.

named_pipe support

Originally filed by [email protected] on 2010-08-03T15:31:06

ssl, read_default_group, compress named_pipe are passed to connect() and raise NotImplementedError currently.

[PATCH] SQLAlchemy test suite compliance

Originally filed by [email protected] on 2010-12-06T19:57:24

Hi,

The attached patch makes PyMySQL pass SQLAlchemy's test suite in the exact same way MySQLdb does.

Here are the main changes:

  • proper big packet handling (i.e. our previous patch)
  • charsets/unicode cleanup
  • proper MySQL SET support
  • BIT type handling aligned with MySQLdb
  • length coded binary/string disambiguation
  • using a connection after it's close()d raises an exception (DB-API)

We also attach the path to SQLAlchemy to properly support the PyMySQL dialect.

"No database selected" on Jython

Originally filed by [email protected] on 2010-07-27T18:54:55

What steps will reproduce the problem?

  1. Run examples under Jython 2.2.1 or 2.5.1 (Ubuntu 10)

What is the expected output? What do you see instead?

Expected output is a list of users and hosts. Actual output is an InternalError: (1046, u"No database selected")

Please use labels and text to provide additional information.

nextset test case fails

Originally filed by [email protected] on 2010-08-04T14:31:34

What steps will reproduce the problem?

  1. Run the test suite

What is the expected output? What do you see instead?
I want it to not fail, but it does.

Please use labels and text to provide additional information.

help/contact/forum

Originally filed by [email protected] on 2009-12-07T22:42:54

is there a contact list to ask questions? i can't seem to find one.

the question i have is:
is the intent to have the same interface as provided by mysqldb? if so that
would be awesome (then clients could migrate just by changing important and
an initialization and not have to worry about other code changes).

cheers.

wish you can maintain a Wiki

Originally filed by thinke365 on 2009-06-26T20:22:01

haha, This can be a promising project which still have quit long way to go.

[PATCH] Fix regression in r

Originally filed by [email protected] on 2010-12-10T09:10:58

What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?

Please provide any additional information below.

wish you can maintain a Wiki

Originally filed by thinke365 on 2009-06-26T20:22:01

haha, This can be a promising project which still have quit long way to go.

socket.error should be reraised as OperationalError

Originally filed by [email protected] on 2010-09-04T07:59:17

What steps will reproduce the problem?

  1. Perform an operation that will generate a socket error, such as connecting to a non-listening port.

pymysql.connect(user='pymysql', passwd='foo', port=5432)
Traceback (most recent call last):
File "", line 1, in ?
File "pymysql/init.py", line 72, in Connect
return Connection(_args, *_kwargs)
File "/home/abg/holland.pymysql/plugins/holland.lib.mysql/holland/lib/mysql/client/pymysql/connections.py", line 465, in init
self._connect()
File "/home/abg/holland.pymysql/plugins/holland.lib.mysql/holland/lib/mysql/client/pymysql/connections.py", line 607, in _connect
sock.connect((self.host, self.port))
File "", line 1, in connect
socket.error: (111, 'Connection refused')

What is the expected output? What do you see instead?

Expected exception:
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (111)")

Actual exception:
socket.error: (111, 'Connection refused')

What version of the product are you using? On what operating system?
python2.3.4 on RHEL4.8 w/ pymysql 0.3 (svn)

Please provide any additional information below.

MySQL user-defined variables fail

Originally filed by [email protected] on 2010-09-09T14:56:07

What steps will reproduce the problem?

  1. Attempt to create or use a user-defined variable:

    import pymysql
    connection = pymysql.connect(user='root')
    cursor = connection.cursor()
    cursor.execute('SELECT @foo')
    cursor.execute("SET @foo = 'bar'")

What is the expected output? What do you see instead?

Expected:

import MySQLdb
connection = MySQLdb.connect(user='root')
cursor = connection.cursor()
cursor.execute('SELECT @foo')
1L
cursor.fetchone()
(None,)
cursor.execute("SET @foo = 'bar'")
0L

Actual:

import pymysql
connection = pymysql.connect(user='root')
cursor = connection.cursor()
cursor.execute('SELECT @foo')
Traceback (most recent call last):
File "", line 1, in
File "pymysql/cursors.py", line 102, in execute
self.errorhandler(self, exc, value)
File "pymysql/connections.py", line 173, in defaulterrorhandler
raise Error(errorclass, errorvalue)
pymysql.err.Error: (<type 'exceptions.KeyError'>, KeyError(251,))
cursor.execute("SET @foo = 'bar'")
Traceback (most recent call last):
File "", line 1, in
File "pymysql/cursors.py", line 102, in execute
self.errorhandler(self, exc, value)
File "pymysql/connections.py", line 173, in defaulterrorhandler
raise Error(errorclass, errorvalue)
pymysql.err.Error: (<type 'exceptions.AssertionError'>, AssertionError('Result length not requested length:\nExpected=2. Actual=0. Position: 7. Data Length: 7',))

What version of the product are you using? On what operating system?
pymysql r35 using python2.6.4 on Fedora 13 testing against mysql 5.1.48

wish you can maintain a Wiki

Originally filed by thinke365 on 2009-06-26T20:22:01

haha, This can be a promising project which still have quit long way to go.

exception: TypeError: ord() expected a character, but string of length 0 found

Originally filed by [email protected] on 2009-11-19T10:45:10

Change the example.py code:

cur.execute("SELECT Host,User FROM user")

to

cur.execute("SELECT * FROM user")

run the example.py, will got the exception like:

Traceback (most recent call last):
File "/home/mk2/workspace/pymysql/example.py", line 10, in
cur.execute("SELECT * FROM user")
File "/home/mk2/workspace/pymysql/pymysql/cursor.py", line 82, in execute
self.errorhandler(self, exc, value)
File "/home/mk2/workspace/pymysql/pymysql/connections.py", line 96, in
defaulterrorhandler
raise errorclass, errorvalue
TypeError: ord() expected a character, but string of length 0 found

CANT RETRIEVE TIMESTAMP

Originally filed by [email protected] on 2010-11-29T20:01:45

What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?

Please provide any additional information below.

no StringIO import

Originally filed by quzhengping on 2010-08-13T06:36:06

What steps will reproduce the problem?

  1. there is leak of StringIO in connections.py

What is the expected output? What do you see instead?
NameError: global name 'StringIO' is not defined

What version of the product are you using? On what operating system?
currently

Django support

Originally filed by [email protected] on 2010-03-02T15:30:47

i use python amd64 and mysql 64 ,
amd i want to get my django app can use the mysql db.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.