# Path: wizzat/pghelper.py
# def copy_from(conn, fp, table_name, columns = None):
# def copy_from_rows(conn, table_name, columns, rows):
# def relation_info(conn, relname, relkind = 'r'):
# def table_columns(conn, table_name):
# def drop_table(conn, table_name):
# def table_exists(conn, table_name):
# def view_exists(conn, view_name):
# def analyze(conn, table_name):
# def vacuum(conn, table_name):
# def currval(conn, sequence):
# def nextval(conn, sequence):
# def sql_where_from_params(**kwargs):
# def pg_conn(conn_info):
#     def __init__(self, conn_info, **kwargs):
#     def new_func(self):
#     def put_func(self, conn):
# class ConnMgr(wizzat.objpool.ObjPool):


from builtins import *
from wizzat.testutil import *
from wizzat import pghelper
import psycopg2, psycopg2.extras
                UNION ALL
                SELECT 3 AS foobar
                UNION ALL
                SELECT 4 AS foobar
            """)

            result2 = pghelper.fetch_results(conn, """
                SELECT 2 AS foobar
                UNION ALL
                SELECT 4 AS foobar
                UNION ALL
                SELECT 6 AS foobar
                UNION ALL
                SELECT 8 AS foobar
            """)

            # We would expect accessing result1 to fail if it isn't cached.
            self.assertEqual([ x["foobar"] for x in result1 ], [ 1, 2, 3, 4 ])
            self.assertEqual([ x["foobar"] for x in result2 ], [ 2, 4, 6, 8 ])

    def test_table_exists(self):
        with psycopg2.connect(**self.db_info) as conn:
            conn.autocommit = False
            pghelper.execute(conn, "DROP TABLE IF EXISTS foobar")
            self.assertEqual(pghelper.table_exists(conn, "foobar"), False);
            conn.commit()


            cur = pghelper.execute(conn, "CREATE TABLE foobar (a INTEGER UNIQUE)")
            conn.commit()

# Path: wizzat/pghelper.py
# def copy_from(conn, fp, table_name, columns = None):
# def copy_from_rows(conn, table_name, columns, rows):
# def relation_info(conn, relname, relkind = 'r'):
# def table_columns(conn, table_name):
# def drop_table(conn, table_name):
# def table_exists(conn, table_name):
# def view_exists(conn, view_name):
# def analyze(conn, table_name):
# def vacuum(conn, table_name):
# def currval(conn, sequence):
# def nextval(conn, sequence):
# def sql_where_from_params(**kwargs):
# def pg_conn(conn_info):
#     def __init__(self, conn_info, **kwargs):
#     def new_func(self):
#     def put_func(self, conn):
# class ConnMgr(wizzat.objpool.ObjPool):


# Path: tests/test_pghelper.py
from builtins import *
from wizzat.testutil import *
from wizzat import pghelper
import psycopg2, psycopg2.extras

                UNION ALL
                SELECT 3 AS foobar
                UNION ALL
                SELECT 4 AS foobar
            """)

            result2 = pghelper.fetch_results(conn, """
                SELECT 2 AS foobar
                UNION ALL
                SELECT 4 AS foobar
                UNION ALL
                SELECT 6 AS foobar
                UNION ALL
                SELECT 8 AS foobar
            """)

            # We would expect accessing result1 to fail if it isn't cached.
            self.assertEqual([ x["foobar"] for x in result1 ], [ 1, 2, 3, 4 ])
            self.assertEqual([ x["foobar"] for x in result2 ], [ 2, 4, 6, 8 ])

    def test_table_exists(self):
        with psycopg2.connect(**self.db_info) as conn:
            conn.autocommit = False
            pghelper.execute(conn, "DROP TABLE IF EXISTS foobar")
            self.assertEqual(pghelper.table_exists(conn, "foobar"), False);
            conn.commit()


            cur = pghelper.execute(conn, "CREATE TABLE foobar (a INTEGER UNIQUE)")
            conn.commit()

            self.assertEqual(pghelper.table_exists(conn, "foobar"), True);