Subject: | Fix for SQLForeignKeys |
Please include the attached fix in future versions of DBD-ODBC.
I have used your package extensively, with great success.
I hit a minor problem when trying to list foreign keys, and am sending you the fix in the hope that it can help all of us.
In order to find all of the foreign keys from a given table in ODBC, it is necessary to use NULL as a wildcard, e.g.:
SQLForeignKeys(H, 0, 0, 0, 0, 0, 0, "Catalog", SQL_NTS, "Schema", SQL_NTS, "Table", SQL_NTS);
Unfortunately, dbdimp.c rewuires valid char * s, and any undef s get changed to the empty string.
I have tested the below code, which works with DBD-ODBC-1.06
/* KAS Start line 3736 DBD-ODBC-1.06/dbdimp.c
SQLForeignKeys uses NULL as a wildcard, so must allow NULLs to get through:
*/
if (PK_CatalogName && PK_CatalogName[0] == 0)
PK_CatalogName = 0;
if (PK_SchemaName && PK_SchemaName[0] == 0)
PK_SchemaName = 0;
if (PK_TableName && PK_TableName[0] == 0)
PK_TableName = 0;
if (FK_CatalogName && FK_CatalogName[0] == 0)
FK_CatalogName = 0;
if (FK_SchemaName && FK_SchemaName[0] == 0)
FK_SchemaName = 0;
if (FK_TableName && FK_TableName[0] == 0)
FK_TableName = 0;
rc = SQLForeignKeys(imp_sth->hstmt,
PK_CatalogName, PK_CatalogName?strlen(PK_CatalogName):0,
PK_SchemaName, PK_SchemaName?strlen(PK_SchemaName):0,
PK_TableName, PK_TableName?strlen(PK_TableName):0,
FK_CatalogName, FK_CatalogName?strlen(FK_CatalogName):0,
FK_SchemaName, FK_SchemaName?strlen(FK_SchemaName):0,
FK_TableName, FK_TableName?strlen(FK_TableName):0);
/* KAS End
*/
/* KAS Start line 3736 DBD-ODBC-1.06/dbdimp.c
SQLForeignKeys uses NULL as a wildcard, so must allow NULLs to get through:
*/
if (PK_CatalogName && PK_CatalogName[0] == 0)
PK_CatalogName = 0;
if (PK_SchemaName && PK_SchemaName[0] == 0)
PK_SchemaName = 0;
if (PK_TableName && PK_TableName[0] == 0)
PK_TableName = 0;
if (FK_CatalogName && FK_CatalogName[0] == 0)
FK_CatalogName = 0;
if (FK_SchemaName && FK_SchemaName[0] == 0)
FK_SchemaName = 0;
if (FK_TableName && FK_TableName[0] == 0)
FK_TableName = 0;
rc = SQLForeignKeys(imp_sth->hstmt,
PK_CatalogName, PK_CatalogName?strlen(PK_CatalogName):0,
PK_SchemaName, PK_SchemaName?strlen(PK_SchemaName):0,
PK_TableName, PK_TableName?strlen(PK_TableName):0,
FK_CatalogName, FK_CatalogName?strlen(FK_CatalogName):0,
FK_SchemaName, FK_SchemaName?strlen(FK_SchemaName):0,
FK_TableName, FK_TableName?strlen(FK_TableName):0);
/* KAS End
*/