zoukankan      html  css  js  c++  java
  • 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();
                }
            }
        }
    }
    
    

    欢迎转载 ,转载时请保留作者信息。本文版权归本人所有,如有任何问题,请与我联系wang2650@sohu.com 。 过错

    adonet的api http://www.cubrid.org/manual/api/ado.net/8.4.1/Index.html













  • 相关阅读:
    Ubuntu升级后apache所有的失败,以解决虚拟文件夹的设置
    UVA315- Network(无向图割点)
    技术新领导人张小龙:一些成功不能复制
    mac在查看jre通路
    ubuntu14.04(64位置) ADB Not Responding
    【SSH三框架】Hibernate基金会七:许多附属业务
    HDU1796-How many integers can you find
    再次递归思想-路劲跨越多个阵列
    基于ORACLE建表和循环回路来创建数据库存储过程SQL语句来实现
    Android4.3 蓝牙BLE初步
  • 原文地址:https://www.cnblogs.com/wang2650/p/5283983.html
Copyright © 2011-2022 走看看