Cubrid Learning notes 16 meta data support

Source: Internet
Author: User

Simplifies many of the features that SQL Server needs to implement with statements

The interface is as follows

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)

Get database
cubridschemaprovider schema = new Cubridschemaprovider (conn);D atatable dt = Schema. Gettables (new string[] {"%"});D Ebug. Assert (dt. Columns.count = = 3);D ebug. Assert (dt. Rows.Count = = ten);D ebug. Assert (dt. Rows[0][0]. ToString () = = "Demodb");D ebug. Assert (dt. ROWS[0][1]. ToString () = = "Demodb");D ebug. Assert (dt. ROWS[0][2]. ToString () = = "Stadium"); 

Gets the foreign key of the table
cubridschemaprovider schema = new Cubridschemaprovider (conn);D atatable dt = Schema. Getforeignkeys (new string[] {"Game"});D Ebug. Assert (dt. Columns.count = = 9);D Ebug. Assert (dt. Rows.Count = = 2);D ebug. Assert (dt. Rows[0][0]. ToString () = = "Athlete");D Ebug. Assert (dt. ROWS[0][1]. ToString () = = "Code");D Ebug. Assert (dt. ROWS[0][2]. ToString () = = "Game");D Ebug. Assert (dt. ROWS[0][3]. ToString () = = "Athlete_code");D ebug. Assert (dt. ROWS[0][4]. ToString () = = "1");D Ebug. Assert (dt. ROWS[0][5]. ToString () = = "1");D Ebug. Assert (dt. ROWS[0][6]. ToString () = = "1");D Ebug. Assert (dt. ROWS[0][7]. ToString () = = "Fk_game_athlete_code");D ebug. Assert (dt. ROWS[0][8]. ToString () = = "Pk_athlete_code"); 


Get index

cubridschemaprovider schema = new Cubridschemaprovider (conn);D atatable dt = Schema. Getindexes (new string[] {"Game"});D Ebug. Assert (dt. Columns.count = = 9);D Ebug. Assert (dt. Rows.Count = = 5);D ebug. Assert (dt. ROWS[3][2]. ToString () = = "Pk_game_host_year_event_code_athlete_code"); Verify index Namedebug.assert (dt. ROWS[3][4]. ToString () = = "True"); Is it a primary key? 

Complete Example
Using Cubrid. Data.cubridclient;using system.diagnostics;using System.data;namespace metadataexample{class Program {Stati c void Main (string[] args) {Cubridconnectionstringbuilder sb = new Cubridconnectionstringbuilder ("Local            Host "," 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 (); }        }    }}

Welcome reprint, please retain the author information when reproduced. The copyright of this article is owned by me, if you have any questions, please contact me [email protected]. Fault

ADONet's API http://www.cubrid.org/manual/api/ado.net/8.4.1/Index.html













Cubrid Learning notes 16 meta data support

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.