Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
Merge pull request #12 from hongqn/feature/flags
Browse files Browse the repository at this point in the history
Decode string for *TEXT columns
  • Loading branch information
Jonas Tärnström committed Apr 20, 2012
2 parents 05166cc + 74691f7 commit ce3a47a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
7 changes: 5 additions & 2 deletions python/umysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,11 @@ int API_resultRowValue(void *result, int column, UMTypeInfo *ti, char *value, si
case MFTYPE_MEDIUM_BLOB:
case MFTYPE_LONG_BLOB:
case MFTYPE_BLOB:
// Fall through for string encoding
valobj = PyString_FromStringAndSize( (const char *) value, cbValue);
if (ti->flags & MFFLAG_BINARY_FLAG) {
valobj = PyString_FromStringAndSize( (const char *) value, cbValue);
} else {
valobj = DecodeString (ti, value, cbValue);
}
break;

//PyString family
Expand Down
32 changes: 31 additions & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,37 @@ def testCharsets(self):
self.assertEquals(result, expected)

cnn.close()


def testTextCharsets(self):
aumlaut_unicode = u"\u00e4"
aumlaut_utf8 = "\xc3\xa4"
aumlaut_latin1 = "\xe4"

cnn = umysql.Connection()
cnn.connect (DB_HOST, 3306, DB_USER, DB_PASSWD, DB_DB)

cnn.query("drop table if exists tblutf")
cnn.query("create table tblutf (test_mode TEXT DEFAULT NULL, test_utf TEXT DEFAULT NULL, test_latin1 TEXT) ENGINE=MyISAM DEFAULT CHARSET=utf8")

# We insert the same character using two different encodings
cnn.query("set names utf8")
cnn.query("insert into tblutf (test_mode, test_utf, test_latin1) values ('utf8', _utf8'" + aumlaut_utf8 + "', _latin1'" + aumlaut_latin1 + "')")

cnn.query("set names latin1")
cnn.query("insert into tblutf (test_mode, test_utf, test_latin1) values ('latin1', _utf8'" + aumlaut_utf8 + "', _latin1'" + aumlaut_latin1 + "')")

# We expect the driver to always give us unicode strings back
expected = [(u"utf8", aumlaut_unicode, aumlaut_unicode), (u"latin1", aumlaut_unicode, aumlaut_unicode)]

# Fetch and test with different charsets
for charset in ("latin1", "utf8", "cp1250"):
cnn.query("set names " + charset)
rs = cnn.query("select test_mode, test_utf, test_latin1 from tblutf")
result = rs.rows
self.assertEquals(result, expected)

cnn.close()

if __name__ == '__main__':
from guppy import hpy
hp = hpy()
Expand Down

0 comments on commit ce3a47a

Please sign in to comment.