CUBRID学习笔记 16 元数据支持
Posted 横刀立马 醉卧山岗
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CUBRID学习笔记 16 元数据支持相关的知识,希望对你有一定的参考价值。
简化了很多 ,在sqlserver需要用语句实现的功能
接口如下
public DataTable GetDatabases(string[] filters) public DataTable GetTables(string[] filters) public DataTable GetViews(string[] filters) public DataTable GetColumns(string[] filters) public DataTable GetIndexes(string[] filters) public DataTable GetIndexColumns(string[] filters) public DataTable GetExportedKeys(string[] filters) public DataTable GetCrossReferenceKeys(string[] filters) public DataTable GetForeignKeys(string[] filters) public DataTable GetUsers(string[] filters) public DataTable GetProcedures(string[] filters) public static DataTable GetDataTypes() public static DataTable GetReservedWords() public static String[] GetNumericFunctions() public static String[] GetStringFunctions() public DataTable GetSchema(string collection, string[] filters)
获取数据库
CUBRIDSchemaProvider schema = new CUBRIDSchemaProvider(conn); DataTable dt = schema.GetTables(new string[] { "%" }); Debug.Assert(dt.Columns.Count == 3); Debug.Assert(dt.Rows.Count == 10); Debug.Assert(dt.Rows[0][0].ToString() == "demodb"); Debug.Assert(dt.Rows[0][1].ToString() == "demodb"); Debug.Assert(dt.Rows[0][2].ToString() == "stadium");
获取表的外键
CUBRIDSchemaProvider schema = new CUBRIDSchemaProvider(conn); DataTable dt = schema.GetForeignKeys(new string[] { "game" }); Debug.Assert(dt.Columns.Count == 9); Debug.Assert(dt.Rows.Count == 2); Debug.Assert(dt.Rows[0][0].ToString() == "athlete"); Debug.Assert(dt.Rows[0][1].ToString() == "code"); Debug.Assert(dt.Rows[0][2].ToString() == "game"); Debug.Assert(dt.Rows[0][3].ToString() == "athlete_code"); Debug.Assert(dt.Rows[0][4].ToString() == "1"); Debug.Assert(dt.Rows[0][5].ToString() == "1"); Debug.Assert(dt.Rows[0][6].ToString() == "1"); Debug.Assert(dt.Rows[0][7].ToString() == "fk_game_athlete_code"); Debug.Assert(dt.Rows[0][8].ToString() == "pk_athlete_code");
获取索引
CUBRIDSchemaProvider schema = new CUBRIDSchemaProvider(conn); DataTable dt = schema.GetIndexes(new string[] { "game" }); Debug.Assert(dt.Columns.Count == 9); Debug.Assert(dt.Rows.Count == 5); Debug.Assert(dt.Rows[3][2].ToString() == "pk_game_host_year_event_code_athlete_code"); //verify index name Debug.Assert(dt.Rows[3][4].ToString() == "True"); //Is it a primary key?
完整例子
using CUBRID.Data.CUBRIDClient; using System.Diagnostics; using System.Data; namespace MetadataExample { class Program { static void Main(string[] args) { CUBRIDConnectionStringBuilder sb = new CUBRIDConnectionStringBuilder("localhost", "demodb", "public", "", "33000"); using (CUBRIDConnection conn = new CUBRIDConnection(sb.GetConnectionString())) { conn.Open(); CUBRIDSchemaProvider schema = new CUBRIDSchemaProvider(conn); //get tables example using (DataTable dt = schema.GetTables(new string[] { "%" })) { Debug.Assert(dt.Columns.Count == 3); Debug.Assert(dt.Rows.Count == 10); Debug.Assert(dt.Rows[0][0].ToString() == "demodb"); Debug.Assert(dt.Rows[0][1].ToString() == "demodb"); Debug.Assert(dt.Rows[0][2].ToString() == "stadium"); } //get columns example using (DataTable dt = schema.GetColumns(new string[] { "game" })) { Debug.Assert(dt.Columns.Count == 11); Debug.Assert(dt.Rows.Count == 7); Debug.Assert(dt.Rows[0][3].ToString() == "host_year"); Debug.Assert(dt.Rows[1][3].ToString() == "event_code"); } //get users example using (DataTable dt = schema.GetUsers(null)) { Debug.Assert(dt.Columns.Count == 1); Debug.Assert(dt.Rows.Count >= 2); Debug.Assert(dt.Rows[0][0].ToString().ToUpper() == "DBA"); Debug.Assert(dt.Rows[1][0].ToString().ToUpper() == "PUBLIC"); } //get views example using (DataTable dt = schema.GetViews(null)) { Debug.Assert(dt.Columns.Count == 3); Debug.Assert(dt.Rows.Count == 0); } //get foreign keys example using (DataTable dt = schema.GetForeignKeys(new string[] { "game" })) { Debug.Assert(dt.Columns.Count == 9); Debug.Assert(dt.Rows.Count == 2); Debug.Assert(dt.Rows[0][0].ToString() == "athlete"); Debug.Assert(dt.Rows[0][1].ToString() == "code"); Debug.Assert(dt.Rows[0][2].ToString() == "game"); Debug.Assert(dt.Rows[0][3].ToString() == "athlete_code"); Debug.Assert(dt.Rows[0][4].ToString() == "1"); Debug.Assert(dt.Rows[0][5].ToString() == "1"); Debug.Assert(dt.Rows[0][6].ToString() == "1"); Debug.Assert(dt.Rows[0][7].ToString() == "fk_game_athlete_code"); Debug.Assert(dt.Rows[0][8].ToString() == "pk_athlete_code"); Debug.Assert(dt.Rows[1][0].ToString() == "event"); Debug.Assert(dt.Rows[1][1].ToString() == "code"); Debug.Assert(dt.Rows[1][2].ToString() == "game"); Debug.Assert(dt.Rows[1][3].ToString() == "event_code"); Debug.Assert(dt.Rows[1][4].ToString() == "1"); Debug.Assert(dt.Rows[1][5].ToString() == "1"); Debug.Assert(dt.Rows[1][6].ToString() == "1"); Debug.Assert(dt.Rows[1][7].ToString() == "fk_game_event_code"); Debug.Assert(dt.Rows[1][8].ToString() == "pk_event_code"); } //get indexes example using (DataTable dt = schema.GetIndexes(new string[] { "game" })) { Debug.Assert(dt.Columns.Count == 9); Debug.Assert(dt.Rows.Count == 5); Debug.Assert(dt.Rows[3][2].ToString() == "pk_game_host_year_event_code_athlete_code"); //Index name Debug.Assert(dt.Rows[3][4].ToString() == "True"); //Is PK? } conn.Close(); } } } }
欢迎转载 ,转载时请保留作者信息。本文版权归本人所有,如有任何问题,请与我联系[email protected] 。 过错
adonet的api http://www.cubrid.org/manual/api/ado.net/8.4.1/Index.html
以上是关于CUBRID学习笔记 16 元数据支持的主要内容,如果未能解决你的问题,请参考以下文章