Skip to content

Commit

Permalink
Fixed description (CONPY-9):
Browse files Browse the repository at this point in the history
When using multibyte characters (default) we need to return the code
points instead of number of characters.
  • Loading branch information
9EOR9 committed Mar 29, 2020
1 parent 083086b commit 9a36090
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
17 changes: 15 additions & 2 deletions src/mariadb_cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,21 @@ PyObject *MrdbCursor_description(MrdbCursor *self)
{
uint32_t precision= 0;
uint32_t decimals= 0;
unsigned long display_length= self->fields[i].max_length;
long packed_len= mysql_ps_fetch_functions[self->fields[i].type].pack_len;
MY_CHARSET_INFO cs;
unsigned long display_length;
long packed_len= 0;

display_length= self->fields[i].max_length > self->fields[i].length ?
self->fields[i].max_length : self->fields[i].length;
mysql_get_character_set_info(self->connection->mysql, &cs);
if (cs.mbmaxlen > 1)
{
packed_len= display_length;
display_length/= cs.mbmaxlen;
}
else {
packed_len= mysql_ps_fetch_functions[self->fields[i].type].pack_len;
}

if (self->fields[i].decimals)
{
Expand Down
16 changes: 8 additions & 8 deletions test/integration/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,19 +492,19 @@ def test_scroll(self):

del cursor

def test_compy_9(self):
def test_conpy_9(self):
cursor = self.connection.cursor()
cursor.execute(
"CREATE TEMPORARY TABLE test_compy_9 (a varchar(20), b double(6,3), c double)");
cursor.execute("INSERT INTO test_compy_9 VALUES ('€uro', 123.345, 12345.678)")
"CREATE TEMPORARY TABLE test_compy_9 (a varchar(20), b double(5,2), c double)");
cursor.execute("INSERT INTO test_compy_9 VALUES ('€uro', -123.34, 12345.678)")
cursor.execute("SELECT a,b,c FROM test_compy_9")
cursor.fetchone()
d = cursor.description;
self.assertEqual(d[0][2], 4); # 4 code points only
self.assertEqual(d[0][3], -1); # variable length
self.assertEqual(d[1][2], 7); # length=precision + 1
self.assertEqual(d[1][4], 6); # precision
self.assertEqual(d[1][5], 3); # decimals
self.assertEqual(d[0][2], 20); # 20 code points
self.assertEqual(d[0][3], 80); # 80 characters
self.assertEqual(d[1][2], 6); # length=precision + 1
self.assertEqual(d[1][4], 5); # precision
self.assertEqual(d[1][5], 2); # scale
del cursor

def test_conpy_15(self):
Expand Down

0 comments on commit 9a36090

Please sign in to comment.