Ejemplo n.º 1
0
    def test_drop_table(self):
        connection = sqlite3.connect(':memory:')
        cursor = connection.cursor()

        cursor.execute('CREATE TEMPORARY TABLE test_table ("A", "B")')
        self.assertTrue(table_exists(cursor, 'test_table'))

        drop_table(cursor, 'test_table')  # <- Drop table!
        self.assertFalse(table_exists(cursor, 'test_table'))
Ejemplo n.º 2
0
    def test_empty_records(self):
        records = []

        load_data(self.cursor, 'testtable1', ['A', 'B'], records)  # <- Using four args.
        self.assertTrue(table_exists(self.cursor, 'testtable1'), 'should create table')
        self.cursor.execute('SELECT A, B FROM testtable1')
        self.assertEqual(self.cursor.fetchall(), [], 'should have zero records')

        load_data(self.cursor, 'testtable2', records)  # <- Using three args.
        self.assertFalse(table_exists(self.cursor, 'testtable2'), 'should not create table')
Ejemplo n.º 3
0
 def from_excel(cls, path, worksheet=0):
     new_cls = cls.__new__(cls)
     new_cls._connection = DEFAULT_CONNECTION
     cursor = new_cls._connection.cursor()
     with savepoint(cursor):
         table = new_table_name(cursor)
         reader = get_reader.from_excel(path, worksheet=0)
         load_data(cursor, table, reader)
     new_cls._table = table if table_exists(cursor, table) else None
     new_cls._data = path
     new_cls._args = tuple()
     new_cls._kwds = dict()
     if worksheet != 0:
         new_cls._kwds['worksheet'] = worksheet
     new_cls._update_list = []
     return new_cls
Ejemplo n.º 4
0
    def from_csv(cls, file, encoding=None, **fmtparams):
        if isinstance(file, string_types) or isinstance(file, file_types):
            data_list = [file]
        else:
            data_list = file

        new_cls = cls.__new__(cls)
        new_cls._connection = DEFAULT_CONNECTION
        cursor = new_cls._connection.cursor()
        with savepoint(cursor):
            table = new_table_name(cursor)
            for obj in data_list:
                load_csv(cursor, table, obj, encoding=encoding, **fmtparams)
        new_cls._table = table if table_exists(cursor, table) else None
        new_cls._data = file
        new_cls._args = (encoding, )
        new_cls._kwds = fmtparams
        new_cls._update_list = []
        return new_cls
Ejemplo n.º 5
0
 def test_temporary_table(self):
     self.cursor.execute('CREATE TEMPORARY TABLE table_c (col1, col2)')
     self.assertTrue(table_exists(self.cursor, 'table_c'))
Ejemplo n.º 6
0
 def test_persistent_table(self):
     self.cursor.execute('CREATE TABLE table_b (col1, col2)')
     self.assertTrue(table_exists(self.cursor, 'table_b'))
Ejemplo n.º 7
0
 def test_empty_database(self):
     self.assertFalse(table_exists(self.cursor, 'table_a'))