Solution Codesmith Unable to get MySQL table and column description description comment

Source: Internet
Author: User

 PublicExtendedproperty[] Getextendedproperties (stringconnectionString, Schemaobjectbase schemaobject) {List<ExtendedProperty> extendedproperties =NewList<extendedproperty>(); if(Schemaobject isColumnschema) {Columnschema Columnschema= Schemaobject asColumnschema; stringCommandText =string. Format (@"SELECT EXTRA, Column_default, Column_type,column_comment From INFORMATION_SCHEMA. COLUMNS WHERE table_schema = ' {0} ' and table_name = ' {1} ' and Column_ NAME = ' {2} '", ColumnSchema.Table.Database.Name, ColumnSchema.Table.Name, Colu                Mnschema.name); using(DbConnection connection =createconnection (connectionString)) {connection.                    Open (); DbCommand Command=connection.                    CreateCommand (); Command.commandtext=CommandText; Command. Connection=connection; using(IDataReader reader =command. ExecuteReader (commandbehavior.closeconnection)) { while(reader. Read ()) {stringExtra = reader. GetString (0).                            ToLower (); BOOLColumndefaultisnull = reader. IsDBNull (1); stringColumndefault =""; if(!columndefaultisnull) {Columndefault= Reader. GetString (1).                            ToUpper (); }                            stringColumnType = reader. GetString (2).                            ToUpper (); string columncomment = reader.                            GetString (3); BOOLIsidentity = (extra. IndexOf ("auto_increment") >-1); Extendedproperties.add (NewExtendedproperty (extendedpropertynames.isidentity, isidentity, Columnschema.datatype)); if(isidentity) {/*MySQL auto_increment doesn ' t work exactly like SQL Server ' s IDENTITY I believe that auto_increment are equivalent to IDENTITY (1, 1) However, auto_i  Ncrement behaves differently from the IDENTITY when used with multi-column primary keys.                                See the MySQL Reference Manual for details. */Extendedproperties.add (NewExtendedproperty (Extendedpropertynames.identityseed,1, Columnschema.datatype)); Extendedproperties.add (NewExtendedproperty (Extendedpropertynames.identityincrement,1, Columnschema.datatype)); } extendedproperties.add (NewExtendedproperty ("Cs_columndefaultisnull", Columndefaultisnull, Dbtype.boolean));//Added for backwards compatibility.Extendedproperties.add (NewExtendedproperty (Extendedpropertynames.defaultvalue, Columndefault, dbtype.string)); Extendedproperties.add (NewExtendedproperty ("Cs_columndefault", Columndefault, dbtype.string));//Added for backwards compatibility.Extendedproperties.add (NewExtendedproperty (Extendedpropertynames.systemtype, ColumnType, dbtype.string)); Extendedproperties.add (NewExtendedproperty ("Cs_columntype", ColumnType, dbtype.string));//Added for backwards compatibility.Extendedproperties.add (NewExtendedproperty ("Cs_columnextra", Extra.                            ToUpper (), dbtype.string)); Extendedproperties.add ( new Extendedproperty ("Cs_description" , Columncomment, dbtype.string)); }                        if(!Reader. IsClosed) reader.                    Close (); }                    if(Connection. State! =connectionstate.closed) connection.                Close (); }            }            if(Schemaobject isTableschema) {Tableschema Tableschema= Schemaobject asTableschema; stringCommandText =string. Format (@"SHOW CREATE TABLE ' {0} '. ' {1} '", TableSchema.Database.Name, tableschema.name); using(DbConnection connection =createconnection (connectionString)) {connection.                    Open (); DbCommand Command=connection.                    CreateCommand (); Command.commandtext=CommandText; Command. Connection=connection; using(IDataReader reader =command. ExecuteReader (commandbehavior.closeconnection)) { while(reader. Read ()) {stringCreateTable = reader. GetString (1); //Extendedproperties.add (New Extendedproperty ("Cs_createtablescript", CreateTable, dbtype.string));                            Extendedproperties.add (New Extendedproperty ("Ts_description", CreateTable, dbtype.string)); int engineindex = createtable.                            LastIndexOf ("ENGINE"); int commentindex = createtable.                            LastIndexOf ("comment="); String tabledescription = reader.                            GetString (0); if (Commentindex > Engineindex) {tabledescription = Createta ble. Substring (Commentindex + 9).                            Replace ("'", ""); } extendedproperties.add (New Extendedproperty ("Cs_description" , Tabledescription, dbtype.string)); }                        if(!Reader. IsClosed) reader.                    Close (); }                    if(Connection. State! =connectionstate.closed) connection.                Close (); }            }            returnExtendedproperties.toarray (); }

Solution Codesmith Unable to get MySQL table and column description description comment

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.