public IEnumerable <T> ExecuteDeferredQuery <T>(TableMapping map) { if (_conn.Trace) { Debug.WriteLine("Executing Query: " + this); } var stmt = Prepare(); try { var cols = new TableMapping.Column[SQLite3.ColumnCount(stmt)]; for (int i = 0; i < cols.Length; i++) { var name = SQLite3.ColumnName16(stmt, i); cols[i] = map.FindColumn(name); } while (SQLite3.Step(stmt) == SQLite3.Result.Row) { var obj = Activator.CreateInstance(map.MappedType); for (int i = 0; i < cols.Length; i++) { if (cols[i] == null) { continue; } var colType = SQLite3.ColumnType(stmt, i); var val = ReadCol(stmt, i, colType, cols[i].ColumnType); cols[i].SetValue(obj, val); } OnInstanceCreated(obj); yield return((T)obj); } } finally { SQLite3.Finalize(stmt); } }
public object Find(object pk, TableMapping map) { return(Query(map, map.GetByPrimaryKeySql, pk).FirstOrDefault()); }
public IEnumerable <object> DeferredQuery(TableMapping map, string query, params object[] args) { SQLiteCommand sQLiteCommand = CreateCommand(query, args); return(sQLiteCommand.ExecuteDeferredQuery <object>(map)); }
public List <object> Query(TableMapping map, string query, params object[] args) { SQLiteCommand sQLiteCommand = CreateCommand(query, args); return(sQLiteCommand.ExecuteQuery <object>(map)); }
public IEnumerable <T> ExecuteQuery <T>(TableMapping map, object[] source) { CheckDisposed(); Log(nameof(ExecuteQuery), source); OnExecutionStarted(); var sw = Stopwatch.StartNew(); try { var r = Result.OK; if (!Prepared) { Statement = Prepare(); Prepared = true; } //bind the values. if (source != null) { for (int i = 0; i < source.Length; i++) { BindParameter(Statement, i + 1, source[i], Connection.StoreDateTimeAsTicks); } } var cols = new TableColumn[SQLite3.ColumnCount(Statement)]; for (int i = 0; i < cols.Length; i++) { var name = SQLite3.ColumnNameUTF8(Statement, i); cols[i] = map.FindColumn(name); } while (SQLite3.Step(Statement) == Result.Row) { var obj = map.CreateInstance(); for (int i = 0; i < cols.Length; i++) { if (cols[i] == null) { continue; } var colType = SQLite3.ColumnType(Statement, i); var val = ReadCol(Statement, i, colType, cols[i].ColumnType, cols[i].PropertyDefaultValue); cols[i].SetValue(obj, val); } OnInstanceCreated(obj); yield return((T)obj); } if (r == Result.Done || r == Result.OK) { } else { var msg = SQLite3.GetErrorMessageUTF8(Connection.Handle); var ex = new SQLiteException(r, msg, sql: CommandText); ex.PopulateColumnFromTableMapping(map); throw ex; } } finally { if (Statement != null) { SQLite3.Reset(Statement); } sw.Stop(); Log(sw); OnExecutionEnded(); } }
public NotifyTableChangedEventArgs(TableMapping table, NotifyTableChangedAction action, int count) { Table = table; Action = action; Count = count; }
public static NotNullConstraintViolationException New(SQLiteException exception, TableMapping mapping, object obj) { return(new NotNullConstraintViolationException(exception.Result, exception.Message, mapping, obj)); }
public static NotNullConstraintViolationException New(SQLite3.Result r, string message, TableMapping mapping, object obj) { return(new NotNullConstraintViolationException(r, message, mapping, obj)); }
protected NotNullConstraintViolationException(SQLite3.Result r, string message, TableMapping mapping, object obj) : base(r, message) { if (mapping != null && obj != null) { Columns = from c in mapping.Columns where !c.IsNullable && c.GetValue(obj) == null select c; } }
/// <summary> /// Creates a SQLiteCommand given the command text (SQL) with arguments. Place a '?' /// in the command text for each of the arguments and then executes that command. /// It returns each row of the result using the specified mapping. This function is /// only used by libraries in order to query the database via introspection. It is /// normally not used. /// </summary> /// <param name="map"> /// A <see cref="TableMapping"/> to use to convert the resulting rows /// into objects. /// </param> /// <param name="query"> /// The fully escaped SQL. /// </param> /// <param name="args"> /// Arguments to substitute for the occurences of '?' in the query. /// </param> /// <returns> /// An enumerable with one result for each row returned by the query. /// </returns> public IEnumerable <object> Query(TableMapping map, string query, params object[] args) { var cmd = CreateCommand(query, args); return(cmd.ExecuteQuery(map)); }
public TableQuery(SQLiteConnection conn) { Connection = conn; Table = Connection.GetMapping(typeof(T)); }
TableQuery(SQLiteConnection conn, TableMapping table) { Connection = conn; Table = table; }
public List <T> ExecuteQuery <T>(TableMapping map) { return(ExecuteDeferredQuery <T>(map).ToList()); }