예제 #1
0
        internal void AddToTable(Table table, SQLiteConnection connection)
        {
            Cells.CheckColumns(table.Columns);
            if (!Cells.Any())
            {
                throw new InvalidOperationException(Resources.ZeroCellsInsert.FormatExt(table.Name));
            }
            CheckMissedColumns(table);
            CheckPrimaryCells(table);

            var insert = InsertSql.FormatExt(table.Name,
                                             Cells.Select(x => x.Column.Name.EscapeIdentifier()).JoinExt(","),
                                             Cells.Select(x => x.ParamName).JoinExt(","));

            using (var command = new SQLiteCommand(insert, connection))
            {
                command.Parameters.AddRange(Cells.Select(x => x.ToParameter()).ToArray());
                command.ExecuteNonQuery();
            }
            RowId = connection.LastInsertRowId;
            Table = table;
            Reload(connection); // Reload in order to fill auto-filled cells (like autoincrement).
        }