Uploaded image for project: 'MariaDB Connector/ODBC'
  1. MariaDB Connector/ODBC
  2. ODBC-211

SQLDescribeCol return precision=0 for field type decimal(1,0), it makes otl return wrong field value when otl_stream buf size is bigger than 1

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0.19, 3.0.9, 3.1.2
    • Component/s: General
    • Labels:
      None
    • Environment:
      linux+otl_v4+mariadb-connector-odbc-3.0.8-ga+mariadb-10.2.12

      Description

      MADB_SetIrdRecord in ma_desc.c:
      switch (Field->type) {
      case MYSQL_TYPE_DECIMAL:
      case MYSQL_TYPE_NEWDECIMAL:
      Record->FixedPrecScale= SQL_FALSE;
      Record->NumPrecRadix= 10;
      Record->Precision= (SQLSMALLINT)Field->length - 2;
      Record->Scale= Field->decimals;

      if field type is MYSQL_TYPE_DECIMAL, the precision is Field->length-2, so field type decimal(1,0) will return precision=2-2=0, which makes otl buffer offset wrong.

      Test Case:
      TABLE:
      MariaDB [test]> show create table t1;
      ----------------------------------------------------------------------------------------------------------------------------------+

      Table Create Table

      ----------------------------------------------------------------------------------------------------------------------------------+

      t1 CREATE TABLE `t1` (
      `f1` decimal(9,0) DEFAULT NULL,
      `f2` decimal(1,0) DEFAULT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8

      ----------------------------------------------------------------------------------------------------------------------------------+
      1 row in set (0.00 sec)

      DATA:
      MariaDB [test]> select * from t1;
      ----------+

      f1 f2

      ----------+

      100 1
      100 2
      100 3

      ----------+
      3 rows in set (0.00 sec)

      use otl to select f1,f2 from t1,result is wrong if otl_stream first param array_size is 1000:
      f1=100,f2=1
      f1=100,f2=0
      f1=100,f2=0

      result is corrent, if otl_stream first param array_size is 1
      f1=100,f2=1
      f1=100,f2=2
      f1=100,f2=3

      Test Code:
      #include <iostream>
      using namespace std;
      #include "otl.h"
      otl_connect db;
      int main()
      {
      otl_connect::otl_initialize();
      try
      {
      db.rlogon("DSN=mdb_test");
      string sql = "select f1,f2 from test.t1";
      otl_nocommit_stream select(1000, sql.c_str(), db);
      //otl_nocommit_stream select(1, sql.c_str(), db);
      while(!select.eof())

      { int f1,f2; select >> f1 >> f2; cout<<"f1="<<f1<<",f2="<<f2<<endl; }

      }catch(otl_exception& p)

      { cerr<<p.msg<<endl; cerr<<p.stm_text<<endl; cerr<<p.var_info<<endl; }

      db.logoff();
      }

        Attachments

          Activity

            People

            • Assignee:
              Lawrin Lawrin Novitsky
              Reporter:
              caizj Cai Zhejun
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: