コード例 #1
0
ファイル: api08.py プロジェクト: drewdolan/datatest
 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
コード例 #2
0
ファイル: api08.py プロジェクト: drewdolan/datatest
    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
コード例 #3
0
 def test_existing_table_and_temptable(self):
     self.cursor.execute('CREATE TABLE tbl0 (col1, col2)')
     self.cursor.execute('CREATE TEMPORARY TABLE tbl1 (col1, col2)')
     table_name = new_table_name(self.cursor)
     self.assertEqual(table_name, 'tbl2')
コード例 #4
0
 def test_empty_database(self):
     table_name = new_table_name(self.cursor)
     self.assertEqual(table_name, 'tbl0')