Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Accessing the OLEDB Database Schemas


If you are not familiar with the OLE DB standard schemas interfaces, please read first the documentation:
http://msdn.microsoft.com/en-US/library/a6fhbff0%28v=vs.80%29.aspx

The current CUBRID OLE DB Provider supports the following database schema interfaces:

  • Tables
  • Columns
  • ProviderTypes
  • TablePrivileges
  • ColumnPrivileges
  • TableConstraints
  • Statistics
  • Indexes
  • ViewColumnUsage
  • Views
  • PrimaryKeys
  • ForeignKeys

Let’s see first how we can get the tables’ schema in the demodb database. The following code will do it:

CTables TablesSchemaRowset;
//Restriction columns: TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE
TCHAR *table_name = L"nation";
HRESULT hr = TablesSchemaRowset.Open(session, NULL, NULL, (LPCTSTR)table_name);

hr = TablesSchemaRowset.MoveFirst();
if (hr == S_OK)
{
ATLASSERT(EQ_STR(TablesSchemaRowset.m_szCatalog , L"") == true);
ATLASSERT(EQ_STR(TablesSchemaRowset.m_szDescription , L"Class") == true);
ATLASSERT(EQ_STR(TablesSchemaRowset.m_szName , L"nation") == true);
ATLASSERT(EQ_STR(TablesSchemaRowset.m_szType , L"TABLE") == true);
}

TablesSchemaRowset.Close();

And now let’s see how we can get the Primary Keys schema in the demodb database:

CPrimaryKeys PrimaryKeysSchemaRowset;
//Restriction columns: TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME
TCHAR *table_name = L"nation";
HRESULT hr = PrimaryKeysSchemaRowset.Open(session, NULL, NULL, (LPCTSTR)table_name);

hr = PrimaryKeysSchemaRowset.MoveFirst();
if (hr == S_OK)
{
ATLASSERT(EQ_STR(PrimaryKeysSchemaRowset.m_szColumnName , L"code")==true);
ATLASSERT(PrimaryKeysSchemaRowset.m_nOrdinal == 1);
ATLASSERT(EQ_STR(PrimaryKeysSchemaRowset.m_szTableName , L"nation")==true);
}

PrimaryKeysSchemaRowset.Close();

Finally, let’s see how we can get theColumnsinformation from the nation table:

CColumns ColumnSchemaRowset;
// TABLE_NAME is the third restriction column
TCHAR *table_name = L"nation";
HRESULT hr = ColumnSchemaRowset.Open(session, NULL, NULL, (LPCTSTR)table_name);
if(FAILED(hr))
{
...
}

int i = 0;
hr = ColumnSchemaRowset.MoveFirst();
while (hr == S_OK)
{
i++;
hr = ColumnSchemaRowset.MoveNext();

if(i == 1)//First column 
{
ATLASSERT(EQ_STR(ColumnSchemaRowset.m_szColumnName, L"name") == true);
ATLASSERT(ColumnSchemaRowset.m_nDataType == 129);
ATLASSERT(ColumnSchemaRowset.m_nOrdinalPosition == 2);
}
}

ATLASSERT(i == 4); //There are 4 columns in the `nation` table

ColumnSchemaRowset.Close();
comments powered by Disqus
Page info
viewed 1316 times
translations en
Author
posted 2 years ago by
CUBRID
Contributors
updated 2 years ago by
View revisions
Share this article