Esempio n. 1
0
        public void ThrowExceptionWhenDroppingWithNullSqlConnection()
        {
            Table table = new Table("test");

            table.Columns.Add(new Column("test", DataType.BigInt()));
            Assert.Throws <ArgumentNullException>(() => table.Drop(null));
        }
        private static Table CreateTableWithEveryDataType(string tableName)
        {
            Table table = new Table(tableName);

            table.Columns.AddAll(
                new Column("ID", DataType.BigInt()),
                new Column("Amount", DataType.Int()),
                new Column("Maximum", DataType.TinyInt()),
                new Column("Minimum", DataType.SmallInt()),
                new Column("Payment", DataType.Money()),
                new Column("Change", DataType.SmallMoney()),
                new Column("Decimal", DataType.Decimal()),
                new Column("Decimal-1", DataType.Decimal(10)),
                new Column("Decimal-2", DataType.Decimal(20, 5)),
                new Column("Numeric", DataType.Numeric()),
                new Column("Numeric-1", DataType.Numeric(15)),
                new Column("Numeric-2", DataType.Numeric(22, 11)),
                new Column("VarChar", DataType.VarChar()),
                new Column("VarChar-128", DataType.VarChar(128)),
                new Column("VarChar-MAX", DataType.VarChar(DataType.MAX)),
                new Column("Char", DataType.Char()),
                new Column("Char-256", DataType.Char(256)),
                new Column("VarBinary", DataType.VarBinary()),
                new Column("VarBinary-512", DataType.VarBinary(512)),
                new Column("VarBinary-MAX", DataType.VarBinary(DataType.MAX)),
                new Column("Binary", DataType.Binary()),
                new Column("Binary-1024", DataType.Binary(1024)),
                new Column("NVarChar", DataType.NVarChar()),
                new Column("NVarChar-248", DataType.NVarChar(248)),
                new Column("NVarChar-MAX", DataType.NVarChar(DataType.MAX)),
                new Column("NChar", DataType.NChar()),
                new Column("NChar-400", DataType.NChar(400)),
                new Column("Date", DataType.Date()),
                new Column("DateTime", DataType.DateTime()),
                new Column("DateTime2", DataType.DateTime2()),
                new Column("DateTime2-2", DataType.DateTime2(2)),
                new Column("Time", DataType.Time()),
                new Column("Time-1", DataType.Time(1)),
                new Column("UniqueIdentifier", DataType.UniqueIdentifier())
                );
            return(table);
        }
Esempio n. 3
0
        public void Test_CreateTable_MySQL()
        {
            CleanUpCreateDropTestTable();

            var sql = Db <DBForCreateTest> .Sql(db =>
                                                CreateTable(db.table3,
                                                            new Column(db.table3.obj1, DataType.TinyInt()),
                                                            new Column(db.table3.obj2, DataType.SmallInt()),
                                                            new Column(db.table3.obj3, DataType.MediumInt()),
                                                            new Column(db.table3.obj4, DataType.Int()),
                                                            new Column(db.table3.obj5, DataType.BigInt()),
                                                            new Column(db.table3.obj6, DataType.Float()),
                                                            new Column(db.table3.obj7, DataType.Double()),
                                                            new Column(db.table3.obj8, DataType.Decimal()),
                                                            new Column(db.table3.obj9, DataType.Char(1)),
                                                            new Column(db.table3.obj10, DataType.VarChar(1)),
                                                            new Column(db.table3.obj11, DataType.TinyBlob()),
                                                            new Column(db.table3.obj12, DataType.Blob()),
                                                            new Column(db.table3.obj13, DataType.MediumBlob()),
                                                            new Column(db.table3.obj14, DataType.LongBlob()),
                                                            new Column(db.table3.obj15, DataType.TinyText()),
                                                            new Column(db.table3.obj16, DataType.Text()),
                                                            new Column(db.table3.obj17, DataType.MediumText()),
                                                            new Column(db.table3.obj18, DataType.LongText()),
                                                            new Column(db.table3.obj19, DataType.Enum("a", "b")),
                                                            new Column(db.table3.obj20, DataType.Set("a", "b")),
                                                            new Column(db.table3.obj21, DataType.Date()),
                                                            new Column(db.table3.obj22, DataType.Time()),
                                                            new Column(db.table3.obj23, DataType.DateTime()),
                                                            new Column(db.table3.obj24, DataType.TimeStamp()),
                                                            new Column(db.table3.obj25, DataType.Year())
                                                            ));

            _connection.Execute(sql);
        }
Esempio n. 4
0
        public void returnBigIntType()
        {
            DataType dataType = DataType.BigInt();

            Assert.Equal("bigint", dataType.Definition);
        }
        public void Test_CreateTable_DB2()
        {
            CleanUpCreateDropTestTable();

            var sql = Db <DBForCreateTest> .Sql(db =>
                                                CreateTable(db.table3,
                                                            new Column(db.table3.obj1, DataType.BigInt()),
                                                            new Column(db.table3.obj2, DataType.Binary()),
                                                            new Column(db.table3.obj3, DataType.Blob()),
                                                            new Column(db.table3.obj4, DataType.Char(1)),
                                                            new Column(db.table3.obj5, DataType.Clob()),
                                                            // new Column(db.table3.obj6, DataType.Currency()),
                                                            new Column(db.table3.obj7, DataType.Date()),
                                                            // new Column(db.table3.obj8, DataType.DateTime()),
                                                            new Column(db.table3.obj9, DataType.DbClob()),
                                                            new Column(db.table3.obj10, DataType.Double()),
                                                            new Column(db.table3.obj11, DataType.Float()),
                                                            new Column(db.table3.obj12, DataType.Graphic()),
                                                            new Column(db.table3.obj13, DataType.Int()),
                                                            new Column(db.table3.obj14, DataType.Integer()),
                                                            // new Column(db.table3.obj15, DataType.LongVarchar(1)),
                                                            // new Column(db.table3.obj16, DataType.LongVarGraphic()),
                                                            new Column(db.table3.obj17, DataType.Numeric()),
                                                            new Column(db.table3.obj18, DataType.Real()),
                                                            new Column(db.table3.obj19, DataType.SmallInt()),
                                                            // new Column(db.table3.obj20, DataType.Text()),
                                                            new Column(db.table3.obj21, DataType.Time()),
                                                            new Column(db.table3.obj22, DataType.TimeStamp()),
                                                            new Column(db.table3.obj23, DataType.VarChar(1))
                                                            // new Column(db.table3.obj24, DataType.VarGraphic())
                                                            ));

            _connection.Execute(sql);
        }
Esempio n. 6
0
        public void ReturnCorrectSize()
        {
            DataType dataType = DataType.BigInt();

            Assert.Equal(8, dataType.Size);
        }
Esempio n. 7
0
        public void ReturnCorrectDefinition()
        {
            DataType dataType = DataType.BigInt();

            Assert.Equal("bigint", dataType.Definition);
        }
Esempio n. 8
0
        public void Test_CreateTable_Postgre()
        {
            CleanUpCreateDropTestTable();

            var sql = Db <DBForCreateTest> .Sql(db =>
                                                CreateTable(db.table3,
                                                            new Column(db.table3.obj1, DataType.BigInt()),
                                                            new Column(db.table3.obj2, DataType.BigSerial()),
                                                            new Column(db.table3.obj3, DataType.Bit(1)),
                                                            new Column(db.table3.obj4, DataType.BitVarying(1)),
                                                            new Column(db.table3.obj5, DataType.Boolean()),
                                                            new Column(db.table3.obj6, DataType.Box()),
                                                            new Column(db.table3.obj7, DataType.Bytea()),
                                                            new Column(db.table3.obj8, DataType.Character(1)),
                                                            new Column(db.table3.obj9, DataType.CharacterVarying(1)),
                                                            new Column(db.table3.obj10, DataType.Cidr()),
                                                            new Column(db.table3.obj11, DataType.Circle()),
                                                            new Column(db.table3.obj12, DataType.Date()),
                                                            new Column(db.table3.obj13, DataType.DoublePrecision()),
                                                            new Column(db.table3.obj14, DataType.Inet()),
                                                            new Column(db.table3.obj15, DataType.Integer()),
                                                            new Column(db.table3.obj16, DataType.Interval(IntervalType.Day)),
                                                            new Column(db.table3.obj17, DataType.Json()),
                                                            new Column(db.table3.obj18, DataType.JsonB()),
                                                            new Column(db.table3.obj19, DataType.Line()),
                                                            new Column(db.table3.obj20, DataType.Lseg()),
                                                            new Column(db.table3.obj21, DataType.MacAddr()),
                                                            new Column(db.table3.obj22, DataType.Money()),
                                                            new Column(db.table3.obj23, DataType.Numeric()),//(1, 2)
                                                            new Column(db.table3.obj24, DataType.Path()),
                                                            new Column(db.table3.obj25, DataType.Pg_Lsn()),
                                                            new Column(db.table3.obj26, DataType.Point()),
                                                            new Column(db.table3.obj27, DataType.Polygon()),
                                                            new Column(db.table3.obj28, DataType.Real()),
                                                            new Column(db.table3.obj29, DataType.SmallInt()),
                                                            new Column(db.table3.obj30, DataType.SmallSerial()),
                                                            new Column(db.table3.obj31, DataType.Serial()),
                                                            new Column(db.table3.obj32, DataType.Text()),
                                                            new Column(db.table3.obj33, DataType.Time()),
                                                            new Column(db.table3.obj34, DataType.Time(1)),
                                                            new Column(db.table3.obj35, DataType.TimeStamp()),
                                                            new Column(db.table3.obj36, DataType.TimeStamp(1)),
                                                            new Column(db.table3.obj37, DataType.TsQuery()),
                                                            new Column(db.table3.obj38, DataType.TsVector()),
                                                            new Column(db.table3.obj39, DataType.Txid_Snapshot()),
                                                            new Column(db.table3.obj40, DataType.Uuid()),
                                                            new Column(db.table3.obj41, DataType.Xml()),
                                                            new Column(db.table3.obj42, DataType.TimeWithTimeZone()),
                                                            new Column(db.table3.obj43, DataType.TimeWithTimeZone(1)),
                                                            new Column(db.table3.obj44, DataType.TimeStampWithTimeZone()),
                                                            new Column(db.table3.obj45, DataType.TimeStampWithTimeZone(1))
                                                            ));

            //time zone

            _connection.Execute(sql);
        }
Esempio n. 9
0
        public void Test_CreateTable_SQLite()
        {
            CleanUpCreateDropTestTable();

            var sql = Db <DBForCreateTest> .Sql(db =>
                                                CreateTable(db.table3,
                                                            new Column(db.table3.obj1, DataType.Int()),
                                                            new Column(db.table3.obj2, DataType.Integer()),
                                                            new Column(db.table3.obj3, DataType.TinyInt()),
                                                            new Column(db.table3.obj4, DataType.SmallInt()),
                                                            new Column(db.table3.obj5, DataType.MediumInt()),
                                                            new Column(db.table3.obj6, DataType.BigInt()),
                                                            new Column(db.table3.obj7, DataType.UnsignedBigInt()),
                                                            new Column(db.table3.obj8, DataType.Int2()),
                                                            new Column(db.table3.obj9, DataType.Int8()),
                                                            new Column(db.table3.obj10, DataType.Character(1)),
                                                            new Column(db.table3.obj11, DataType.VarChar(1)),
                                                            new Column(db.table3.obj12, DataType.VaryingCharacter(1)),
                                                            new Column(db.table3.obj13, DataType.NChar(1)),
                                                            new Column(db.table3.obj14, DataType.NativeCharacter(1)),
                                                            new Column(db.table3.obj15, DataType.NVarChar()),
                                                            new Column(db.table3.obj16, DataType.Text()),
                                                            new Column(db.table3.obj17, DataType.Clob()),
                                                            new Column(db.table3.obj18, DataType.Blob()),
                                                            new Column(db.table3.obj19, DataType.Real()),
                                                            new Column(db.table3.obj20, DataType.Double()),
                                                            new Column(db.table3.obj21, DataType.DoublePrecision()),
                                                            new Column(db.table3.obj22, DataType.Float()),
                                                            new Column(db.table3.obj23, DataType.Numeric()),
                                                            new Column(db.table3.obj24, DataType.Decimal()),//(10, 5)
                                                            new Column(db.table3.obj25, DataType.Boolean()),
                                                            new Column(db.table3.obj26, DataType.Date()),
                                                            new Column(db.table3.obj27, DataType.DateTime())
                                                            ));

            _connection.Execute(sql);
        }
        public void Test_CreateTable_SqlServer()
        {
            CleanUpCreateDropTestTable();

            var sql = Db <DBForCreateTest> .Sql(db =>
                                                CreateTable(db.table3,
                                                            new Column(db.table3.obj1, DataType.Bit()),
                                                            new Column(db.table3.obj2, DataType.Date()),
                                                            new Column(db.table3.obj3, DataType.DateTime()),
                                                            new Column(db.table3.obj4, DataType.DateTime2()),
                                                            new Column(db.table3.obj5, DataType.DateTime2(2)),
                                                            new Column(db.table3.obj6, DataType.DateTimeOffset()),
                                                            new Column(db.table3.obj7, DataType.DateTimeOffset(3)),
                                                            new Column(db.table3.obj8, DataType.SmallDateTime()),
                                                            new Column(db.table3.obj9, DataType.Time()),
                                                            new Column(db.table3.obj10, DataType.Time(4)),
                                                            new Column(db.table3.obj11, DataType.Decimal()),
                                                            new Column(db.table3.obj12, DataType.Decimal(5)),
                                                            new Column(db.table3.obj13, DataType.Decimal(6, 6)),
                                                            new Column(db.table3.obj14, DataType.Numeric()),
                                                            new Column(db.table3.obj15, DataType.Numeric(8)),
                                                            new Column(db.table3.obj16, DataType.Numeric(9, 6)),
                                                            new Column(db.table3.obj17, DataType.Float()),
                                                            new Column(db.table3.obj18, DataType.Float(5)),
                                                            new Column(db.table3.obj19, DataType.Real()),
                                                            new Column(db.table3.obj20, DataType.BigInt()),
                                                            new Column(db.table3.obj21, DataType.Int()),
                                                            new Column(db.table3.obj22, DataType.SmallInt()),
                                                            new Column(db.table3.obj23, DataType.TinyInt()),
                                                            new Column(db.table3.obj24, DataType.Money()),
                                                            new Column(db.table3.obj25, DataType.SmallMoney()),
                                                            new Column(db.table3.obj26, DataType.Binary()),
                                                            new Column(db.table3.obj27, DataType.Binary(8)),
                                                            new Column(db.table3.obj28, DataType.VarBinary()),
                                                            new Column(db.table3.obj29, DataType.VarBinary(6)),
                                                            new Column(db.table3.obj30, DataType.Char()),
                                                            new Column(db.table3.obj31, DataType.Char(4)),
                                                            new Column(db.table3.obj32, DataType.VarChar()),
                                                            new Column(db.table3.obj33, DataType.VarChar(7)),
                                                            new Column(db.table3.obj34, DataType.NChar()),
                                                            new Column(db.table3.obj35, DataType.NChar(9)),
                                                            new Column(db.table3.obj36, DataType.NVarChar()),
                                                            new Column(db.table3.obj37, DataType.NVarChar(3)),
                                                            new Column(db.table3.obj38, DataType.NText()),
                                                            new Column(db.table3.obj39, DataType.Text()),
                                                            new Column(db.table3.obj40, DataType.Image()))
                                                );

            _connection.Execute(sql);
            AssertEx.AreEqual(sql, _connection,
                              @"CREATE TABLE table3(
	obj1 BIT,
	obj2 DATE,
	obj3 DATETIME,
	obj4 DATETIME2,
	obj5 DATETIME2(2),
	obj6 DATETIMEOFFSET,
	obj7 DATETIMEOFFSET(3),
	obj8 SMALLDATETIME,
	obj9 TIME,
	obj10 TIME(4),
	obj11 DECIMAL,
	obj12 DECIMAL(5),
	obj13 DECIMAL(6, 6),
	obj14 NUMERIC,
	obj15 NUMERIC(8),
	obj16 NUMERIC(9, 6),
	obj17 FLOAT,
	obj18 FLOAT(5),
	obj19 REAL,
	obj20 BIGINT,
	obj21 INT,
	obj22 SMALLINT,
	obj23 TINYINT,
	obj24 MONEY,
	obj25 SMALLMONEY,
	obj26 BINARY,
	obj27 BINARY(8),
	obj28 VARBINARY,
	obj29 VARBINARY(6),
	obj30 CHAR,
	obj31 CHAR(4),
	obj32 VARCHAR,
	obj33 VARCHAR(7),
	obj34 NCHAR,
	obj35 NCHAR(9),
	obj36 NVARCHAR,
	obj37 NVARCHAR(3),
	obj38 NTEXT,
	obj39 TEXT,
	obj40 IMAGE)"    );
        }