Exemplo n.º 1
0
def connection(request):
    connection = con.connect()
    request.addfinalizer(con.disconnect)

    cursor = connection.cursor()

    con.drop_tables()

    cursor.execute("""create table table1 (
    id serial unique, 
    name varchar(20) not null,
    value varchar(20),
    primary key (id, name)
    );""")

    cursor.execute("""create table table2 (
    id serial, 
    name varchar(20) not null,
    table1_id integer,
    primary key (id),
    foreign key (table1_id) references table1(id)
    );""")

    cursor.execute("""create table table3 (
    value varchar(20) not null
    );""")

    connection.commit()

    mro.load_database(connection)

    create_test_data(connection)

    return connection
Exemplo n.º 2
0
def connection(request):
    connection = con.connect()
    request.addfinalizer(con.disconnect)

    cursor = connection.cursor()

    con.drop_tables()

    cursor.execute("""create table test_type (
    id serial primary key,
    "varchar" varchar(15), 
    "varchar2" varchar(20), 
    "varchar_not_null" varchar(20) not null default 'abc',
    "integer" integer,
    "boolean" boolean,
    "time" time,
    "date" date,
    "timestamp" timestamp,
    "json" json,
    "jsonb" jsonb,
    "text" text,
    "double" double precision,
    "real" real)""")
    connection.commit()

    mro.load_database(connection)

    return connection
Exemplo n.º 3
0
def connection(request):
    connection = con.connect()
    request.addfinalizer(con.disconnect)

    cursor = connection.cursor()

    con.drop_tables()

    cursor.execute("create table table1 (id serial primary key, column1 integer, column2 varchar(20), column3 integer)")
    cursor.execute("create table table2 (id serial primary key, column1 varchar(20), column2 integer, column3 varchar(20))")
    cursor.execute("insert into table1 (column1, column2, column3) values (%s,%s,%s)", (1,'Hellow World!', 2))
    cursor.execute("insert into table1 (column1, column2, column3) values (%s,%s,%s)", (2,'Hellow World2!', 3))
    cursor.execute("insert into table2 (column1, column2, column3) values (%s,%s,%s)", ('Hellow World3!', 4, 'Hellow World4!'))
    connection.commit()

    return connection
Exemplo n.º 4
0
def connection(request):
    connection = con.connect()
    request.addfinalizer(con.disconnect)

    cursor = connection.cursor()

    con.drop_tables()

    cursor.execute("create table table1 (id serial primary key, created_date date not null default current_date, column1 integer default 1, column2 varchar(20), column3 integer)")
    cursor.execute("create table table2 (column1 varchar(20), column2 integer, column3 varchar(20))")
    cursor.execute("create table table3 (created_datetime timestamp not null default current_timestamp, created_time time not null default current_time, column1 varchar(20) default 'ABC DEF', column2 integer, column3 varchar(20), column4 jsonb)")
    cursor.execute("insert into table1 (column1, column2, column3) values (%s,%s,%s)", (1,'Hello World!', 2))
    cursor.execute("insert into table1 (column1, column2, column3) values (%s,%s,%s)", (2,'Hello World2!', 3))
    cursor.execute("insert into table2 values (%s,%s,%s)", ('Hello World3!', 4, 'Hello World4!'))
    connection.commit()

    return connection