private MySqlDataReader GetHackedOuputParameters() { if (outSelect.Length == 0) { return(null); } MySqlCommand cmd = new MySqlCommand("SELECT " + outSelect, Connection); MySqlDataReader reader = cmd.ExecuteReader(); // since MySQL likes to return user variables as strings // we reset the types of the readers internal value objects // this will allow those value objects to parse the string based // return values ResultSet results = reader.ResultSet; for (int i = 0; i < reader.FieldCount; i++) { string fieldName = reader.GetName(i); fieldName = fieldName.Remove(0, ParameterPrefix.Length + 1); MySqlParameter parameter = Parameters.GetParameterFlexible(fieldName, true); results.SetValueObject(i, MySqlField.GetIMySqlValue(parameter.MySqlDbType)); } if (!reader.Read()) { reader.Close(); return(null); } return(reader); }
public override void Close() { if (outSelect.Length == 0) { return; } char marker = Connection.ParameterMarker; MySqlCommand cmd = new MySqlCommand("SELECT " + outSelect, Connection); MySqlDataReader reader = cmd.ExecuteReader(); // since MySQL likes to return user variables as strings // we reset the types of the readers internal value objects // this will allow those value objects to parse the string based // return values for (int i = 0; i < reader.FieldCount; i++) { string fieldName = reader.GetName(i); fieldName = marker + fieldName.Remove(0, hash.Length + 1); reader.values[i] = MySqlField.GetIMySqlValue(Parameters[fieldName].MySqlDbType, true); } reader.Read(); for (int i = 0; i < reader.FieldCount; i++) { string fieldName = reader.GetName(i); fieldName = marker + fieldName.Remove(0, hash.Length + 1); Parameters[fieldName].Value = reader.GetValue(i); } reader.Close(); }
private void AdjustOutputTypes(MySqlDataReader reader) { // since MySQL likes to return user variables as strings // we reset the types of the readers internal value objects // this will allow those value objects to parse the string based // return values for (var i = 0; i < reader.FieldCount; i++) { var fieldName = reader.GetName(i); if (fieldName.IndexOf(ParameterPrefix) != -1) { fieldName = fieldName.Remove(0, ParameterPrefix.Length + 1); } var parameter = command.Parameters.GetParameterFlexible(fieldName, true); var v = MySqlField.GetIMySqlValue(parameter.MySqlDbType); if (v is MySqlBit) { var bit = (MySqlBit)v; bit.ReadAsString = true; reader.ResultSet.SetValueObject(i, bit); } else { reader.ResultSet.SetValueObject(i, v); } } }
private void AdjustOutputTypes() { // since MySQL likes to return user variables as strings // we reset the types of the readers internal value objects // this will allow those value objects to parse the string based // return values for (int i = 0; i < FieldCount; i++) { string fieldName = GetName(i); fieldName = fieldName.Remove(0, StoredProcedure.ParameterPrefix.Length + 1); MySqlParameter parameter = command.Parameters.GetParameterFlexible(fieldName, true); IMySqlValue v = MySqlField.GetIMySqlValue(parameter.MySqlDbType); if (v is MySqlBit) { MySqlBit bit = (MySqlBit)v; bit.ReadAsString = true; resultSet.SetValueObject(i, bit); } else { resultSet.SetValueObject(i, v); } } }
private void SetMySqlDbType(MySqlDbType mysqlDbtype) { // JSON type is treated as VarChar because in MySQL Server since 8.0.13 /// MYSQL_TYPE_JSON is not allowed as Item_param lacks a proper /// implementation for val_json. _mySqlDbType = mysqlDbtype == MySqlDbType.JSON ? MySqlDbType.VarChar : mysqlDbtype; ValueObject = MySqlField.GetIMySqlValue(_mySqlDbType); SetDbTypeFromMySqlDbType(); }
internal void Serialize(MySqlStream stream, bool binary) { IMySqlValue v = MySqlField.GetIMySqlValue(mySqlDbType); if (!binary && (paramValue == null || paramValue == DBNull.Value)) { stream.WriteStringNoNull("NULL"); } else { v.WriteValue(stream, binary, paramValue, size); } }
public IMySqlValue GetValueObject() { IMySqlValue mySqlValue = MySqlField.GetIMySqlValue(this.Type); if (mySqlValue is MySqlByte && this.ColumnLength == 1 && this.driver.Settings.TreatTinyAsBoolean) { MySqlByte mySqlByte = (MySqlByte)mySqlValue; mySqlByte.TreatAsBoolean = true; mySqlValue = mySqlByte; } else if (mySqlValue is MySqlGuid) { MySqlGuid mySqlGuid = (MySqlGuid)mySqlValue; mySqlGuid.OldGuids = this.driver.Settings.OldGuids; mySqlValue = mySqlGuid; } return(mySqlValue); }
private void AdjustOutputTypes() { for (int i = 0; i < this.FieldCount; i++) { string parameterName = this.GetName(i).Remove(0, "_cnet_param_".Length + 1); IMySqlValue iMySqlValue = MySqlField.GetIMySqlValue(this.command.Parameters.GetParameterFlexible(parameterName, true).MySqlDbType); if (iMySqlValue is MySqlBit) { MySqlBit valueObject = (MySqlBit)iMySqlValue; valueObject.ReadAsString = true; this.resultSet.SetValueObject(i, valueObject); } else { this.resultSet.SetValueObject(i, iMySqlValue); } } }
public override void Close() { base.Close(); if (outSelect.Length == 0) { return; } MySqlCommand cmd = new MySqlCommand("SELECT " + outSelect, Connection); // set the parameter hash for this new command to our current parameter hash // so the inout and out parameters won't cause a problem string parameterHash = command.parameterHash; cmd.parameterHash = parameterHash; using (MySqlDataReader reader = cmd.ExecuteReader()) { // since MySQL likes to return user variables as strings // we reset the types of the readers internal value objects // this will allow those value objects to parse the string based // return values for (int i = 0; i < reader.FieldCount; i++) { string fieldName = reader.GetName(i); fieldName = fieldName.Remove(0, parameterHash.Length + 1); MySqlParameter parameter = Parameters.GetParameterFlexible(fieldName, true); reader.values[i] = MySqlField.GetIMySqlValue(parameter.MySqlDbType); } if (reader.Read()) { for (int i = 0; i < reader.FieldCount; i++) { string fieldName = reader.GetName(i); fieldName = fieldName.Remove(0, parameterHash.Length + 1); MySqlParameter parameter = Parameters.GetParameterFlexible(fieldName, true); parameter.Value = reader.GetValue(i); } } } }
private void AdjustOutputTypes(MySqlDataReader reader) { for (int i = 0; i < reader.FieldCount; i++) { string text = reader.GetName(i); if (text.IndexOf("_cnet_param_") != -1) { text = text.Remove(0, "_cnet_param_".Length + 1); } IMySqlValue iMySqlValue = MySqlField.GetIMySqlValue(this.command.Parameters.GetParameterFlexible(text, true).MySqlDbType); if (iMySqlValue is MySqlBit) { MySqlBit mySqlBit = (MySqlBit)iMySqlValue; mySqlBit.ReadAsString = true; reader.ResultSet.SetValueObject(i, mySqlBit); } else { reader.ResultSet.SetValueObject(i, iMySqlValue); } } }
public IMySqlValue ReadColumnValue(int index, MySqlField field, IMySqlValue valObject) { long length = -1; bool isNull; Regex regex = new Regex(@"(?i)^[0-9A-F]{8}[-](?:[0-9A-F]{4}[-]){3}[0-9A-F]{12}$"); // check for GUID format if (nullMap != null) { isNull = nullMap[index + 2]; if (!MySqlField.GetIMySqlValue(field.Type).GetType().Equals(valObject.GetType()) && !field.IsUnsigned) { length = packet.ReadFieldLength(); } } else { length = packet.ReadFieldLength(); isNull = length == -1; } if ((valObject.MySqlDbType is MySqlDbType.Guid && !Settings.OldGuids) && !regex.IsMatch(Encoding.GetString(packet.Buffer, packet.Position, (int)length))) { field.Type = MySqlDbType.String; valObject = field.GetValueObject(); } packet.Encoding = field.Encoding; packet.Version = version; var val = valObject.ReadValue(packet, length, isNull); if (val is MySqlDateTime d) { d.TimezoneOffset = field.driver.timeZoneOffset; return(d); } return(val); }
private void SetDbType(DbType db_type) { dbType = db_type; switch (dbType) { case DbType.Guid: mySqlDbType = MySqlDbType.Guid; break; case DbType.AnsiString: case DbType.String: mySqlDbType = MySqlDbType.VarChar; break; case DbType.AnsiStringFixedLength: case DbType.StringFixedLength: mySqlDbType = MySqlDbType.String; break; case DbType.Boolean: case DbType.Byte: mySqlDbType = MySqlDbType.UByte; break; case DbType.SByte: mySqlDbType = MySqlDbType.Byte; break; case DbType.Date: mySqlDbType = MySqlDbType.Date; break; case DbType.DateTime: mySqlDbType = MySqlDbType.DateTime; break; case DbType.Time: mySqlDbType = MySqlDbType.Time; break; case DbType.Single: mySqlDbType = MySqlDbType.Float; break; case DbType.Double: mySqlDbType = MySqlDbType.Double; break; case DbType.Int16: mySqlDbType = MySqlDbType.Int16; break; case DbType.UInt16: mySqlDbType = MySqlDbType.UInt16; break; case DbType.Int32: mySqlDbType = MySqlDbType.Int32; break; case DbType.UInt32: mySqlDbType = MySqlDbType.UInt32; break; case DbType.Int64: mySqlDbType = MySqlDbType.Int64; break; case DbType.UInt64: mySqlDbType = MySqlDbType.UInt64; break; case DbType.Decimal: case DbType.Currency: mySqlDbType = MySqlDbType.Decimal; break; case DbType.Object: case DbType.VarNumeric: case DbType.Binary: default: mySqlDbType = MySqlDbType.Blob; break; } if (dbType == DbType.Object) { var value = this.paramValue as byte[]; if (value != null && value.Length == GEOMETRY_LENGTH) { mySqlDbType = MySqlDbType.Geometry; } } ValueObject = MySqlField.GetIMySqlValue(mySqlDbType); }
private void SetDbType(DbType db_type) { dbType = db_type; switch (dbType) { case DbType.Guid: mySqlDbType = MySqlDbType.Guid; break; case DbType.AnsiString: case DbType.String: mySqlDbType = MySqlDbType.VarChar; break; case DbType.AnsiStringFixedLength: case DbType.StringFixedLength: mySqlDbType = MySqlDbType.String; break; case DbType.Boolean: case DbType.Byte: mySqlDbType = MySqlDbType.UByte; break; case DbType.SByte: mySqlDbType = MySqlDbType.Byte; break; case DbType.Date: mySqlDbType = MySqlDbType.Date; break; case DbType.DateTime: mySqlDbType = MySqlDbType.DateTime; break; case DbType.Time: mySqlDbType = MySqlDbType.Time; break; case DbType.Single: mySqlDbType = MySqlDbType.Float; break; case DbType.Double: mySqlDbType = MySqlDbType.Double; break; case DbType.Int16: mySqlDbType = MySqlDbType.Int16; break; case DbType.UInt16: mySqlDbType = MySqlDbType.UInt16; break; case DbType.Int32: mySqlDbType = MySqlDbType.Int32; break; case DbType.UInt32: mySqlDbType = MySqlDbType.UInt32; break; case DbType.Int64: mySqlDbType = MySqlDbType.Int64; break; case DbType.UInt64: mySqlDbType = MySqlDbType.UInt64; break; case DbType.Decimal: case DbType.Currency: mySqlDbType = MySqlDbType.Decimal; break; case DbType.Object: case DbType.VarNumeric: case DbType.Binary: default: mySqlDbType = MySqlDbType.Blob; break; } valueObject = MySqlField.GetIMySqlValue(mySqlDbType); }
private void SetMySqlDbType(MySqlDbType mysql_dbtype) { mySqlDbType = mysql_dbtype; valueObject = MySqlField.GetIMySqlValue(mySqlDbType); switch (mySqlDbType) { case MySqlDbType.Decimal: dbType = DbType.Decimal; break; case MySqlDbType.Byte: dbType = DbType.SByte; break; case MySqlDbType.UByte: dbType = DbType.Byte; break; case MySqlDbType.Int16: dbType = DbType.Int16; break; case MySqlDbType.UInt16: dbType = DbType.UInt16; break; case MySqlDbType.Int24: case MySqlDbType.Int32: dbType = DbType.Int32; break; case MySqlDbType.UInt24: case MySqlDbType.UInt32: dbType = DbType.UInt32; break; case MySqlDbType.Int64: dbType = DbType.Int64; break; case MySqlDbType.UInt64: dbType = DbType.UInt64; break; case MySqlDbType.Bit: dbType = DbType.UInt64; break; case MySqlDbType.Float: dbType = DbType.Single; break; case MySqlDbType.Double: dbType = DbType.Double; break; case MySqlDbType.Timestamp: case MySqlDbType.DateTime: dbType = DbType.DateTime; break; case MySqlDbType.Date: case MySqlDbType.Newdate: case MySqlDbType.Year: dbType = DbType.Date; break; case MySqlDbType.Time: dbType = DbType.Time; break; case MySqlDbType.Enum: case MySqlDbType.Set: case MySqlDbType.VarChar: dbType = DbType.String; break; case MySqlDbType.TinyBlob: case MySqlDbType.MediumBlob: case MySqlDbType.LongBlob: case MySqlDbType.Blob: dbType = DbType.Object; break; case MySqlDbType.String: dbType = DbType.StringFixedLength; break; case MySqlDbType.Guid: dbType = DbType.Guid; break; } }
private void SetDbType(DbType db_type) { this.dbType = db_type; switch (this.dbType) { case DbType.AnsiString: case DbType.String: this.mySqlDbType = MySqlDbType.VarChar; goto IL_14B; case DbType.Byte: case DbType.Boolean: this.mySqlDbType = MySqlDbType.UByte; goto IL_14B; case DbType.Currency: case DbType.Decimal: this.mySqlDbType = MySqlDbType.Decimal; goto IL_14B; case DbType.Date: this.mySqlDbType = MySqlDbType.Date; goto IL_14B; case DbType.DateTime: this.mySqlDbType = MySqlDbType.DateTime; goto IL_14B; case DbType.Double: this.mySqlDbType = MySqlDbType.Double; goto IL_14B; case DbType.Guid: this.mySqlDbType = MySqlDbType.Guid; goto IL_14B; case DbType.Int16: this.mySqlDbType = MySqlDbType.Int16; goto IL_14B; case DbType.Int32: this.mySqlDbType = MySqlDbType.Int32; goto IL_14B; case DbType.Int64: this.mySqlDbType = MySqlDbType.Int64; goto IL_14B; case DbType.SByte: this.mySqlDbType = MySqlDbType.Byte; goto IL_14B; case DbType.Single: this.mySqlDbType = MySqlDbType.Float; goto IL_14B; case DbType.Time: this.mySqlDbType = MySqlDbType.Time; goto IL_14B; case DbType.UInt16: this.mySqlDbType = MySqlDbType.UInt16; goto IL_14B; case DbType.UInt32: this.mySqlDbType = MySqlDbType.UInt32; goto IL_14B; case DbType.UInt64: this.mySqlDbType = MySqlDbType.UInt64; goto IL_14B; case DbType.AnsiStringFixedLength: case DbType.StringFixedLength: this.mySqlDbType = MySqlDbType.String; goto IL_14B; } this.mySqlDbType = MySqlDbType.Blob; IL_14B: if (this.dbType == DbType.Object) { byte[] array = this.paramValue as byte[]; if (array != null && array.Length == 25) { this.mySqlDbType = MySqlDbType.Geometry; } } this.ValueObject = MySqlField.GetIMySqlValue(this.mySqlDbType); }
private void SetMySqlDbType(MySqlDbType mysql_dbtype) { mySqlDbType = mysql_dbtype; ValueObject = MySqlField.GetIMySqlValue(mySqlDbType); SetDbTypeFromMySqlDbType(); }
private void SetMySqlDbType(MySqlDbType mysql_dbtype) { this.mySqlDbType = mysql_dbtype; this.ValueObject = MySqlField.GetIMySqlValue(this.mySqlDbType); this.SetDbTypeFromMySqlDbType(); }