1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
SQLRETURN BsolSQL_PrimaryKeys (SQLHSTMT hStmt_p, SQLWCHAR* ctlgName_p, SQLSMALLINT cCtlg_p,
SQLWCHAR* schema_p, SQLSMALLINT cSchema_p,
SQLWCHAR* table_p, SQLSMALLINT cTable_p) {
SQLRETURN return_v;
return_v = SQLPrimaryKeys (hStmt_p, ctlgName_p, cCtlg_p, schema_p, cSchema_p, table_p, cTable_p);
if (return_v == SQL_ERROR || return_v == SQL_INVALID_HANDLE) {
BsolSQLShowError (SQL_HANDLE_STMT, hStmt_p);
return_v = -1;
}
return return_v;
}
wstring BsolGetPrimaryKeys (SQLHANDLE hdlConn_p, wchar_t * tblName_p) {
wchar_t * ctgName_v, * schmName_v, * tblName_v, * colName_v, * pkName_v;
int seqNum_v, sizeOut_v;
wstring wsPkName_v;
SQLRETURN return_v;
SQLSMALLINT colLen_v, schmLen_v, tblLen_v;
SQLHSTMT hdlStmt_v;
// Initialize Statement
return_v = BsolSQL_AllocStmt (hdlConn_p, &hdlStmt_v);
// Initialize all Variables
colLen_v = 50;
sizeOut_v = 50;
seqNum_v = 0;
ctgName_v = TEXT("");
schmName_v = TEXT("");
tblName_v = TEXT("");
colName_v = TEXT("");
pkName_v = TEXT("");
// Bind column iCol_v
return_v = SQLBindCol (hdlStmt_v, 1, SQL_C_WCHAR, ctgName_v, colLen_v, (SQLINTEGER*)&sizeOut_v);
return_v = SQLBindCol (hdlStmt_v, 2, SQL_C_WCHAR, schmName_v, colLen_v, (SQLINTEGER*)&sizeOut_v);
return_v = SQLBindCol (hdlStmt_v, 3, SQL_C_WCHAR, tblName_v, colLen_v, (SQLINTEGER*)&sizeOut_v);
return_v = SQLBindCol (hdlStmt_v, 4, SQL_C_WCHAR, colName_v, colLen_v, (SQLINTEGER*)&sizeOut_v);
return_v = SQLBindCol (hdlStmt_v, 5, SQL_C_SLONG, &seqNum_v, colLen_v, (SQLINTEGER*)&sizeOut_v);
return_v = SQLBindCol (hdlStmt_v, 6, SQL_C_WCHAR, pkName_v, colLen_v, (SQLINTEGER*)&sizeOut_v);
// Get Lenght of Schema Name
schmLen_v = 50; //BsolLengthOfChaW (schmName_p);
// Get Lenght of Table Name
tblLen_v = 50; //BsolLengthOfChaW (tblName_p);
// Get Primary Key
return_v = BsolSQL_PrimaryKeys (hdlStmt_v, TEXT(""), 0, TEXT(""), schmLen_v, tblName_p, tblLen_v);
// Fetch Row from Result Set
return_v = SQLFetch (hdlStmt_v);
return_v = SQLNumResultCols (hdlStmt_v, &tblLen_v);
// If Successful
if (return_v == SQL_SUCCESS || return_v == SQL_SUCCESS_WITH_INFO)
// Convert wchar_t * to Wstring
wsPkName_v = pkName_v;
return wsPkName_v;
}
|