Example #1
0
        public void InsertOrUpdateWithIntegers([IncludeDataSources(TestProvNameDb2i.All_71, TestProvNameDb2i.All_72, TestProvNameDb2i.All_73)] string context)
        {
            using (var db = new TestDataConnection(context))
            {
                LinqToDB.ITable <MergeTypesByte> table;
                using (new DisableLogging())
                {
                    db.DropTable <MergeTypesByte>(throwExceptionIfNotExists: false);
                    table = db.CreateTable <MergeTypesByte>();
                }

                ulong val = long.MaxValue;

                table.InsertOrUpdate(
                    () => new MergeTypesByte {
                    FieldByte = 27, FieldULong = val
                },
                    s => new MergeTypesByte {
                    FieldByte = 27, FieldULong = val
                },
                    () => new MergeTypesByte {
                    FieldByte = 22, FieldULong = val
                }
                    );

                Assert.AreEqual(1, table.Count());
            }
        }
Example #2
0
        public void DropSpecificDatabaseTableTest([DataSources(false, TestProvName.AllSapHana)] string context)
        {
            using (var db = new TestDataConnection(context))
            {
                // cleanup
                db.DropTable <DropTableTest>(throwExceptionIfNotExists: false);

                var schema   = TestUtils.GetSchemaName(db);
                var database = TestUtils.GetDatabaseName(db);

                // no idea why, but Access ODBC needs database set in CREATE TABLE for INSERT to work
                // still it doesn't distinguish CREATE TABLE with and without database name
                var table = db.CreateTable <DropTableTest>(databaseName: context == ProviderName.AccessOdbc ? database : null)
                            .SchemaName(schema)
                            .DatabaseName(database);


                table.Insert(() => new DropTableTest()
                {
                    ID = 123
                });

                var data = table.ToList();

                Assert.NotNull(data);
                Assert.AreEqual(1, data.Count);
                Assert.AreEqual(123, data[0].ID);

                table.Drop();

                var sql = db.LastQuery !;

                // check that table dropped
                var exception = Assert.Catch(() => table.ToList());
                Assert.True(exception is Exception);

                // TODO: we need better assertion here
                // Right now we just check generated sql query, not that it is
                // executed properly as we use only one test database
                if (database != TestUtils.NO_DATABASE_NAME)
                {
                    Assert.True(sql.Contains(database));
                }

                if (schema != TestUtils.NO_SCHEMA_NAME)
                {
                    Assert.True(sql.Contains(schema));
                }
            }
        }
Example #3
0
        public void DropSpecificDatabaseTableTest([DataSources(false, ProviderName.SapHana)] string context)
        {
            using (var db = new TestDataConnection(context))
            {
                // cleanup
                db.DropTable <DropTableTest>(throwExceptionIfNotExists: false);

                var schema   = TestUtils.GetSchemaName(db);
                var database = TestUtils.GetDatabaseName(db);

                var table = db.CreateTable <DropTableTest>()
                            .SchemaName(schema)
                            .DatabaseName(database);

                table.Insert(() => new DropTableTest()
                {
                    ID = 123
                });

                var data = table.ToList();

                Assert.NotNull(data);
                Assert.AreEqual(1, data.Count);
                Assert.AreEqual(123, data[0].ID);

                table.Drop();

                var sql = db.LastQuery;

                // check that table dropped
                var exception = Assert.Catch(() => table.ToList());
                Assert.True(exception is Exception);

                // TODO: we need better assertion here
                // Right now we just check generated sql query, not that it is
                // executed properly as we use only one test database
                if (database != TestUtils.NO_DATABASE_NAME)
                {
                    Assert.True(sql.Contains(database));
                }

                if (schema != TestUtils.NO_SCHEMA_NAME)
                {
                    Assert.True(sql.Contains(schema));
                }
            }
        }