Skip to content

Commit

Permalink
Fix for CONPY-62:
Browse files Browse the repository at this point in the history
When using binary protocl (which is forced when using a placeholder), the type
NEW_DECIMAL was ignored and internally converted as string instead of Decimal.
  • Loading branch information
9EOR9 committed May 5, 2020
1 parent d35d172 commit 87684a1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/mariadb_codecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ field_fetch_fromtext(MrdbCursor *self, char *data, unsigned int column)
case MYSQL_TYPE_NEWDECIMAL:
{
PyObject *decimal;

decimal= PyObject_CallFunction(decimal_type, "s", (const char *)data);
self->values[column]= decimal;
break;
Expand Down Expand Up @@ -692,13 +691,24 @@ field_fetch_callback(void *data, unsigned int column, unsigned char **row)
*row+= length;
break;
}
case MYSQL_TYPE_NEWDECIMAL:
{
unsigned long length= mysql_net_field_length(row);

if (length > 0)
{
self->values[column]= PyObject_CallFunction(decimal_type, "s", (const char *)*row);
} else {
self->values[column]= PyObject_CallFunction(decimal_type, "s", "0");
}
break;
}
case MYSQL_TYPE_GEOMETRY:
case MYSQL_TYPE_STRING:
case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_JSON:
case MYSQL_TYPE_VARCHAR:
case MYSQL_TYPE_DECIMAL:
case MYSQL_TYPE_NEWDECIMAL:
case MYSQL_TYPE_SET:
case MYSQL_TYPE_ENUM:
{
Expand Down
1 change: 0 additions & 1 deletion src/mariadb_cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,6 @@ MrdbCursor_fetchone(MrdbCursor *self)
"Cursor doesn't have a result set");
return NULL;
}

if (MrdbCursor_fetchinternal(self))
{
Py_INCREF(Py_None);
Expand Down
9 changes: 9 additions & 0 deletions test/integration/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,5 +918,14 @@ def test_conpy61(self):

del cursor

def test_conpy62(self):
con= create_connection()
cur = con.cursor()
con= create_connection()
query = "select round(.75 * (? / 3), 2) as val"
cur.execute(query,[5])
row= cur.fetchone()
self.assertEqual(row[0], Decimal(1.25))

if __name__ == '__main__':
unittest.main()

0 comments on commit 87684a1

Please sign in to comment.