sqldata/sqlociapi.cpp
// Get the list of available tables
Get the list of available tables
Get the list of available tables
int SqlOciApi::GetAvailableTables(std::string &select, std::string &exclude, 
										std::list<std::string> &tables)
{
	std::string condition;
	GetSelectionCriteria(select.c_str(), exclude.c_str(), "owner", "table_name", condition, _user.c_str(), true);
	std::string query = "SELECT owner, table_name FROM all_tables WHERE";
	query += " iot_name IS NULL";
	if(condition.empty() == false)
	{
		query += " AND ";
		query += condition;
	}
	if(strcmp(select.c_str(), "*.*") == 0)
	{
		query += " AND owner NOT IN ('APPQOSSYS','DBSNMP','CTXSYS','FLOWS_FILES','MDSYS','OUTLN','SYS',";
		query += " 'SYSTEM','XDB')";
		query += " AND owner NOT LIKE 'APEX%'";
	}
	OCIStmt *stmtp;
	OCIDefine *defnpp;
	char owner[100][31];
	char table_name[100][31];
	 indicators, lengths and codes
	sb2 owner_ind[100], table_name_ind[100];
	ub2 owner_len[100], table_name_len[100];
	ub2 owner_code[100], table_name_code[100];
	int prefetch_rows = 100;
	int fetched;
	int rc = _ociHandleAlloc((dvoid*)_envhp, (dvoid**)&stmtp, OCI_HTYPE_STMT, 0, NULL);
	rc = _ociAttrSet(stmtp, OCI_HTYPE_STMT, (void*)&prefetch_rows, sizeof(int), OCI_ATTR_PREFETCH_ROWS, _errhp);
	rc = _ociStmtPrepare(stmtp, _errhp, (text*)query.c_str(), (ub4)query.length(), OCI_NTV_SYNTAX, OCI_DEFAULT);
	rc = _ociDefineByPos(stmtp, &defnpp, _errhp, 1, (void*)owner, 31, SQLT_STR, (void*)owner_ind,
						owner_len, owner_code, OCI_DEFAULT);
	rc = _ociDefineByPos(stmtp, &defnpp, _errhp, 2, (void*)table_name, 31, SQLT_STR, (void*)table_name_ind,
						table_name_len, table_name_code, OCI_DEFAULT);
	rc = _ociStmtExecute(_svchp, stmtp, _errhp, 100, 0, NULL, NULL, OCI_DEFAULT);
	if(rc < 0)
		SetError();
	while(rc >= 0)
	{
		_ociAttrGet(stmtp, OCI_HTYPE_STMT, (void*)&fetched, NULL, OCI_ATTR_ROWS_FETCHED, _errhp);
		if(fetched == 0)
			break;
		for(int i = 0; i < fetched; i++)
		{
			std::string tab = owner[i];
			tab += ".";
			tab += table_name[i];
			tables.push_back(tab);
		}
		if(rc == OCI_NO_DATA)
			break;
		rc = _ociStmtFetch2(stmtp, _errhp, 100, OCI_DEFAULT, 0, OCI_DEFAULT);
	}
	rc = _ociHandleFree(stmtp, OCI_HTYPE_STMT);
	return 0;
}
int SqlOciApi :: GetAvailableTables ( std :: string & select , std :: string & exclude , std :: list < std :: string > & tables ) { std :: string condition ; GetSelectionCriteria ( select . c_str ( ) , exclude . c_str ( ) , " " , " " , condition , _user . c_str ( ) , true ) ; std :: string query = " " ; query += " " ; if ( condition . empty ( ) == false ) { query += " " ; query += condition ; } if ( strcmp ( select . c_str ( ) , " " ) == 0 ) { query += " " ; query += " " ; query += " " ; } OCIStmt * stmtp ; OCIDefine * defnpp ; char owner [ 100 ] [ 31 ] ; char table_name [ 100 ] [ 31 ] ; sb2 owner_ind [ 100 ] , table_name_ind [ 100 ] ; ub2 owner_len [ 100 ] , table_name_len [ 100 ] ; ub2 owner_code [ 100 ] , table_name_code [ 100 ] ; int prefetch_rows = 100 ; int fetched ; int rc = _ociHandleAlloc ( ( dvoid * ) _envhp , ( dvoid * * ) & stmtp , OCI_HTYPE_STMT , 0 , NULL ) ; rc = _ociAttrSet ( stmtp , OCI_HTYPE_STMT , ( void * ) & prefetch_rows , sizeof ( int ) , OCI_ATTR_PREFETCH_ROWS , _errhp ) ; rc = _ociStmtPrepare ( stmtp , _errhp , ( text * ) query . c_str ( ) , ( ub4 ) query . length ( ) , OCI_NTV_SYNTAX , OCI_DEFAULT ) ; rc = _ociDefineByPos ( stmtp , & defnpp , _errhp , 1 , ( void * ) owner , 31 , SQLT_STR , ( void * ) owner_ind , owner_len , owner_code , OCI_DEFAULT ) ; rc = _ociDefineByPos ( stmtp , & defnpp , _errhp , 2 , ( void * ) table_name , 31 , SQLT_STR , ( void * ) table_name_ind , table_name_len , table_name_code , OCI_DEFAULT ) ; rc = _ociStmtExecute ( _svchp , stmtp , _errhp , 100 , 0 , NULL , NULL , OCI_DEFAULT ) ; if ( rc < 0 ) SetError ( ) ; while ( rc >= 0 ) { _ociAttrGet ( stmtp , OCI_HTYPE_STMT , ( void * ) & fetched , NULL , OCI_ATTR_ROWS_FETCHED , _errhp ) ; if ( fetched == 0 ) break ; for ( int i = 0 ; i < fetched ; i ++ ) { std :: string tab = owner [ i ] ; tab += " " ; tab += table_name [ i ] ; tables . push_back ( tab ) ; } if ( rc == OCI_NO_DATA ) break ; rc = _ociStmtFetch2 ( stmtp , _errhp , 100 , OCI_DEFAULT , 0 , OCI_DEFAULT ) ; } rc = _ociHandleFree ( stmtp , OCI_HTYPE_STMT ) ; return 0 ; }
Get the list of available tables
Get the list of available tables
// Get a condition to select objects from the catalog // Build the query // Exclude overflow tables for index organized tables // In any case, user cannot access them directly, Oracle returns ORA-25191: cannot reference overflow table of an index-organized table // IOT_NAME column available even in Oracle 9i // Add filter // Exclude system and Oracle specific schemas if *.* condition is set // Fetched data // Fetched data indicators, lengths and codes // Set prefetch count // Define the select list items  // Execute the statement and perform the initial fetch of 100 rows into the defined array // OCI_NO_DATA is returned by OCIStmtExecute and OCIStmtFetch2 when the number of fetched rows  // is less than the number of rows allocated in the array // Output fetched data  // Fetch another set of rows