国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

修改CodeSmith中的SchemaExplorer.MySQLSchemaProvider

2019-11-14 16:11:22
字體:
來源:轉載
供稿:網友

修改C:/PRogram Files (x86)/CodeSmith/v6.5/Samples/Projects/CSharp/MySQLSchemaProvider/MySQLSchemaProvider.cs

修改GetCommandParameters方法,原本是沒有實現的。一直報錯誤信息:GetCommandParameters() is not supported in this release.

        /// <summary>        /// Gets the parameters for a given command.        /// </summary>        /// <param name="connectionString">The connection string used to connect to the target database.</param>        /// <param name="command"></param>        /// <returns></returns>        public ParameterSchema[] GetCommandParameters( string connectionString, CommandSchema command )        {            // MySQL does not yet implement INFORMATION_SCHEMA.PARAMETERS            // MySQL Connector/Net 1.0.7 is supposed to support DeriveParameters()            // However, in my testing there appears to be a bug (throws a NULL reference exception)            // This method will be unsupported until a subsequent release of DeriverParameters()            // is working.            // throw new NotSupportedException( "GetCommandParameters() is not supported in this release." );            /*            ArrayList a = new ArrayList();            ParameterSchema ps;            DbConnection cnx = null;            DbCommand cmd = null;            try            {                cnx = new DbConnection(connectionString);                cmd = new DbCommand(command.Name, cnx);                cmd.CommandType = CommandType.StoredProcedure;                cnx.Open();                IDbCommandBuilder.DeriveParameters(cmd);                cnx.Close();                foreach(MySqlParameter param in cmd.Parameters)                {                    ps = new ParameterSchema(command, param.ParameterName, param.Direction, param.DbType,                         param.MySqlDbType.ToString(), param.Size, param.Precision, param.Scale, param.IsNullable);                    a.Add(ps);                }            }            catch            {                throw;            }            finally            {                if (cnx != null)                    cnx.Close();            }            return (ParameterSchema[]) a.ToArray(typeof (ParameterSchema));            */            string commandText = string.Format("SELECT PARAMETER_NAME, DATA_TYPE, CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION,"                + " NUMERIC_SCALE, 0 IS_NULLABLE, PARAMETER_MODE"                + " FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPECIFIC_SCHEMA = '{0}' AND SPECIFIC_NAME = '{1}' AND ROUTINE_TYPE = 'PROCEDURE' ORDER BY ORDINAL_POSITION", command.Database.Name, command.Name);            List<ParameterSchema> parameterSchema = new List<ParameterSchema>();            using (DbConnection connection = CreateConnection(connectionString))            {                connection.Open();                DbCommand cmd = connection.CreateCommand();                cmd.CommandText = commandText;                cmd.Connection = connection;                using (IDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))                {                    while (reader.Read())                    {                        string name = reader.GetString( 0 );                        string nativeType = reader.GetString( 1 );                        long longSize = ( reader.IsDBNull( 2 ) == false ) ? reader.GetInt64( 2 ) : 0;                        byte precision = ( byte ) ( ( reader.IsDBNull( 3 ) == false ) ? reader.GetInt32( 3 ) : 0 );                        int scale = ( reader.IsDBNull( 4 ) == false ) ? reader.GetInt32( 4 ) : 0;                        bool isNullable = ( reader.IsDBNull( 5 ) == false ) && reader.GetBoolean( 5 );                        string direction = reader.GetString( 6 );                        ParameterDirection paramDirection = ParameterDirection.Input;                        switch(direction)                        {                            case "IN":                                paramDirection = ParameterDirection.Input;                                break;                            case "OUT":                                paramDirection = ParameterDirection.Output;                                break;                            case "INOUT":                                paramDirection = ParameterDirection.InputOutput;                                break;                            default:                                paramDirection = ParameterDirection.Input;                                break;                        }                        int size = ( longSize < int.MaxValue ) ? ( int ) longSize : int.MaxValue;                        bool isUnsigned = ( nativeType.IndexOf( "unsigned" ) > -1 );                        DbType type = GetDbType( nativeType, isUnsigned );                        parameterSchema.Add(new ParameterSchema(command,name,paramDirection,type,nativeType,size,precision,scale,isNullable));                    }                    if (!reader.IsClosed)                        reader.Close();                }                if (connection.State != ConnectionState.Closed)                    connection.Close();            }            return parameterSchema.ToArray();        }

編譯后生成SchemaExplorer.MySQLSchemaProvider.dll,覆蓋程序安裝目錄中SchemaProviders目錄的同名文件。

修改后替換目錄(C:/Program Files (x86)/CodeSmith/v6.5/SchemaProviders/SchemaExplorer.MySQLSchemaProvider.dll)中的同名文件。

 

啟動CodeSmith后,需要在Schema Explorer中刪除原來的MySQL數據庫,重新添加,不然會報錯。

也可以先卸載GAC中的SchemaExplorer.MySQLSchemaProvider.dll,然后將自己修改、編譯并簽名后的SchemaExplorer.MySQLSchemaProvider.dll安裝到GAC中。

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 芜湖市| 随州市| 新巴尔虎右旗| 宁陕县| 师宗县| 安龙县| 合山市| 新邵县| 英吉沙县| 榆中县| 海兴县| 竹山县| 兴宁市| 神木县| 惠水县| 出国| 长子县| 沁源县| 南城县| 绥棱县| 锦屏县| 岢岚县| 临武县| 克拉玛依市| 德阳市| 桂平市| 田阳县| 勃利县| 苍南县| 蒙自县| 祁连县| 揭东县| 永修县| 怀化市| 宁波市| 隆子县| 五家渠市| 临湘市| 滨海县| 福建省| 雷山县|