/// <summary> /// Returns the double array of rowid references by the field name. /// Field must have <see cref="TableRepresentation.Reference"/> or <see cref="TableRepresentation.ReferenceArray"/>. /// </summary> /// <param name="type">The type indicating the table.</param> /// <param name="variableName">The name of the field.</param> /// <returns>The double array of rowid references by the field name. Null if the field is not found or the table representation is invalid.</returns> protected long[] RequestReferences(string condition, Type type, string variableName) { if (condition is null || type is null || variableName is null) { return(Array.Empty <long>()); } var request = String.Format(FormatRequestWhere, variableName.ToLowerInvariant(), type.Name, condition); long[] refs = null; try { using var cmd = new SQLiteCommand(request, Connection); using var reader = cmd.ExecuteReader(); if (!reader.Read()) { return(Array.Empty <long>()); } var vi = VariableInfo.FromType(type).FirstOrDefault(x => x.Name.Equals(variableName, StringComparison.InvariantCultureIgnoreCase)); if (vi == null) { return(Array.Empty <long>()); } refs = (GetTableRepresentation(vi.VariableType, DatabaseTableTypes)) switch { TableRepresentation.Reference => new long[] { reader.GetInt64(0) }, TableRepresentation.ReferenceArray => ParseSerializedArray(reader.GetString(0), Base85.DecodeInt64), _ => null }; } catch (InvalidOperationException) { } catch (ArgumentException) { } catch (SQLiteException) { } return(refs ?? Array.Empty <long>()); }
static PlayerGamesChartModel() { var chartValuesInterface = typeof(IChartValues); chartValues = VariableInfo.FromType(typeof(PlayerGamesChartModel), true).Where(vi => chartValuesInterface.IsAssignableFrom(vi.VariableType)).ToArray(); playerGameModelVariables = VariableInfo.FromType(typeof(PlayerGameModel), true); }
/// <summary> /// Returns the first dataset from the <see cref="SQLiteConnection"/> using the provided command. /// </summary> /// <param name="type">Indicates the return type, and which table should be accessed.</param> /// <param name="requestCommand">The REQUEST command sent to the SQLite database.</param> /// <param name="con">The <see cref="SQLiteConnection"/> used.</param> /// <param name="filterTableRepresentation">Masks the <see cref="TableRepresentation"/> of each variable.</param> /// <returns>The first item in the SQLite database fullfilling the conditions of the REQUEST.</returns> protected object ExecuteRequestSingleObject(Type type, string requestCommand, TableRepresentation filterTableRepresentation = TableRepresentation.All) { var varInfos = VariableInfo.FromType(type); object result = null; try { using var cmd = new SQLiteCommand(requestCommand, Connection); using var reader = cmd.ExecuteReader(); result = reader.Read() ? ReadCurrentObject(() => Activator.CreateInstance(type), varInfos, reader, filterTableRepresentation) : null; } catch (InvalidOperationException) { } catch (ArgumentException) { } catch (SQLiteException) { } return(result); }
/// <summary> /// Creates a datatable based on a given type using a provided <see cref="SQLiteConnection"/>. /// </summary> /// <param name="type">Type of the table.</param> /// <param name="con"></param> protected static void CreateDataTable(Type type, SQLiteConnection con) { if (type is null || con is null) { return; } var varInfos = VariableInfo.FromType(type); var definition = new string[varInfos.Length]; int i = 0; foreach (var vi in varInfos) { definition[i++] = String.Format(FormatCreateTableField, vi.Name.ToLowerInvariant(), SQLiteType(vi.VariableType)); } Array.Sort(definition); InvokeNonQuery(String.Format(FormatCreateTable, type.Name, String.Join(", ", definition)), con); }
/// <summary> /// Returns the first dataset from the <see cref="SQLiteConnection"/> using the provided command. /// </summary> /// <typeparam name="T">Indicates the return type, and which table should be accessed.</typeparam> /// <param name="requestCommand">The REQUEST command sent to the SQLite database.</param> /// <param name="filterTableRepresentation">Masks the <see cref="TableRepresentation"/> of each variable.</param> /// <returns>The first item in the SQLite database fullfilling the conditions of the REQUEST.</returns> protected T ExecuteRequestSingleObject <T>(string requestCommand, TableRepresentation filterTableRepresentation = TableRepresentation.All) where T : new() { var type = typeof(T); var varInfos = VariableInfo.FromType(type); T result = default; try { using var cmd = new SQLiteCommand(requestCommand, Connection); using var reader = cmd.ExecuteReader(); result = reader.Read() ? (T)ReadCurrentObject(() => new T(), varInfos, reader, filterTableRepresentation) : default; } catch (InvalidOperationException) { } catch (ArgumentException) { } catch (SQLiteException) { } return(result); }
/// <summary> /// Returns data from the <see cref="SQLiteConnection"/> using the provided command. /// </summary> /// <param name="type">Indicates the return type, and which table should be accessed.</param> /// <param name="requestCommand">The REQUEST command sent to the SQLite database.</param> /// <param name="filterTableRepresentation">Masks the <see cref="TableRepresentation"/> of each variable.</param> /// <returns>All items in the SQLite database fullfilling the conditions of the REQUEST.</returns> protected IList ExecuteRequest(Type type, string requestCommand, TableRepresentation filterTableRepresentation = TableRepresentation.All) { var varInfos = VariableInfo.FromType(type); var result = new List <object>(); try { using var cmd = new SQLiteCommand(requestCommand, Connection); using var reader = cmd.ExecuteReader(); while (reader.Read()) { var obj = ReadCurrentObject(() => Activator.CreateInstance(type), varInfos, reader, filterTableRepresentation); if (obj != null) { result.Add(obj); } } } catch (InvalidOperationException) { } catch (ArgumentException) { } catch (SQLiteException) { } return(result); }
/// <summary> /// Returns data from the <see cref="SQLiteConnection"/> using the provided command. /// </summary> /// <typeparam name="T">Indicates the return type, and which table should be accessed.</typeparam> /// <param name="requestCommand">The REQUEST command sent to the SQLite database.</param> /// <param name="filterTableRepresentation">Masks the <see cref="TableRepresentation"/> of each variable.</param> /// <returns>All items in the SQLite database fullfilling the conditions of the REQUEST.</returns> protected List <T> ExecuteRequest <T>(string requestCommand, TableRepresentation filterTableRepresentation = TableRepresentation.All) where T : new() { var type = typeof(T); var result = new List <T>(); try { var varInfos = VariableInfo.FromType(type); using var cmd = new SQLiteCommand(requestCommand, Connection); using var reader = cmd.ExecuteReader(); while (reader.Read()) { var obj = (T)ReadCurrentObject(() => new T(), varInfos, reader, filterTableRepresentation); if (obj != null) { result.Add(obj); } } } catch (InvalidOperationException) { } catch (ArgumentException) { } catch (SQLiteException) { } return(result); }