Giter Club home page Giter Club logo

pymysql's Issues

Multi-statement init_command causes subsequent query to fail

Given that the CLIENT.MULTI_STATEMENTS flag is set, it is valid for the init_command supplied by the connection contain multiple statements. Since on one ok_packet is read this causes subsequent queries to return unexpected results since client/server are out of sync.

Demonstrated by:

    def test_init_command(self):
        conn = pymysql.connect(
            init_command='set time_zone="+00:00"; set max_join_size=1000',
            **self.databases[0]
        )
        c = conn.cursor()
        c.execute('select "foobar";')
        self.assertEqual(('foobar',), c.fetchone())
        conn.close()

Support custom mapping for connection's escape method

MySQLdb provides a second argument to connection's escape method where an 'encoders' dict can be supplied.

For compatibility with existing code could this be added to PyMySQL?

From MySQLdb, _mysql.c:

static char _mysql_escape__doc__[] =
"escape(obj, dict) -- escape any special characters in object obj\n\
using mapping dict to provide quoting functions for each type.\n\
Returns a SQL literal string.";

Proposed test case:

def test_escape_custom_object(self):
    con = self.connections[0]
    cur = con.cursor()

    class Foo(object):
        value = "bar"
        encoder = lambda x: x.value

    self.assertEqual(con.escape(Foo(), encoders={Foo: encoder}), "bar")

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.