Ejemplo n.º 1
0
        public void Can_Create_Table_with_MaxText_column_Unicode()
        {
            using (var db = OpenDbConnection())
            {
                var stringConverter = DialectProvider.GetStringConverter();
                var hold            = stringConverter.UseUnicode;
                stringConverter.UseUnicode = true;

                try
                {
                    db.DropAndCreateTable <CacheEntry>();
                }
                catch (Exception)
                {
                    db.DropAndCreateTable <CacheEntry>();
                }
                finally
                {
                    stringConverter.UseUnicode = hold;
                }

                var sql = db.GetLastSql();
                sql.Print();

                if (Dialect.Sqlite.HasFlag(Dialect))
                {
                    Assert.That(sql, Does.Contain(" NVARCHAR(1000000)"));
                }
                else if (Dialect.AnyPostgreSql.HasFlag(Dialect))
                {
                    Assert.That(sql, Does.Contain(" TEXT"));
                }
                else if (Dialect.AnyMySql.HasFlag(Dialect))
                {
                    Assert.That(sql, Does.Contain(" LONGTEXT"));
                }
                else if (Dialect.AnyOracle.HasFlag(Dialect))
                {
                    Assert.That(sql, Does.Contain(" NVARCHAR2(4000)"));
                }
                else if (Dialect.Firebird.HasFlag(Dialect))
                {
                    Assert.That(sql, Does.Contain(" VARCHAR(10000)"));
                }
                else
                {
                    Assert.That(sql, Does.Contain(" NVARCHAR(MAX)"));
                }
            }
        }
Ejemplo n.º 2
0
        public void can_create_tables_after_UseUnicode_or_DefaultStringLength_changed()
        {
            //first one passes
            _reCreateTheTable();

            //all of these pass now:
            var stringConverter = DialectProvider.GetStringConverter();

            stringConverter.UseUnicode = true;
            _reCreateTheTable();

            stringConverter.UseUnicode = false;
            _reCreateTheTable();

            stringConverter.StringLength = 98765;

            _reCreateTheTable();
        }
        public void Can_create_ModelWithIdAndName_table_with_specified_DefaultStringLength()
        {
            var converter = DialectProvider.GetStringConverter();
            var hold      = converter.StringLength;

            converter.StringLength = 255;
            var createTableSql = DialectProvider.ToCreateTableStatement(typeof(ModelWithIdAndName));

            Console.WriteLine("createTableSql: " + createTableSql);
            if (Dialect != Dialect.AnyPostgreSql)
            {
                Assert.That(createTableSql, Does.Contain("VARCHAR(255)").
                            Or.Contain("VARCHAR2(255)"));
            }
            else
            {
                Assert.That(createTableSql, Does.Contain("TEXT"));
            }
            converter.StringLength = hold;
        }
        public void Can_change_schema_definitions()
        {
            using (var db = OpenDbConnection())
            {
                var insertDate = new DateTime(2014, 1, 1);

                db.DropAndCreateTable <AuditTableA>();
                var before = db.GetLastSql();

                var idA = db.Insert(new AuditTableA {
                    CreatedDate = insertDate
                }, selectIdentity: true);
                var insertRowA = db.SingleById <AuditTableA>(idA);
                Assert.That(insertRowA.CreatedDate, Is.EqualTo(insertDate));

                var stringConverter = DialectProvider.GetStringConverter();
                var hold            = stringConverter.UseUnicode;
                stringConverter.UseUnicode = true;

                db.DropAndCreateTable <AuditTableA>();
                db.GetLastSql().Print();

                stringConverter.UseUnicode = hold;

                db.DropAndCreateTable <AuditTableA>();
                var after = db.GetLastSql();

                Assert.That(after, Is.EqualTo(before));

                idA = db.Insert(new AuditTableA {
                    CreatedDate = insertDate
                }, selectIdentity: true);
                insertRowA = db.SingleById <AuditTableA>(idA);
                Assert.That(insertRowA.CreatedDate, Is.EqualTo(insertDate));
            }
        }
Ejemplo n.º 5
0
        public void Can_insert_update_and_select_AllTypes()
        {
            using var db = OpenDbConnection();
            if (Dialect == Dialect.Firebird) //Exceeds row limit
            {
                DialectProvider.GetStringConverter().MaxColumnDefinition = "VARCHAR(4000)";
            }

            db.DropAndCreateTable <AllTypes>();
            db.GetLastSql().Print();

            var rows = 3.Times(i => AllTypes.Create(i));

            db.InsertAll(rows);

            var lastRow = rows.Last();

            var dbRow = db.SingleById <AllTypes>(lastRow.Id);

            Assert.That(dbRow, Is.EqualTo(lastRow));

            Assert.That(db.Single <AllTypes>(x => x.NullableId == lastRow.NullableId), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.Byte == lastRow.Byte), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.Short == lastRow.Short), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.Int == lastRow.Int), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.Long == lastRow.Long), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.UShort == lastRow.UShort), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.UInt == lastRow.UInt), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.ULong == lastRow.ULong), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.Decimal == lastRow.Decimal), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.String == lastRow.String), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.DateTime == lastRow.DateTime), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.TimeSpan == lastRow.TimeSpan), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.DateTimeOffset == lastRow.DateTimeOffset), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.Guid == lastRow.Guid), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.Char == lastRow.Char), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.NullableDateTime == lastRow.NullableDateTime), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.NullableTimeSpan == lastRow.NullableTimeSpan), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.CustomText == lastRow.CustomText), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.MaxText == lastRow.MaxText), Is.EqualTo(lastRow));
            Assert.That(db.Single <AllTypes>(x => x.CustomDecimal == lastRow.CustomDecimal), Is.EqualTo(lastRow));

            Assert.That(db.Single(db.From <AllTypes>().Where(x => x.Bool == lastRow.Bool).OrderByDescending(x => x.Id)), Is.EqualTo(lastRow));

            var updatedRows = 3.Times(i =>
            {
                var updated = AllTypes.Create(i + 3);
                updated.Id  = i + 1;
                db.Update(updated);
                return(updated);
            });

            var lastUpdatedRow = updatedRows.Last();
            var dbUpdatedRow   = db.SingleById <AllTypes>(lastUpdatedRow.Id);

            Assert.That(dbUpdatedRow, Is.EqualTo(lastUpdatedRow));

            if (Dialect == Dialect.Firebird)
            {
                DialectProvider.GetStringConverter().MaxColumnDefinition = null;
            }
        }