private static void GetNullOutputParameterSmi(SmiMetaData metaData, SqlBuffer targetBuffer, ref object result) { if (SqlDbType.Udt == metaData.SqlDbType) { result = NullUdtInstance(metaData); } else { SqlBuffer.StorageType stype = SqlDbTypeToStorageType(metaData.SqlDbType); if (SqlBuffer.StorageType.Empty == stype) { result = DBNull.Value; } else if (SqlBuffer.StorageType.SqlBinary == stype) { // special case SqlBinary, 'cause tds parser never sets SqlBuffer to null, just to empty! targetBuffer.SqlBinary = SqlBinary.Null; } else if (SqlBuffer.StorageType.SqlGuid == stype) { targetBuffer.SqlGuid = SqlGuid.Null; } else { targetBuffer.SetToNullOfType(stype); } } }
// UDTs and null variants come back via return value, all else is via targetBuffer. // implements SqlClient 1.1-compatible output parameter semantics internal static object GetOutputParameterV200Smi( SmiEventSink_Default sink, // event sink for errors SmiTypedGetterSetter getters, // getters interface to grab value from int ordinal, // parameter within getters SmiMetaData metaData, // Getter's type for this ordinal SmiContext context, // used to obtain scratch streams SqlBuffer targetBuffer // destination ) { object result = null; // Workaround for UDT hack in non-Smi code paths. if (IsDBNull_Unchecked(sink, getters, ordinal)) { GetNullOutputParameterSmi(metaData, targetBuffer, ref result); } else { switch (metaData.SqlDbType) { // new types go here case SqlDbType.Variant: // Handle variants specifically for v200, since they could contain v200 types // For variants, recur using the current value's sqldbtype metaData = getters.GetVariantType(sink, ordinal); sink.ProcessMessagesAndThrow(); Debug.Assert(SqlDbType.Variant != metaData.SqlDbType, "Variant-within-variant not supposed to be possible!"); GetOutputParameterV200Smi(sink, getters, ordinal, metaData, context, targetBuffer); break; case SqlDbType.Date: targetBuffer.SetToDate(GetDateTime_Unchecked(sink, getters, ordinal)); break; case SqlDbType.DateTime2: targetBuffer.SetToDateTime2(GetDateTime_Unchecked(sink, getters, ordinal), metaData.Scale); break; case SqlDbType.Time: targetBuffer.SetToTime(GetTimeSpan_Unchecked(sink, getters, ordinal), metaData.Scale); break; case SqlDbType.DateTimeOffset: targetBuffer.SetToDateTimeOffset(GetDateTimeOffset_Unchecked(sink, getters, ordinal), metaData.Scale); break; default: result = GetOutputParameterV3Smi(sink, getters, ordinal, metaData, context, targetBuffer); break; } } return(result); }
/// <summary> /// Returns a specified number of contiguous elements from the start of the set. /// </summary> /// <param name="count">The number of elements to return.</param> /// <returns>A new <see cref="SqlSet"/> that contains the specified number of elements from the start of the current set.</returns> public SqlSet Take(int count) { bool ignoreBuffer = this.buffer.Take == null; var newBuffer = new SqlBuffer( where : (ignoreBuffer) ? this.buffer.Where : null, orderBy: (ignoreBuffer) ? this.buffer.OrderBy : null, skip: (ignoreBuffer) ? this.buffer.Skip : null, take: count ); SqlSet set = CreateBufferedSet(ignoreBuffer, newBuffer); return(set); }
/// <summary> /// Sorts the elements of the set according to the <paramref name="columnList"/>. /// </summary> /// <param name="columnList">The list of columns to base the sort on.</param> /// <param name="parameters">The parameters to apply to the <paramref name="columnList"/>.</param> /// <returns>A new <see cref="SqlSet"/> whose elements are sorted according to <paramref name="columnList"/>.</returns> public SqlSet OrderBy(string columnList, params object[] parameters) { bool ignoreBuffer = this.buffer.OrderBy == null && this.buffer.Skip == null && this.buffer.Take == null; var newBuffer = new SqlBuffer( where : (ignoreBuffer) ? this.buffer.Where : null, orderBy: new SqlFragment(columnList, parameters), skip: null, take: null ); SqlSet set = CreateBufferedSet(ignoreBuffer, newBuffer); return(set); }
internal SqlSet <TResult> CreateBufferedSet <TResult>(bool ignoreBuffer, SqlBuffer buffer) { SqlSet <TResult> set = null; if (ignoreBuffer && this.definingQuery == null) { set = CreateSet <TResult>(this.fromSelect, buffer); } if (set == null) { SqlBuilder query = GetDefiningQuery(ignoreBuffer: ignoreBuffer); set = CreateSet <TResult>(query, default(Func <IDataRecord, TResult>), buffer); } return(set); }
internal SqlSet CreateBufferedSet(bool ignoreBuffer, SqlBuffer buffer, Type resultType = null) { SqlSet set = null; if (ignoreBuffer && this.definingQuery == null) { set = CreateSet(this.fromSelect, resultType, buffer); } if (set == null) { SqlBuilder query = GetDefiningQuery(ignoreBuffer: ignoreBuffer); set = CreateSet(query, resultType, buffer); } return(set); }
private SqlSet(SqlSet set, Type resultType, SqlBuffer?buffer) { if (set == null) { throw new ArgumentNullException(nameof(set)); } this.ResultType = set.ResultType; this.setIndex += set.setIndex; this.db = set.db; if (resultType != null) { this.ResultType = resultType; } if (buffer != null) { this.buffer = buffer.Value; } Initialize2(set); }
public void Setup() { AppSettings.Instance = new AppSettings(); AppSettings.Instance.MySqlDatabase = dataBase; AppSettings.Instance.CurrentUser = user; TimeServer.SqlCurrentUser = user; var buf = SqlBuffer.Load(); buf.ClearBuffer(); buf.Save(); MySqlConnectionStringBuilder mysqlBuiler = new MySqlConnectionStringBuilder() { Server = "localhost", UserID = "WendallMartin", Password = "******", Port = 3306, SslMode = MySqlSslMode.Required }; _instance = new TheTimeApp.TimeData.MySql(mysqlBuiler, TheTimeApp.TimeData.MySql.UpdateModes.Sync); _instance.AddUser(new User(user, "", new List <Day>())); _instance.ClearBuffer(); }
public bool InsertData(List <double> nomreListSorted, DataTable listStudents) { try { _buffer = new SqlBuffer(); for (int i = 0; i < nomreListSorted.Count; i++) { _buffer.AddQuery($@"INSERT INTO Workbook_tbl (Student_Id,Lessson_Id,Nomre) VALUES({listStudents.Rows[i][0]},{int.Parse(cmbLesson.SelectedValue.ToString())},{nomreListSorted[i]})"); } int resultCount = _buffer.WriteBufferToDb(); if (resultCount > 0) { return(true); } return(false);//else } catch { return(false); } }
// UDTs and null variants come back via return value, all else is via targetBuffer. // implements SqlClient 2.0-compatible output parameter semantics internal static object GetOutputParameterV3Smi( SmiEventSink_Default sink, // event sink for errors ITypedGettersV3 getters, // getters interface to grab value from int ordinal, // parameter within getters SmiMetaData metaData, // Getter's type for this ordinal SmiContext context, // used to obtain scratch streams SqlBuffer targetBuffer // destination ) { object result = null; // Workaround for UDT hack in non-Smi code paths. if (IsDBNull_Unchecked(sink, getters, ordinal)) { GetNullOutputParameterSmi(metaData, targetBuffer, ref result); } else { switch (metaData.SqlDbType) { case SqlDbType.BigInt: targetBuffer.Int64 = GetInt64_Unchecked(sink, getters, ordinal); break; case SqlDbType.Binary: case SqlDbType.Image: case SqlDbType.Timestamp: case SqlDbType.VarBinary: targetBuffer.SqlBinary = GetSqlBinary_Unchecked(sink, getters, ordinal); break; case SqlDbType.Bit: targetBuffer.Boolean = GetBoolean_Unchecked(sink, getters, ordinal); break; case SqlDbType.NChar: case SqlDbType.NText: case SqlDbType.NVarChar: case SqlDbType.Char: case SqlDbType.VarChar: case SqlDbType.Text: targetBuffer.SetToString(GetString_Unchecked(sink, getters, ordinal)); break; case SqlDbType.DateTime: case SqlDbType.SmallDateTime: { SqlDateTime dt = new(GetDateTime_Unchecked(sink, getters, ordinal)); targetBuffer.SetToDateTime(dt.DayTicks, dt.TimeTicks); break; } case SqlDbType.Decimal: { SqlDecimal dec = GetSqlDecimal_Unchecked(sink, getters, ordinal); targetBuffer.SetToDecimal(dec.Precision, dec.Scale, dec.IsPositive, dec.Data); break; } case SqlDbType.Float: targetBuffer.Double = GetDouble_Unchecked(sink, getters, ordinal); break; case SqlDbType.Int: targetBuffer.Int32 = GetInt32_Unchecked(sink, getters, ordinal); break; case SqlDbType.Money: case SqlDbType.SmallMoney: targetBuffer.SetToMoney(GetInt64_Unchecked(sink, getters, ordinal)); break; case SqlDbType.Real: targetBuffer.Single = GetSingle_Unchecked(sink, getters, ordinal); break; case SqlDbType.UniqueIdentifier: targetBuffer.SqlGuid = new SqlGuid(GetGuid_Unchecked(sink, getters, ordinal)); break; case SqlDbType.SmallInt: targetBuffer.Int16 = GetInt16_Unchecked(sink, getters, ordinal); break; case SqlDbType.TinyInt: targetBuffer.Byte = GetByte_Unchecked(sink, getters, ordinal); break; case SqlDbType.Variant: // For variants, recur using the current value's sqldbtype metaData = getters.GetVariantType(sink, ordinal); sink.ProcessMessagesAndThrow(); Debug.Assert(SqlDbType.Variant != metaData.SqlDbType, "Variant-within-variant not supposed to be possible!"); GetOutputParameterV3Smi(sink, getters, ordinal, metaData, context, targetBuffer); break; case SqlDbType.Udt: result = GetUdt_LengthChecked(sink, getters, ordinal, metaData); break; case SqlDbType.Xml: targetBuffer.SqlXml = GetSqlXml_Unchecked(sink, getters, ordinal, null); break; default: Debug.Assert(false, "Unexpected SqlDbType"); break; } } return(result); }