예제 #1
0
def test_file_gets_created_on_connect():
    filename = absolute_filename('test.db')
    db = SQLiteDB(filename)
    db._get_connection()
    assert_true(os.path.exists(filename))
    db.close()
    delete_file(filename)
예제 #2
0
    def __init__(self,
                 database_file,
                 table_name,
                 table_schema,
                 key,
                 logger=None):

        if logger is None:
            self.logger = logging.getLogger()
            self.logger.addHandler(logging.NullHandler())
        else:
            self.logger = logger
        self._table_name = table_name
        self._autocommit = True
        self._key = None
        self._columns = None
        self._schema = None
        self._db = SQLiteDB(database_file)
        self._filename = database_file
        self.recreated = False
        # Note: self.schema is a property object
        self.schema = table_schema
        self._check_schema(
        )  # possibly creating the table if it does not exist
        # Note: self.key is a property object
        self.key = key
        self._create_index_if_needed()

        # Remember not to vacuum from any other method than the constructor,
        # since it makes any open transaction commit!
        self._execute("VACUUM")
예제 #3
0
def test_connection_is_singleton():
    filename = absolute_filename('test.db')
    db = SQLiteDB(filename)
    c1 = db._get_connection()
    c2 = db._get_connection()
    assert_true(c1 is c2)
    assert_equal(c1, c2)
    db.close()
    delete_file(filename)
예제 #4
0
def test_each_thread_has_its_own_connection():
    filename = absolute_filename('test.db')
    db = SQLiteDB(filename)
    connection1 = db._get_connection()

    def other_thread():
        connection2 = db._get_connection()
        assert_true(connection1 is connection1)
        assert_false(connection2 is connection1)
        assert_equal(connection1, connection1)
        assert_not_equal(connection2, connection1)
        db.close()

    try:
        t1 = threading.Thread(target=other_thread)
        t1.start()
        t1.join()
    finally:
        db.close()
        delete_file(filename)
예제 #5
0
def test_object_creation():
    SQLiteDB('foobar')
    assert_true(True)
예제 #6
0
def create_onefield_database():
    filename = absolute_filename('test.db')
    delete_file(filename)
    db = SQLiteDB(filename)
    db.execute("CREATE TABLE test (field1 text)")
    return db