Skip to content

Commit 52c0c59

Browse files
committed
remove dead code and update catalog fetching case
Update the logic that gets the catalog name: there's a new SYS CATALOGS available system query that can be used, so the way to implement it in the driver is now clear.
1 parent d80a79b commit 52c0c59

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

driver/connect.c

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,12 +2071,25 @@ SQLRETURN EsSQLSetConnectAttrW(
20712071
return SQL_SUCCESS;
20722072
}
20732073

2074-
#if 0
2075-
static BOOL get_current_catalog(esodbc_dbc_st *dbc)
2074+
/* writes into 'dest', of size 'room', the current catalog of 'dbc'.
2075+
* returns negative on error, or the char count written otherwise */
2076+
static SQLSMALLINT get_current_catalog(esodbc_dbc_st *dbc, SQLWCHAR *dest,
2077+
SQLSMALLINT room)
20762078
{
2077-
FIXME;
2079+
SQLSMALLINT used;
2080+
SQLWCHAR *catalog = MK_WPTR("my_current_catalog"); // FIXME
2081+
2082+
//
2083+
// TODO: use the new SYS CATALOGS query
2084+
//
2085+
2086+
DBGH(dbc, "current catalog: `" LWPD "`.", catalog);
2087+
if (! SQL_SUCCEEDED(write_wptr(&dbc->hdr.diag, dest, catalog, room,
2088+
&used))) {
2089+
return -1;
2090+
}
2091+
return used;
20782092
}
2079-
#endif //0
20802093

20812094
SQLRETURN EsSQLGetConnectAttrW(
20822095
SQLHDBC ConnectionHandle,
@@ -2086,9 +2099,7 @@ SQLRETURN EsSQLGetConnectAttrW(
20862099
_Out_opt_ SQLINTEGER* StringLengthPtr)
20872100
{
20882101
esodbc_dbc_st *dbc = DBCH(ConnectionHandle);
2089-
SQLRETURN ret;
20902102
SQLSMALLINT used;
2091-
// SQLWCHAR *val;
20922103

20932104
switch(Attribute) {
20942105
/* https://docs.microsoft.com/en-us/sql/odbc/reference/develop-app/automatic-population-of-the-ipd */
@@ -2103,30 +2114,17 @@ SQLRETURN EsSQLGetConnectAttrW(
21032114

21042115
/* "the name of the catalog to be used by the data source" */
21052116
case SQL_ATTR_CURRENT_CATALOG:
2106-
DBGH(dbc, "requested: catalog name (@0x%p).", dbc->catalog);
2107-
#if 0
2117+
DBGH(dbc, "requested: catalog name.");
21082118
if (! dbc->es_types) {
21092119
ERRH(dbc, "no connection active.");
2110-
/* TODO: check connection state and correct state */
21112120
RET_HDIAGS(dbc, SQL_STATE_08003);
2112-
} else if (! get_current_catalog(dbc)) {
2121+
} else if ((used = get_current_catalog(dbc, (SQLWCHAR *)ValuePtr,
2122+
(SQLSMALLINT)BufferLength)) < 0) {
21132123
ERRH(dbc, "failed to get current catalog.");
2114-
RET_STATE(dbc, dbc->hdr.diag.state);
2124+
RET_STATE(dbc->hdr.diag.state);
21152125
}
2116-
#endif //0
2117-
#if 0
2118-
val = dbc->catalog ? dbc->catalog : MK_WPTR("null");
2119-
*StringLengthPtr = wcslen(*(SQLWCHAR **)ValuePtr);
2120-
*StringLengthPtr *= sizeof(SQLWCHAR);
2121-
*(SQLWCHAR **)ValuePtr = val;
2122-
#else //0
2123-
// FIXME;
2124-
ret = write_wptr(&dbc->hdr.diag, (SQLWCHAR *)ValuePtr,
2125-
MK_WPTR("NulL"), (SQLSMALLINT)BufferLength, &used);
21262126
if (StringLengthPtr);
21272127
*StringLengthPtr = (SQLINTEGER)used;
2128-
return ret;
2129-
#endif //0
21302128
break;
21312129

21322130
case SQL_ATTR_METADATA_ID:

0 commit comments

Comments
 (0)