Hi*!
I hav OCI application. In I am trying to get the table name present in the DB.
Here is my code
bool bRet = false;
OCIStmt* InsertStmt;
sword empno;
OCIDefine *defnp = (OCIDefine *) 0;
text* szSelectStmt = (text*)"SELECT * FROM ALL_TABLES";
OCIParam* ociParam;
char* columnName = NULL;
ub4 columnLength;
ub4 nPos = 2; // This Gives me the "TABLE_NAME" string at first printf.
ub2 dataType;
char szTmpBuffer[256] = "";
char szData[1000] = "";
OCISuccess(errhp, OCIHandleAlloc((dvoid *) envhp,(dvoid **)&InsertStmt,
OCI_HTYPE_STMT, (size_t) 0, (dvoid **) 0));
OCISuccess(errhp, OCIStmtPrepare(InsertStmt,
errhp, szSelectStmt,
(ub4) strlen((char*) szSelectStmt), (ub4) OCI_NTV_SYNTAX,
(ub4) OCI_DEFAULT));
OCISuccess(errhp, OCIStmtExecute(svchp, InsertStmt, errhp, (ub4)0,
(ub4)0, (OCISnapshot*) NULL, (OCISnapshot*)NULL,
(ub4)OCI_DEFAULT));
OCISuccess(errhp, OCIParamGet(InsertStmt, OCI_HTYPE_STMT, errhp,
(void**)&ociParam, (ub4)nPos));
OCISuccess(errhp, OCIAttrGet((dvoid*)ociPara
m, (ub4)OCI_DTYPE_PARAM,
(dvoid*)&dataType, (ub4*)0, (ub4)OCI_ATTR_DATA_TYPE,
errhp));
bRet = OCISuccess(errhp, OCIAttrGet((dvoid*)ociPara
m, (ub4)OCI_DTYPE_PARAM,
(dvoid**)&columnName, (ub4*)&columnLength, (ub4)OCI_ATTR_NAME,
errhp));
if(bRet == true && columnLength != 0){
strncpy(szTmpBuffer, columnName, columnLength);
szTmpBuffer[strlen(szTmpBu
ffer)] = '\0';
printf(szTmpBuffer); // Gives me "TABLE_NAME" at the otuput.
printf("\n\n");
}
How can i get the value to that "TABLE_NAME" and iterate over all the table names present in the DB.
Thanks for your time,
Usman.
Start Free Trial