mysql怎么样修改schema_修改CodeSmith中的SchemaExplorer.MySQLSchemaProvider

///

///Gets the parameters for a given command.///

/// The connection string used to connect to the target database.

///

///

public ParameterSchema[] GetCommandParameters( stringconnectionString, 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 = new List();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(newParameterSchema(command,name,paramDirection,type,nativeType,size,precision,scale,isNullable));

}if (!reader.IsClosed)

reader.Close();

}if (connection.State !=ConnectionState.Closed)

connection.Close();

}returnparameterSchema.ToArray();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值