[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 Created: 2019-01-20  Updated: 2019-07-23  Resolved: 2019-05-02

Status: Closed
Project: MariaDB Connector/ODBC
Component/s: General
Affects Version/s: None
Fix Version/s: 2.0.19, 3.0.9, 3.1.2

Type: Bug Priority: Major
Reporter: Cai Zhejun Assignee: Lawrin Novitsky
Resolution: Fixed Votes: 0
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();
}



 Comments   
Comment by Cai Zhejun [ 2019-02-15 ]

Dear Lawrin,
Could you please give some confirmations about issue ODBC-211 as soon as possible.

Comment by Lawrin Novitsky [ 2019-02-15 ]

Dear Cai,
Thank you for your report and the proposed solution.
This is interesting case. atm I am not sure that your solution is complete, but the fix will definitely make to all next releases

Comment by Lawrin Novitsky [ 2019-05-02 ]

In odbc-3.0, master and develop commit 832360f

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