예제 #1
0
    public void TestMultiplePrimaryKeys()
    {
        string sch1 = "column: name=f1,type=int,null=0\n" + 
            "column: name=f2,type=int,null=0\n";

        string pk1 = sch1 + "primary-key: column=f1\n";
        string pk2 = pk1 + "primary-key: column=f2\n";
        string expected_sql1 = "CREATE TABLE [testtable] (" + 
            "\n\t[f1] [int] NOT NULL,\n\t[f2] [int] NOT NULL);\n\n\n";
        string expected_pksql1 = "CREATE TABLE [testtable] (\n" + 
            "\t[f1] [int] NOT NULL,\n\t[f2] [int] NOT NULL);\n\n" + 
            "ALTER TABLE [testtable] ADD CONSTRAINT [PK_testtable] " + 
            "PRIMARY KEY NONCLUSTERED\n" + 
            "\t(f1);\n\n\n";

        VxSchemaTable table = new VxSchemaTable("testtable");
        table.text = sch1;
        log.print("Expected sch1: " + expected_sql1 + "\n");
        log.print("Actual sch1: " + table.ToSql() + "\n");
        WVPASSEQ(table.text, sch1);
        WVPASSEQ(table.ToSql(), expected_sql1);
        table.text = pk1;
        WVPASSEQ(table.text, pk1);
        log.print("Expected PK1: " + expected_pksql1 + "\n");
        log.print("Actual PK1: " + table.ToSql() + "\n");
        WVPASSEQ(table.ToSql(), expected_pksql1);
        try {
            WVEXCEPT(table.text = pk2);
        } catch (VxBadSchemaException e) {
            WVPASSEQ(e.Message, "Duplicate table entry 'primary-key' found.");
            log.print(e.ToString() + "\n");
        }
    }
예제 #2
0
    public void TestToSql()
    {
        string tab1schema = "column: name=f1,type=int,null=0\n" + 
            "column: name=f2,type=money,null=0\n" + 
            "column: name=f3,type=varchar,null=0,length=80\n" + 
            "column: name=f4,type=varchar,null=1,length=max,default='Default Value'\n" + 
            "column: name=f5,type=decimal,null=1,precision=3,scale=2\n" + 
            "column: name=f6,type=bigint,null=0,identity_seed=4,identity_incr=5\n" + 
            "primary-key: column=f1,column=f2,clustered=1\n" + 
            "index: name=idx1,column=f3,column=f4,unique=1,clustered=1\n" + 
            "index: name=idx2,column=f5,unique=0\n";

        VxSchemaTable table = new VxSchemaTable("testtable", tab1schema);

        string sql = table.ToSql();

        string expected = "CREATE TABLE [testtable] (\n" + 
            "\t[f1] [int] NOT NULL,\n" +
            "\t[f2] [money] NOT NULL,\n" + 
            "\t[f3] [varchar] (80) NOT NULL,\n" + 
            "\t[f4] [varchar] (max) CONSTRAINT testtable_f4_default DEFAULT 'Default Value' NULL,\n" + 
            "\t[f5] [decimal] (3,2) NULL,\n" +
            "\t[f6] [bigint] NOT NULL IDENTITY (4,5));\n\n" + 
            "ALTER TABLE [testtable] ADD CONSTRAINT [PK_testtable] " + 
            "PRIMARY KEY CLUSTERED\n" + 
            "\t(f1, f2);\n\n" + 
            "CREATE UNIQUE CLUSTERED INDEX [idx1] ON [testtable] \n\t(f3, f4);\n" + 
            "CREATE INDEX [idx2] ON [testtable] \n\t(f5);\n";

        log.print("Returned SQL: " + sql + "\n");
        log.print("Expected: " + expected + "\n");

        WVPASSEQ(sql, expected);

    }
예제 #3
0
    public void TestPKNames()
    {
        string sch1 = "column: name=f1,type=int,null=0\n" + 
            "primary-key: column=f1\n";
        string sch2 = "column: name=f1,type=int,null=0\n" + 
            "primary-key: name=mypkname,column=f1\n";

        string expected_sql1 = "CREATE TABLE [testtable] (\n" + 
            "\t[f1] [int] NOT NULL);\n\n" + 
            "ALTER TABLE [testtable] ADD CONSTRAINT [PK_testtable] " + 
            "PRIMARY KEY NONCLUSTERED\n" + 
            "\t(f1);\n\n\n";
        string expected_sql2 = "CREATE TABLE [testtable] (\n" + 
            "\t[f1] [int] NOT NULL);\n\n" + 
            "ALTER TABLE [testtable] ADD CONSTRAINT [mypkname] " + 
            "PRIMARY KEY NONCLUSTERED\n" + 
            "\t(f1);\n\n\n";
        VxSchemaTable table = new VxSchemaTable("testtable");
        table.text = sch1;
        log.print("Expected sql1: " + expected_sql1 + "\n");
        log.print("Actual sql1: " + table.ToSql() + "\n");
        WVPASSEQ(table.text, sch1);
        WVPASSEQ(table.ToSql(), expected_sql1);
        table.text = sch2;
        WVPASSEQ(table.text, sch2);
        log.print("Expected sql2: " + expected_sql2 + "\n");
        log.print("Actual sql2: " + table.ToSql() + "\n");
        WVPASSEQ(table.ToSql(), expected_sql2);
    }