[ODBC-214] Mediumint(INT24) is always empty Created: 2019-01-26  Updated: 2020-07-11  Resolved: 2020-07-11

Status: Closed
Project: MariaDB Connector/ODBC
Component/s: General
Affects Version/s: 3.0.8
Fix Version/s: 3.1.9

Type: Bug Priority: Major
Reporter: Matthias Schröder Assignee: Lawrin Novitsky
Resolution: Fixed Votes: 0
Labels: None
Environment:

Windows 10, Microsoft Visual FoxPro 9, MariaDB ODBC 3.0 Driver 32-Bit



 Description   

Brief description

When I try to fetch records from tables that contain mediumint columns, I get empty values. The problem doesn’t occur when I use the odbc driver 5.3 from oracle/mysql.

Long description

I am using Microsoft Visual FoxPro 9.0 to access the data. It is a quite old development environment from Microsoft. I was not able to trigger this bug in other ways than using Microsoft Visual FoxPro. However, I figured some things out:

When I apply the following patch to the odbc driver, everything works fine:

diff --git a/ma_helper.c b/ma_helper.c
index a1ca7a580a9e9f64b9cda149367644f56d022409..259a6ea25d80c9cefd94717a30a2c961d4846792 100644
--- a/ma_helper.c
+++ b/ma_helper.c
@@ -544,7 +544,6 @@ size_t MADB_GetOctetLength(MYSQL_FIELD *Field, unsigned short MaxCharLen)
   case MYSQL_TYPE_SHORT:
     return 2;
   case MYSQL_TYPE_INT24:
-    return 3;
   case MYSQL_TYPE_LONG:
     return 4;
   case MYSQL_TYPE_LONGLONG:

But I am not sure whether this is the right solution because in the module ma_statement.c I found another snipped of code that could be related to this issue:

/* We do this for catalog functions and MS Access in first turn. The thing is that for some columns in catalog functions result,
           we fix column type manually, since we can't make field of desired type in the query to I_S. Mostly that is for SQLSMALLINT
           fields, and we can cast only to int, not to short. MSAccess in its turn like to to get length for fixed length types, and
           throws error if the length is not what it expected (ODBC-131)
           Probably it makes sense to do this only for SQL_C_DEFAULT type, which MS Access uses. But atm it looks like this should
           not hurt if done for other types, too */{color}
        if (*StrLen_or_IndPtr == 0 || (Bind.length_value > (unsigned long)IrdRec->OctetLength && *StrLen_or_IndPtr > IrdRec->OctetLength))
        {
          *StrLen_or_IndPtr= IrdRec->OctetLength;
        }

The comment says at some point: „Probably it makes sense to do this only for SQL_C_DEFAULT type, which MS Access uses. But atm it looks like this should not hurt if done for other types, too“.

If I remove this line of code, everything works fine too:

*StrLen_or_IndPtr= IrdRec->OctetLength;

Maybe FoxPro doesn’t like this behavior and it should actually be done only for SQL_C_DEFAULT type.



 Comments   
Comment by Lawrin Novitsky [ 2020-07-11 ]

Forgot to close it - the fix was pushed in the commit 9465795, and have been released in 3.1.9
I did not re-create the issue, and fix is based on reporter's experience. It makes sense to report octet length as 4, as we map the mediumint type to the SQLINTEGER any way, and 3 was strange there

Generated at Thu Feb 08 03:27:03 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.