Example #1
0
 /// <summary>
 /// Binds a parameter to the command with the given value and type.
 /// </summary>
 /// <param name="parameterName">
 /// The parameter Name.
 /// </param>
 /// <param name="value">
 /// The value.
 /// </param>
 /// <param name="type">
 /// The type.
 /// </param>
 public void AddParameter(string parameterName, object value, MySqlDbType type)
 {
     var parameter = new MySqlParameter();
     parameter.ParameterName = parameterName;
     parameter.Value = value;
     this.Command.Parameters.Add(parameter);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MySqlParameter"/> class with the parameter name, the <see cref="MySqlDbType"/>, the size, and the source column name.
 /// </summary>
 /// <param name="parameterName">The name of the parameter to map. </param>
 /// <param name="dbType">One of the <see cref="MySqlDbType"/> values. </param>
 /// <param name="size">The length of the parameter. </param>
 /// <param name="sourceColumn">The name of the source column. </param>
 public MySqlParameter(string parameterName, MySqlDbType dbType, int size, string sourceColumn) : this(parameterName, dbType)
 {
   Size = size;
   Direction = ParameterDirection.Input;
   SourceColumn = sourceColumn;
   SourceVersion = DataRowVersion.Current;
 }
    internal MySqlGeometry(MySqlDbType type, Double xValue, Double yValue, int srid)
    {
      this._type = type;
      this._xValue = xValue;
      this._yValue = yValue;      
      this._isNull = false;
      this._srid = srid;
      this._valBinary = new byte[GEOMETRY_LENGTH];

      byte[] sridBinary = BitConverter.GetBytes(srid);

      for (int i = 0; i < sridBinary.Length; i++)
        _valBinary[i] = sridBinary[i];

      long xVal = BitConverter.DoubleToInt64Bits(xValue);
      long yVal = BitConverter.DoubleToInt64Bits(yValue);

      _valBinary[4] = 1;
      _valBinary[5] = 1;
     
      for (int i = 0; i < 8; i++)
        {
          _valBinary[i + 9] = (byte)(xVal & 0xff);
          xVal >>= 8;
        }

      for (int i = 0; i < 8; i++)
      {
        _valBinary[i + 17] = (byte)(yVal & 0xff);
        yVal >>= 8;
      }
    }
Example #4
0
 public static MySqlParameter CreateParameter(ParameterDirection direction, string paramName, MySqlDbType dbtype, int size, object value)
 {
     MySqlParameter param = new MySqlParameter(paramName, dbtype, size);
     param.Value = value;
     param.Direction = direction;
     return param;
 }
Example #5
0
 public string DbTypeToString(MySqlDbType type, int? length)
 {
     string ret;
     if (TypesAsStrings.TryGetValue(type, out ret))
         return ret + (length != null ? "({0})".SFormat((int)length) : "");
     throw new NotImplementedException(Enum.GetName(typeof(MySqlDbType), type));
 }
Example #6
0
 public MySqlBinary(MySqlDbType type, byte[] val)
 {
     this.type = type;
     this.isNull = false;
     this.mValue = val;
     this.IsGuid = false;
 }
Example #7
0
        ///<summary>
        ///</summary>
        ///<param name="paramName"></param>
        ///<param name="dbType"></param>
        ///<param name="size"></param>
        ///<param name="direction"></param>
        ///<param name="value"></param>
        ///<returns></returns>
        ///<exception cref="ArgumentOutOfRangeException"></exception>
        public static MySqlParameter MakeParam(string paramName, MySqlDbType dbType, int size, ParameterDirection direction, object value)
        {
            MySqlParameter sqlParameter = null;
            try
            {
                paramName = paramName ?? string.Empty;

                //modify reason:验证花时比较大
                //if (!MathUtils.IsMachVarName(paramName))
                //{
                //    throw new ArgumentOutOfRangeException("paramName", "参数名格式不正确");
                //}
                if (size > 0)
                {
                    sqlParameter = new MySqlParameter(FormatParamName(paramName), dbType, size);
                }
                else
                {
                    sqlParameter = new MySqlParameter(FormatParamName(paramName), dbType);
                }
                sqlParameter.Direction = direction;
                if (direction != ParameterDirection.Output || value != null)
                {
                    sqlParameter.Value = value;
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("{0}", ex);
            }
            return sqlParameter;
        }
Example #8
0
 public MySqlBinary(MySqlDbType type, bool isNull)
 {
     this.type = type;
     this.isNull = isNull;
     this.mValue = null;
     this.IsGuid = false;
 }
Example #9
0
		public string DbTypeToString(MySqlDbType type, int? length)
		{
			string ret;
			if (TypesAsStrings.TryGetValue(type, out ret))
				return ret;
			throw new NotImplementedException(Enum.GetName(typeof(MySqlDbType), type));
		}
Example #10
0
		internal static void SetDSInfo(DataTable dsTable) {
			string[] strArray = new string[] { "INT", "YEAR", "MEDIUMINT" };
			MySqlDbType[] typeArray = new MySqlDbType[] { MySqlDbType.Int32, MySqlDbType.Year, MySqlDbType.Int24 };
			for (int i = 0; i < strArray.Length; i++) {
				DataRow row = dsTable.NewRow();
				row["TypeName"] = strArray[i];
				row["ProviderDbType"] = typeArray[i];
				row["ColumnSize"] = 0;
				row["CreateFormat"] = strArray[i];
				row["CreateParameters"] = null;
				row["DataType"] = "System.Int32";
				row["IsAutoincrementable"] = typeArray[i] != MySqlDbType.Year;
				row["IsBestMatch"] = true;
				row["IsCaseSensitive"] = false;
				row["IsFixedLength"] = true;
				row["IsFixedPrecisionScale"] = true;
				row["IsLong"] = false;
				row["IsNullable"] = true;
				row["IsSearchable"] = true;
				row["IsSearchableWithLike"] = false;
				row["IsUnsigned"] = false;
				row["MaximumScale"] = 0;
				row["MinimumScale"] = 0;
				row["IsConcurrencyType"] = DBNull.Value;
				row["IsLiteralsSupported"] = false;
				row["LiteralPrefix"] = null;
				row["LiteralSuffix"] = null;
				row["NativeDataType"] = null;
				dsTable.Rows.Add(row);
			}
		}
Example #11
0
 private static MySqlParameter getParameter(string Name, MySqlDbType Type, object Value)
 {
     MySqlParameter param = new MySqlParameter();
     param.ParameterName = Name;
     param.MySqlDbType = Type;
     param.Value = Value;
     return param;
 }
 internal MySqlParameter(string name, MySqlDbType type, ParameterDirection dir, string col, DataRowVersion ver, object val)
   : this(name, type)
 {
   Direction = dir;
   SourceColumn = col;
   SourceVersion = ver;
   Value = val;
 }
Example #13
0
 public MySqlParameter AddParameter(string ParameterName, MySqlDbType type, int size, object value, ParameterDirection direction)
 {
     MySqlParameter param = new MySqlParameter(ParameterName, type, size);
     param.Direction = direction;
     param.Value = value;
     Command.Parameters.Add(param);
     return param;
 }
Example #14
0
 public static void addSqlParam(string name, ParameterDirection direction, int size, MySqlDbType type)
 {
     MySqlParameter sqlParam = new MySqlParameter();
     sqlParam.ParameterName = name;
     sqlParam.Direction = direction;
     sqlParam.Size = size;
     sqlParam.MySqlDbType = type;
     sqlParms.Add(sqlParam);
 }
Example #15
0
		/// <summary>
		/// Initializes a new instance of the <see cref="MySqlParameter"/> class with the parameter name and a value of the new MySqlParameter.
		/// </summary>
		/// <param name="parameterName">The name of the parameter to map. </param>
		/// <param name="value">An <see cref="Object"/> that is the value of the <see cref="MySqlParameter"/>. </param>
		public MySqlParameter(string parameterName, object value)
		{
			ParameterName = parameterName;
			paramValue = value;
			if (value is Byte[])
				size = (value as Byte[]).Length;
			dbType = GetMySqlType();
			genericType = GetGenericType();
		}
 internal MySqlGeometry(MySqlDbType type, bool isNull)
 {
   this._type = type;
   isNull = true;
   _xValue = 0;
   _yValue = 0;
   _srid = 0;
   _valBinary = null;
   this._isNull = isNull;
 }
Example #17
0
 /// <summary>
 /// 增加SQL命令参数
 /// </summary>
 /// <param name="paraName">参数名</param>
 /// <param name="paraValue">参数值</param>
 /// <param name="paraDbType">数据类型</param>
 /// <param name="paraSize">参数长度</param>
 /// <param name="paraDirection">参数类型(in, out, inout)</param>
 /// <returns></returns>
 public static MySqlParameter AddParameter(string paraName, object paraValue, MySqlDbType paraDbType, int paraSize, ParameterDirection paraDirection)
 {
     MySqlParameter par = new MySqlParameter();
     par.ParameterName = paraName;
     par.Value = paraValue;
     par.Direction = paraDirection;
     par.MySqlDbType = paraDbType;
     if (paraSize > 0)
         par.Size = paraSize;
     return par;
 }
Example #18
0
		public MySqlDateTime(MySqlDateTime mdt) {
			this.year = mdt.Year;
			this.month = mdt.Month;
			this.day = mdt.Day;
			this.hour = mdt.Hour;
			this.minute = mdt.Minute;
			this.second = mdt.Second;
			this.millisecond = 0;
			this.type = MySqlDbType.DateTime;
			this.isNull = false;
		}
Example #19
0
		internal MySqlDateTime(MySqlDbType type, DateTime val)
			: this(type, 0, 0, 0, 0, 0, 0) {
			this.isNull = false;
			this.year = val.Year;
			this.month = val.Month;
			this.day = val.Day;
			this.hour = val.Hour;
			this.minute = val.Minute;
			this.second = val.Second;
			this.millisecond = val.Millisecond;
		}
Example #20
0
		internal MySqlDateTime(MySqlDbType type, int year, int month, int day, int hour, int minute, int second) {
			this.isNull = false;
			this.type = type;
			this.year = year;
			this.month = month;
			this.day = day;
			this.hour = hour;
			this.minute = minute;
			this.second = second;
			this.millisecond = 0;
		}
 /// <summary>
 /// Constructs a new <b>MySqlDateTime</b> object by copying the current value of the given object.
 /// </summary>
 /// <param name="mdt">The <b>MySqlDateTime</b> object to copy.</param>
 public MySqlDateTime(MySqlDateTime mdt)
 {
   year = mdt.Year;
   month = mdt.Month;
   day = mdt.Day;
   hour = mdt.Hour;
   minute = mdt.Minute;
   second = mdt.Second;
   millisecond = 0;
   type = MySqlDbType.DateTime;
   isNull = false;
 }
Example #22
0
 /// <summary>
 /// Adds a parameter to the parameteres collection of the command object
 /// </summary>
 /// <param name="Name"></param>
 /// <param name="Type"></param>
 /// <param name="Size"></param>
 /// <param name="Value"></param>
 public void AddParameter(string Name, MySqlDbType Type, int Size, object Value)
 {
     try
     {
         Command.Parameters.Add(Name, Type, Size).Value = Value;
         Command.Parameters[Name].Direction = ParameterDirection.Input;
     }
     catch(MySqlException e)
     {
         throw new System.Exception(e.Message, e.InnerException);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MySqlParameter"/> class with the parameter name, the type of the parameter, the size of the parameter, a <see cref="ParameterDirection"/>, the precision of the parameter, the scale of the parameter, the source column, a <see cref="DataRowVersion"/> to use, and the value of the parameter.
 /// </summary>
 /// <param name="parameterName">The name of the parameter to map. </param>
 /// <param name="dbType">One of the <see cref="MySqlDbType"/> values. </param>
 /// <param name="size">The length of the parameter. </param>
 /// <param name="direction">One of the <see cref="ParameterDirection"/> values. </param>
 /// <param name="isNullable">true if the value of the field can be null, otherwise false. </param>
 /// <param name="precision">The total number of digits to the left and right of the decimal point to which <see cref="MySqlParameter.Value"/> is resolved.</param>
 /// <param name="scale">The total number of decimal places to which <see cref="MySqlParameter.Value"/> is resolved. </param>
 /// <param name="sourceColumn">The name of the source column. </param>
 /// <param name="sourceVersion">One of the <see cref="DataRowVersion"/> values. </param>
 /// <param name="value">An <see cref="Object"/> that is the value of the <see cref="MySqlParameter"/>. </param>
 /// <exception cref="ArgumentException"/>
 public MySqlParameter(string parameterName, MySqlDbType dbType, int size, ParameterDirection direction,
                       bool isNullable, byte precision, byte scale, string sourceColumn,
                       DataRowVersion sourceVersion,
                       object value)
   : this(parameterName, dbType, size, sourceColumn)
 {
   Direction = direction;
   SourceVersion = sourceVersion;
   IsNullable = isNullable;
   Precision = precision;
   Scale = scale;
   Value = value;
 }
Example #24
0
 private static DbParameter CreateParam(string ParamName, MySqlDbType DbType, int Size, ParameterDirection Direction, object Value)
 {
     DbParameter parameter;
     if (Size > 0)
     {
         parameter = new MySqlParameter(ParamName, DbType, Size);
     }
     else
     {
         parameter = new MySqlParameter(ParamName, DbType);
     }
     parameter.Direction = Direction;
     if ((Direction != ParameterDirection.Output) || (Value != null))
     {
         parameter.Value = Value;
     }
     return parameter;
 }
        public MySqlGeometry(MySqlDbType type, byte[] val)
        {
            if (val == null)
            throw new ArgumentNullException("val");

              byte[] buffValue = new byte[val.Length];

              for (int i = 0; i < val.Length; i++)
               buffValue[i] = val[i];

              var xIndex = val.Length == GEOMETRY_LENGTH ? 9 : 5;
              var yIndex = val.Length == GEOMETRY_LENGTH ? 17 : 13;

              _valBinary = buffValue;
              _xValue = BitConverter.ToDouble(val, xIndex);
              _yValue = BitConverter.ToDouble(val, yIndex);
              this._srid = val.Length == GEOMETRY_LENGTH ? BitConverter.ToInt32(val, 0) : 0;
              this._isNull = false;
              this._type = type;
        }
    internal static void SetDSInfo(DataTable dsTable)
    {
      var types = new string[] { "DATE", "DATETIME", "TIMESTAMP" };
      var dbtype = new MySqlDbType[] { MySqlDbType.Date, 
        MySqlDbType.DateTime, MySqlDbType.Timestamp };

      // we use name indexing because this method will only be called
      // when GetSchema is called for the DataSourceInformation 
      // collection and then it wil be cached.
      for (var x = 0; x < types.Length; x++)
      {
        var row = dsTable.NewRow();
        row["TypeName"] = types[x];
        row["ProviderDbType"] = dbtype[x];
        row["ColumnSize"] = 0;
        row["CreateFormat"] = types[x];
        row["CreateParameters"] = null;
        row["DataType"] = "System.DateTime";
        row["IsAutoincrementable"] = false;
        row["IsBestMatch"] = true;
        row["IsCaseSensitive"] = false;
        row["IsFixedLength"] = true;
        row["IsFixedPrecisionScale"] = true;
        row["IsLong"] = false;
        row["IsNullable"] = true;
        row["IsSearchable"] = true;
        row["IsSearchableWithLike"] = false;
        row["IsUnsigned"] = false;
        row["MaximumScale"] = 0;
        row["MinimumScale"] = 0;
        row["IsConcurrencyType"] = DBNull.Value;
        row["IsLiteralSupported"] = false;
        row["LiteralPrefix"] = null;
        row["LiteralSuffix"] = null;
        row["NativeDataType"] = null;
        dsTable.Rows.Add(row);
      }
    }
 internal MySqlDateTime(MySqlDbType type, DateTime val)
   : this(type, 0, 0, 0, 0, 0, 0, 0)
 {
   isNull = false;
   year = val.Year;
   month = val.Month;
   day = val.Day;
   hour = val.Hour;
   minute = val.Minute;
   second = val.Second;
   millisecond = val.Millisecond;
 }
 internal MySqlDateTime(MySqlDbType type, bool isNull)
   : this(type, 0, 0, 0, 0, 0, 0, 0)
 {
   this.isNull = isNull;
 }
 public MySqlBinary(MySqlDbType type, bool isNull)
 {
     this.type = type;
     this.isNull = isNull;
     mValue = null;
 }
        public static void SetDSInfo(DataTable dsTable)
        {
            string[] types = new string[] { "BLOB", "TINYBLOB", "MEDIUMBLOB", "LONGBLOB", "BINARY", "VARBINARY" };
            MySqlDbType[] dbtype = new MySqlDbType[] { MySqlDbType.Blob,
                MySqlDbType.TinyBlob, MySqlDbType.MediumBlob, MySqlDbType.LongBlob, MySqlDbType.Binary, MySqlDbType.VarBinary };
            long[] sizes = new long[] { 65535L, 255L, 16777215L, 4294967295L, 255L, 65535L };
            string[] format = new string[] { null, null, null, null, "binary({0})", "varbinary({0})" };
            string[] parms = new string[] { null, null, null, null, "length", "length" };

            // we use name indexing because this method will only be called
            // when GetSchema is called for the DataSourceInformation
            // collection and then it wil be cached.
            for (int x = 0; x < types.Length; x++)
            {
                DataRow row = dsTable.NewRow();
                row["TypeName"] = types[x];
                row["ProviderDbType"] = dbtype[x];
                row["ColumnSize"] = sizes[x];
                row["CreateFormat"] = format[x];
                row["CreateParameters"] = parms[x];
                row["DataType"] = "System.Byte[]";
                row["IsAutoincrementable"] = false;
                row["IsBestMatch"] = true;
                row["IsCaseSensitive"] = false;
                row["IsFixedLength"] = x < 4 ? false : true;
                row["IsFixedPrecisionScale"] = false;
                row["IsLong"] = sizes[x] > 255;
                row["IsNullable"] = true;
                row["IsSearchable"] = false;
                row["IsSearchableWithLike"] = false;
                row["IsUnsigned"] = DBNull.Value;
                row["MaximumScale"] = DBNull.Value;
                row["MinimumScale"] = DBNull.Value;
                row["IsConcurrencyType"] = DBNull.Value;
                row["IsLiteralSupported"] = false;
                row["LiteralPrefix"] = "0x";
                row["LiteralSuffix"] = DBNull.Value;
                row["NativeDataType"] = DBNull.Value;
                dsTable.Rows.Add(row);
            }
        }