Skip to content

Commit 334247d

Browse files
authored
Implementation of SQLSetDescRec & SQLGetDescRec functions (#23)
* Implemented SQLSetDescRec function - Fixed SQL_DESC_PRECISION field in IPDSetField & IPDGetField functions - Added support for other fields for bookmark column in ARDSetField - SQL_DESC_TYPE - SQL_DESC_DATETIME_INTERVAL_CODE - SQL_DESC_OCTET_LENGTH - SQL_DESC_PRECISION - SQL_DESC_SCALE * Implemented SQLGetDescRec function - Handled SQL_NO_DATA case in GetField functions - Handled 01004 SQLSTATE in GetField functions - Added support for SQL_DESC_NAME & SQL_DESC_NULLABLE IPDGetField functions * Implemented SQLGetDescRecW & SQLSetDescRecW functions - Updated PGAPI_GetFunctions function to get new functions - Updated psqlodbc.def file for new functions on Windows - Fixed HY007 error handling * Added regression test for DescRec functions
1 parent 5949d81 commit 334247d

File tree

12 files changed

+507
-36
lines changed

12 files changed

+507
-36
lines changed

descriptor.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,8 @@ static const struct
701701
{ DESC_OPTION_NOT_FOR_THE_DRIVER, "HYC00", "HYC00" },
702702
{ DESC_FETCH_OUT_OF_RANGE, "HY106", "S1106" },
703703
{ DESC_COUNT_FIELD_INCORRECT, "07002", "07002" },
704+
{ DESC_STATEMENT_NOT_PREPARED, "HY007", "S1010" },
705+
{ DESC_STRING_DATA_TRUNCATED, "01004", "01004"}
704706
};
705707

706708
static PG_ErrorInfo *DC_create_errorinfo(const DescriptorClass *self)

descriptor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,5 +262,7 @@ enum {
262262
,DESC_OPTION_NOT_FOR_THE_DRIVER
263263
,DESC_FETCH_OUT_OF_RANGE
264264
,DESC_COUNT_FIELD_INCORRECT
265+
,DESC_STATEMENT_NOT_PREPARED
266+
,DESC_STRING_DATA_TRUNCATED
265267
};
266268
#endif /* __DESCRIPTOR_H__ */

info.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,18 +1565,18 @@ PGAPI_GetFunctions(HDBC hdbc,
15651565
case SQL_API_SQLFREEHANDLE: /* 1006 */
15661566
case SQL_API_SQLGETCONNECTATTR: /* 1007 */
15671567
case SQL_API_SQLGETDESCFIELD: /* 1008 */
1568+
case SQL_API_SQLGETDESCREC: /* 1009 */
15681569
case SQL_API_SQLGETDIAGFIELD: /* 1010 */
15691570
case SQL_API_SQLGETDIAGREC: /* 1011 */
15701571
case SQL_API_SQLGETENVATTR: /* 1012 */
15711572
case SQL_API_SQLGETSTMTATTR: /* 1014 */
15721573
case SQL_API_SQLSETCONNECTATTR: /* 1016 */
15731574
case SQL_API_SQLSETDESCFIELD: /* 1017 */
1575+
case SQL_API_SQLSETDESCREC: /* 1018 */
15741576
case SQL_API_SQLSETENVATTR: /* 1019 */
15751577
case SQL_API_SQLSETSTMTATTR: /* 1020 */
15761578
*pfExists = TRUE;
15771579
break;
1578-
case SQL_API_SQLGETDESCREC: /* 1009 */
1579-
case SQL_API_SQLSETDESCREC: /* 1018 */
15801580
case SQL_API_SQLCOPYDESC: /* 1004 */
15811581
*pfExists = FALSE;
15821582
break;

odbcapi30.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,14 @@ SQLGetDescRec(SQLHDESC DescriptorHandle,
308308
SQLLEN *Length, SQLSMALLINT *Precision,
309309
SQLSMALLINT *Scale, SQLSMALLINT *Nullable)
310310
{
311-
MYLOG(0, "Entering\n");
312-
MYLOG(0, "Error not implemented\n");
313-
return SQL_ERROR;
311+
RETCODE ret;
312+
313+
MYLOG(0, "Entering h=%p rec=%d name=%p blen=%d\n", DescriptorHandle, RecNumber, Name, BufferLength);
314+
MYLOG(0, "str=%p type=%p sub=%p len=%p prec=%p scale=%p null=%p\n", StringLength, Type, SubType, Length, Precision, Scale, Nullable);
315+
ret = PGAPI_GetDescRec(DescriptorHandle, RecNumber, Name, BufferLength,
316+
StringLength, Type, SubType, Length, Precision,
317+
Scale, Nullable);
318+
return ret;
314319
}
315320

316321
/* new function */
@@ -459,9 +464,14 @@ SQLSetDescRec(SQLHDESC DescriptorHandle,
459464
PTR Data, SQLLEN *StringLength,
460465
SQLLEN *Indicator)
461466
{
462-
MYLOG(0, "Entering\n");
463-
MYLOG(0, "Error not implemented\n");
464-
return SQL_ERROR;
467+
RETCODE ret;
468+
469+
MYLOG(0, "Entering h=%p rec=%d type=%d sub=%d len=" FORMAT_LEN " prec=%d scale=%d data=%p\n", DescriptorHandle, RecNumber, Type, SubType, Length, Precision, Scale, Data);
470+
MYLOG(0, "str=%p ind=%p\n", StringLength, Indicator);
471+
ret = PGAPI_SetDescRec(DescriptorHandle, RecNumber, Type,
472+
SubType, Length, Precision, Scale, Data,
473+
StringLength, Indicator);
474+
return ret;
465475
}
466476
#endif /* UNICODE_SUPPORTXX */
467477

@@ -646,20 +656,14 @@ MYLOG(DETAIL_LOG_LEVEL, "lie=%d\n", ci->drivers.lie);
646656
SQL_FUNC_ESET(pfExists, SQL_API_SQLFREEHANDLE); /* 1006 */
647657
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETCONNECTATTR); /* 1007 */
648658
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDESCFIELD); /* 1008 */
649-
if (ci->drivers.lie)
650-
{
651-
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDESCREC); /* 1009 not implemented yet */
652-
}
659+
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDESCREC); /* 1009 */
653660
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDIAGFIELD); /* 1010 minimal implementation */
654661
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDIAGREC); /* 1011 */
655662
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETENVATTR); /* 1012 */
656663
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETSTMTATTR); /* 1014 */
657664
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETCONNECTATTR); /* 1016 */
658665
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETDESCFIELD); /* 1017 */
659-
if (ci->drivers.lie)
660-
{
661-
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETDESCREC); /* 1018 not implemented yet */
662-
}
666+
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETDESCREC); /* 1018 */
663667
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETENVATTR); /* 1019 */
664668
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETSTMTATTR); /* 1020 */
665669
SQL_FUNC_ESET(pfExists, SQL_API_SQLFETCHSCROLL); /* 1021 */

odbcapi30w.c

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,37 @@ SQLGetDescRecW(SQLHDESC DescriptorHandle,
426426
SQLLEN *Length, SQLSMALLINT *Precision,
427427
SQLSMALLINT *Scale, SQLSMALLINT *Nullable)
428428
{
429-
MYLOG(0, "Entering\n");
430-
MYLOG(0, "Error not implemented\n");
431-
return SQL_ERROR;
429+
RETCODE ret;
430+
char *NameA = NULL;
431+
SQLSMALLINT nlen;
432+
433+
MYLOG(0, "Entering h=%p rec=%d name=%p blen=%d\n", DescriptorHandle, RecNumber, Name, BufferLength);
434+
MYLOG(0, "str=%p type=%p sub=%p len=%p prec=%p scale=%p null=%p\n", StringLength, Type, SubType, Length, Precision, Scale, Nullable);
435+
436+
if (BufferLength > 0)
437+
NameA = malloc(BufferLength);
438+
439+
ret = PGAPI_GetDescRec(DescriptorHandle, RecNumber, (SQLCHAR *) NameA, BufferLength,
440+
&nlen, Type, SubType, Length, Precision,
441+
Scale, Nullable);
442+
if (SQL_SUCCEEDED(ret))
443+
{
444+
if (NameA && nlen <= BufferLength)
445+
{
446+
SQLULEN ulen = utf8_to_ucs2_lf(NameA, nlen, FALSE, Name, BufferLength, TRUE);
447+
if (ulen == (SQLULEN) -1)
448+
nlen = (SQLSMALLINT) locale_to_sqlwchar((SQLWCHAR *) Name, NameA, BufferLength, FALSE);
449+
else
450+
nlen = (SQLSMALLINT) ulen;
451+
if (nlen >= BufferLength)
452+
ret = SQL_SUCCESS_WITH_INFO;
453+
}
454+
if (StringLength)
455+
*StringLength = nlen;
456+
}
457+
if (NameA)
458+
free(NameA);
459+
return ret;
432460
}
433461

434462
/* new function */
@@ -440,7 +468,28 @@ SQLSetDescRecW(SQLHDESC DescriptorHandle,
440468
PTR Data, SQLLEN *StringLength,
441469
SQLLEN *Indicator)
442470
{
443-
MYLOG(0, "Entering\n");
444-
MYLOG(0, "Error not implemented\n");
445-
return SQL_ERROR;
471+
RETCODE ret;
472+
SQLLEN vallen;
473+
char *uval = NULL;
474+
BOOL val_alloced = FALSE;
475+
476+
MYLOG(0, "Entering h=%p rec=%d type=%d sub=%d len=" FORMAT_LEN " prec=%d scale=%d data=%p\n", DescriptorHandle, RecNumber, Type, SubType, Length, Precision, Scale, Data);
477+
MYLOG(0, "str=%p ind=%p\n", StringLength, Indicator);
478+
479+
if (Length > 0 || SQL_NTS == Length)
480+
{
481+
uval = ucs2_to_utf8(Data, Length > 0 ? Length / WCLEN : Length, &vallen, FALSE);
482+
val_alloced = TRUE;
483+
}
484+
if (!val_alloced)
485+
{
486+
uval = Data;
487+
vallen = Length;
488+
}
489+
ret = PGAPI_SetDescRec(DescriptorHandle, RecNumber, Type,
490+
SubType, Length, Precision, Scale, uval,
491+
&vallen, Indicator);
492+
if (val_alloced)
493+
free(uval);
494+
return ret;
446495
}

0 commit comments

Comments
 (0)