Esempio n. 1
0
    def test(self):
        sql = sqlgen.create_table(sqlgen.DIALECT_SQLITE, Foo)
        self.assertEquals(
            """CREATE TABLE foo (
    foo_id INTEGER PRIMARY KEY,
    i1 INTEGER NOT NULL,
    s1 TEXT NOT NULL COLLATE NOCASE,
    d1 TEXT
)""",
            sql,
        )
        sql = sqlgen.create_table(sqlgen.DIALECT_POSTGRES, Foo)
        self.assertEquals(
            """CREATE TABLE foo (
    foo_id SERIAL UNIQUE,
    i1 BIGINT NOT NULL,
    s1 VARCHAR(10) NOT NULL COLLATE "C",
    d1 DATE
)""",
            sql,
        )
        sql = sqlgen.create_table(sqlgen.DIALECT_MYSQL, Foo)
        self.assertEquals(
            """CREATE TABLE foo (
    foo_id BIGINT AUTO_INCREMENT PRIMARY KEY,
    i1 BIGINT NOT NULL,
    s1 VARCHAR(10) CHARACTER SET utf8 NOT NULL COLLATE utf8_general_ci,
    d1 DATE
) ENGINE=INNODB""",
            sql,
        )
        sql = sqlgen.create_table(sqlgen.DIALECT_SQLITE, Bar)
        self.assertEquals(
            """CREATE TABLE bar (
    bi INTEGER,
    bs TEXT NOT NULL,
    bd TEXT,
    bdt1 TEXT,
    bb INTEGER NOT NULL
)""",
            sql,
        )
        sql = sqlgen.create_table(sqlgen.DIALECT_POSTGRES, Bar)
        self.assertEquals(
            """CREATE TABLE bar (
    bi BIGINT,
    bs VARCHAR(10) NOT NULL,
    bd DATE,
    bdt1 TIMESTAMP,
    bb BOOLEAN NOT NULL
)""",
            sql,
        )
        sql = sqlgen.create_table(sqlgen.DIALECT_MYSQL, Bar)
        self.assertEquals(
            """CREATE TABLE bar (
    bi BIGINT,
    bs VARCHAR(10) CHARACTER SET utf8 NOT NULL,
    bd DATE,
    bdt1 DATETIME,
    bb BOOL NOT NULL
) ENGINE=INNODB""",
            sql,
        )
        sql = sqlgen.create_table(sqlgen.DIALECT_SQLITE, Baz)
        self.assertEquals(
            """CREATE TABLE baz (
    baz_id INTEGER PRIMARY KEY,
    f3 REAL NOT NULL,
    s3 TEXT NOT NULL UNIQUE
)""",
            sql,
        )
        sql = sqlgen.create_table(sqlgen.DIALECT_POSTGRES, Baz)
        self.assertEquals(
            """CREATE TABLE baz (
    baz_id SERIAL UNIQUE,
    f3 DOUBLE PRECISION NOT NULL,
    s3 VARCHAR(5) NOT NULL UNIQUE
)""",
            sql,
        )
        sql = sqlgen.create_table(sqlgen.DIALECT_MYSQL, Baz)
        self.assertEquals(
            """CREATE TABLE baz (
    baz_id BIGINT AUTO_INCREMENT PRIMARY KEY,
    f3 DOUBLE PRECISION NOT NULL,
    s3 VARCHAR(5) CHARACTER SET utf8 NOT NULL UNIQUE
) ENGINE=INNODB""",
            sql,
        )
Esempio n. 2
0
 def create_table(self, table):
     # read only check
     self._check_write_ok()
     #
     sql = sqlgen.create_table(self.dialect, table)
     self._execute(sql)