Exemplo n.º 1
0
        public void InsertData_WhenCalled_InsertsData()
        {
            var table = new DataTable();

            table.Columns.Add("boolColumn", typeof(bool));
            table.Columns.Add("dateColumn", typeof(DateTime));
            table.Columns.Add("longColumn", typeof(long));
            table.Columns.Add("textColumn", typeof(string));
            table.Columns.Add("noTypeColumn");

            var row = table.NewRow();

            row[0] = true;
            row[1] = DateTime.Now;
            row[2] = long.MaxValue;
            row[3] = "string";
            row[4] = "";

            var parameters = new Tuple <string, object>[] {
                new Tuple <string, object>("param0", true),
                new Tuple <string, object>("param1", DateTime.Now),
                new Tuple <string, object>("param2", long.MaxValue),
                new Tuple <string, object>("param3", "string"),
                new Tuple <string, object>("param4", "")
            };
            var query = $"INSERT INTO table([boolColumn], [dateColumn], [longColumn], [textColumn], [noTypeColumn]) " +
                        $"VALUES ({string.Join(", ", parameters.Select(p => p.Item1))})";

            dbBuilder.InsertData(row);

            sqliteService.Verify(x =>
                                 x.ExecuteQuery(query, null, It.IsAny <IEnumerable <Tuple <string, object> > >()));
        }
Exemplo n.º 2
0
        private void StoreDataToDb(object sender, EventArgs e)
        {
            const string tableName = "myTable";
            const string dbName    = "temp.sqlite";
            string       dbPath    = Application.StartupPath + "\\" + dbName;

            if (File.Exists(dbPath))
            {
                File.Delete(dbPath);
            }
            var sqliteService = new SqliteService(tableName, dbPath);

            var dbBuilder = new DbBuilder(tableName, sqliteService);

            dbBuilder.CreateTable(_dataTable.Columns);
            dbBuilder.InsertData(_dataTable.Rows);
        }
Exemplo n.º 3
0
        private void View_OnStoreDb(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;


            if (File.Exists(DbPath))
            {
                File.Delete(DbPath);
            }


            var dbBuilder = new DbBuilder(
                DbPath,
                TableName,
                ExcelTable,
                ColumnInfos.Where(info => info.Keep).ToList(),
                View.XCoordinateHeader,
                View.YCoordinateHeader,
                View.Projection
                );

            dbBuilder.CreateTable();
            dbBuilder.InsertData();
        }