The CUBRIDSchemaProvider class provides support for database schema, provides the following functions: query user tables, indexes, views, database users, etc.
Need to add the following code:
using System.Data; using System.Data.Common; using CUBRID.Data.CUBRIDClient;
Define the connection string:
/* conection string, please modify before using. */ string _connString = "server=localhost;database=demodb;port=33000;user=public;password=";
Use CUBRIDConnectionStringBuilder class generated connection string:
string server = "localhost"; int port = 33000; string database = "demodb"; string user = "public"; string password = ""; string encoding = "utf-8"; CUBRIDConnectionStringBuilder sb = new CUBRIDConnectionStringBuilder(server, port, database, user, password, encoding); string _connString = sb.GetConnectionString();
Get All User Tables:
/* create a new CUBRIDConnection instance */
using (CUBRIDConnection conn = new CUBRIDConnection())
{
try
{
/* set the connection string */
conn.ConnectionString = _connString;
/* connect to db server */
conn.Open();
/* create a new CUBRIDSchemaProvider instance */
CUBRIDSchemaProvider schema = new CUBRIDSchemaProvider(conn);
/* get all tables */
DataTable dt = schema.GetTables(new string[] { "%" });
/* print all tables */
for (int i = 0; i < dt.Rows.Count; i++)
Console.WriteLine(dt.Rowsi2.ToString());
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
}
}
Get all users:
/* create a new CUBRIDConnection instance */
using (CUBRIDConnection conn = new CUBRIDConnection())
{
try
{
/* set the connection string */
conn.ConnectionString = _connString;
/* connect to db server */
conn.Open();
/* create a new CUBRIDSchemaProvider instance */
CUBRIDSchemaProvider schema = new CUBRIDSchemaProvider(conn);
/* get all users */
DataTable dt = schema.GetUsers(null);
/* print all users */
for (int i = 0; i < dt.Rows.Count; i++)
Console.WriteLine(dt.Rowsi0.ToString().ToUpper());
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
}
}
Get all views:
/* create a new CUBRIDConnection instance */
using (CUBRIDConnection conn = new CUBRIDConnection())
{
try
{
/* set the connection string */
conn.ConnectionString = _connString;
/* connect to db server */
conn.Open();
/* create a new CUBRIDSchemaProvider instance */
CUBRIDSchemaProvider schema = new CUBRIDSchemaProvider(conn);
/* get all tables */
DataTable dt = schema.GetViews(new string[] { "%" });
/* print all tables */
for (int i = 0; i < dt.Rows.Count; i++)
Console.WriteLine(dt.Rowsi2.ToString());
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
}
}
Sample Code: SchemaProviderTest.cs