Skip to content

Commit

Permalink
Implementation of SQLSetDescRec & SQLGetDescRec functions (#23)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Hunaid2000 committed Aug 11, 2024
1 parent 5949d81 commit 334247d
Show file tree
Hide file tree
Showing 12 changed files with 507 additions and 36 deletions.
2 changes: 2 additions & 0 deletions descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,8 @@ static const struct
{ DESC_OPTION_NOT_FOR_THE_DRIVER, "HYC00", "HYC00" },
{ DESC_FETCH_OUT_OF_RANGE, "HY106", "S1106" },
{ DESC_COUNT_FIELD_INCORRECT, "07002", "07002" },
{ DESC_STATEMENT_NOT_PREPARED, "HY007", "S1010" },
{ DESC_STRING_DATA_TRUNCATED, "01004", "01004"}
};

static PG_ErrorInfo *DC_create_errorinfo(const DescriptorClass *self)
Expand Down
2 changes: 2 additions & 0 deletions descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,7 @@ enum {
,DESC_OPTION_NOT_FOR_THE_DRIVER
,DESC_FETCH_OUT_OF_RANGE
,DESC_COUNT_FIELD_INCORRECT
,DESC_STATEMENT_NOT_PREPARED
,DESC_STRING_DATA_TRUNCATED
};
#endif /* __DESCRIPTOR_H__ */
4 changes: 2 additions & 2 deletions info.c
Original file line number Diff line number Diff line change
Expand Up @@ -1565,18 +1565,18 @@ PGAPI_GetFunctions(HDBC hdbc,
case SQL_API_SQLFREEHANDLE: /* 1006 */
case SQL_API_SQLGETCONNECTATTR: /* 1007 */
case SQL_API_SQLGETDESCFIELD: /* 1008 */
case SQL_API_SQLGETDESCREC: /* 1009 */
case SQL_API_SQLGETDIAGFIELD: /* 1010 */
case SQL_API_SQLGETDIAGREC: /* 1011 */
case SQL_API_SQLGETENVATTR: /* 1012 */
case SQL_API_SQLGETSTMTATTR: /* 1014 */
case SQL_API_SQLSETCONNECTATTR: /* 1016 */
case SQL_API_SQLSETDESCFIELD: /* 1017 */
case SQL_API_SQLSETDESCREC: /* 1018 */
case SQL_API_SQLSETENVATTR: /* 1019 */
case SQL_API_SQLSETSTMTATTR: /* 1020 */
*pfExists = TRUE;
break;
case SQL_API_SQLGETDESCREC: /* 1009 */
case SQL_API_SQLSETDESCREC: /* 1018 */
case SQL_API_SQLCOPYDESC: /* 1004 */
*pfExists = FALSE;
break;
Expand Down
32 changes: 18 additions & 14 deletions odbcapi30.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,14 @@ SQLGetDescRec(SQLHDESC DescriptorHandle,
SQLLEN *Length, SQLSMALLINT *Precision,
SQLSMALLINT *Scale, SQLSMALLINT *Nullable)
{
MYLOG(0, "Entering\n");
MYLOG(0, "Error not implemented\n");
return SQL_ERROR;
RETCODE ret;

MYLOG(0, "Entering h=%p rec=%d name=%p blen=%d\n", DescriptorHandle, RecNumber, Name, BufferLength);
MYLOG(0, "str=%p type=%p sub=%p len=%p prec=%p scale=%p null=%p\n", StringLength, Type, SubType, Length, Precision, Scale, Nullable);
ret = PGAPI_GetDescRec(DescriptorHandle, RecNumber, Name, BufferLength,
StringLength, Type, SubType, Length, Precision,
Scale, Nullable);
return ret;
}

/* new function */
Expand Down Expand Up @@ -459,9 +464,14 @@ SQLSetDescRec(SQLHDESC DescriptorHandle,
PTR Data, SQLLEN *StringLength,
SQLLEN *Indicator)
{
MYLOG(0, "Entering\n");
MYLOG(0, "Error not implemented\n");
return SQL_ERROR;
RETCODE ret;

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);
MYLOG(0, "str=%p ind=%p\n", StringLength, Indicator);
ret = PGAPI_SetDescRec(DescriptorHandle, RecNumber, Type,
SubType, Length, Precision, Scale, Data,
StringLength, Indicator);
return ret;
}
#endif /* UNICODE_SUPPORTXX */

Expand Down Expand Up @@ -646,20 +656,14 @@ MYLOG(DETAIL_LOG_LEVEL, "lie=%d\n", ci->drivers.lie);
SQL_FUNC_ESET(pfExists, SQL_API_SQLFREEHANDLE); /* 1006 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETCONNECTATTR); /* 1007 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDESCFIELD); /* 1008 */
if (ci->drivers.lie)
{
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDESCREC); /* 1009 not implemented yet */
}
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDESCREC); /* 1009 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDIAGFIELD); /* 1010 minimal implementation */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETDIAGREC); /* 1011 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETENVATTR); /* 1012 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLGETSTMTATTR); /* 1014 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETCONNECTATTR); /* 1016 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETDESCFIELD); /* 1017 */
if (ci->drivers.lie)
{
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETDESCREC); /* 1018 not implemented yet */
}
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETDESCREC); /* 1018 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETENVATTR); /* 1019 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLSETSTMTATTR); /* 1020 */
SQL_FUNC_ESET(pfExists, SQL_API_SQLFETCHSCROLL); /* 1021 */
Expand Down
61 changes: 55 additions & 6 deletions odbcapi30w.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,37 @@ SQLGetDescRecW(SQLHDESC DescriptorHandle,
SQLLEN *Length, SQLSMALLINT *Precision,
SQLSMALLINT *Scale, SQLSMALLINT *Nullable)
{
MYLOG(0, "Entering\n");
MYLOG(0, "Error not implemented\n");
return SQL_ERROR;
RETCODE ret;
char *NameA = NULL;
SQLSMALLINT nlen;

MYLOG(0, "Entering h=%p rec=%d name=%p blen=%d\n", DescriptorHandle, RecNumber, Name, BufferLength);
MYLOG(0, "str=%p type=%p sub=%p len=%p prec=%p scale=%p null=%p\n", StringLength, Type, SubType, Length, Precision, Scale, Nullable);

if (BufferLength > 0)
NameA = malloc(BufferLength);

ret = PGAPI_GetDescRec(DescriptorHandle, RecNumber, (SQLCHAR *) NameA, BufferLength,
&nlen, Type, SubType, Length, Precision,
Scale, Nullable);
if (SQL_SUCCEEDED(ret))
{
if (NameA && nlen <= BufferLength)
{
SQLULEN ulen = utf8_to_ucs2_lf(NameA, nlen, FALSE, Name, BufferLength, TRUE);
if (ulen == (SQLULEN) -1)
nlen = (SQLSMALLINT) locale_to_sqlwchar((SQLWCHAR *) Name, NameA, BufferLength, FALSE);
else
nlen = (SQLSMALLINT) ulen;
if (nlen >= BufferLength)
ret = SQL_SUCCESS_WITH_INFO;
}
if (StringLength)
*StringLength = nlen;
}
if (NameA)
free(NameA);
return ret;
}

/* new function */
Expand All @@ -440,7 +468,28 @@ SQLSetDescRecW(SQLHDESC DescriptorHandle,
PTR Data, SQLLEN *StringLength,
SQLLEN *Indicator)
{
MYLOG(0, "Entering\n");
MYLOG(0, "Error not implemented\n");
return SQL_ERROR;
RETCODE ret;
SQLLEN vallen;
char *uval = NULL;
BOOL val_alloced = FALSE;

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);
MYLOG(0, "str=%p ind=%p\n", StringLength, Indicator);

if (Length > 0 || SQL_NTS == Length)
{
uval = ucs2_to_utf8(Data, Length > 0 ? Length / WCLEN : Length, &vallen, FALSE);
val_alloced = TRUE;
}
if (!val_alloced)
{
uval = Data;
vallen = Length;
}
ret = PGAPI_SetDescRec(DescriptorHandle, RecNumber, Type,
SubType, Length, Precision, Scale, uval,
&vallen, Indicator);
if (val_alloced)
free(uval);
return ret;
}
Loading

0 comments on commit 334247d

Please sign in to comment.