root / snf-pithos-backend / pithos / backends / lib / sqlite / dbwrapper.py @ dc7159be
History | View | Annotate | Download (2 kB)
1 | 2e662088 | Antony Chazapis | # Copyright 2011-2012 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | 2715ade4 | Sofia Papagiannaki | #
|
3 | a9b3f29d | Antony Chazapis | # Redistribution and use in source and binary forms, with or
|
4 | a9b3f29d | Antony Chazapis | # without modification, are permitted provided that the following
|
5 | a9b3f29d | Antony Chazapis | # conditions are met:
|
6 | 2715ade4 | Sofia Papagiannaki | #
|
7 | a9b3f29d | Antony Chazapis | # 1. Redistributions of source code must retain the above
|
8 | a9b3f29d | Antony Chazapis | # copyright notice, this list of conditions and the following
|
9 | a9b3f29d | Antony Chazapis | # disclaimer.
|
10 | 2715ade4 | Sofia Papagiannaki | #
|
11 | a9b3f29d | Antony Chazapis | # 2. Redistributions in binary form must reproduce the above
|
12 | a9b3f29d | Antony Chazapis | # copyright notice, this list of conditions and the following
|
13 | a9b3f29d | Antony Chazapis | # disclaimer in the documentation and/or other materials
|
14 | a9b3f29d | Antony Chazapis | # provided with the distribution.
|
15 | 2715ade4 | Sofia Papagiannaki | #
|
16 | a9b3f29d | Antony Chazapis | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | a9b3f29d | Antony Chazapis | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | a9b3f29d | Antony Chazapis | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | a9b3f29d | Antony Chazapis | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | a9b3f29d | Antony Chazapis | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | a9b3f29d | Antony Chazapis | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | a9b3f29d | Antony Chazapis | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | a9b3f29d | Antony Chazapis | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | a9b3f29d | Antony Chazapis | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | a9b3f29d | Antony Chazapis | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | a9b3f29d | Antony Chazapis | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | a9b3f29d | Antony Chazapis | # POSSIBILITY OF SUCH DAMAGE.
|
28 | 2715ade4 | Sofia Papagiannaki | #
|
29 | a9b3f29d | Antony Chazapis | # The views and conclusions contained in the software and
|
30 | a9b3f29d | Antony Chazapis | # documentation are those of the authors and should not be
|
31 | a9b3f29d | Antony Chazapis | # interpreted as representing official policies, either expressed
|
32 | a9b3f29d | Antony Chazapis | # or implied, of GRNET S.A.
|
33 | a9b3f29d | Antony Chazapis | |
34 | 759a5e02 | Antony Chazapis | try:
|
35 | 759a5e02 | Antony Chazapis | from pysqlite2 import dbapi2 as sqlite3 |
36 | 759a5e02 | Antony Chazapis | except ImportError: |
37 | 759a5e02 | Antony Chazapis | import sqlite3 |
38 | 759a5e02 | Antony Chazapis | |
39 | a9b3f29d | Antony Chazapis | |
40 | 2c5363a0 | Antony Chazapis | class DBWrapper(object): |
41 | 2c5363a0 | Antony Chazapis | """Database connection wrapper."""
|
42 | 2715ade4 | Sofia Papagiannaki | |
43 | 2c5363a0 | Antony Chazapis | def __init__(self, db): |
44 | 2c5363a0 | Antony Chazapis | self.conn = sqlite3.connect(db, check_same_thread=False) |
45 | 7759260d | Antony Chazapis | self.conn.execute(""" pragma case_sensitive_like = on """) |
46 | 2715ade4 | Sofia Papagiannaki | |
47 | d14fe290 | Antony Chazapis | def close(self): |
48 | d14fe290 | Antony Chazapis | self.conn.close()
|
49 | 2715ade4 | Sofia Papagiannaki | |
50 | 2c5363a0 | Antony Chazapis | def execute(self): |
51 | 2c5363a0 | Antony Chazapis | self.conn.execute('begin deferred') |
52 | 2715ade4 | Sofia Papagiannaki | |
53 | 2c5363a0 | Antony Chazapis | def commit(self): |
54 | 2c5363a0 | Antony Chazapis | self.conn.commit()
|
55 | 2715ade4 | Sofia Papagiannaki | |
56 | 2c5363a0 | Antony Chazapis | def rollback(self): |
57 | 2c5363a0 | Antony Chazapis | self.conn.rollback() |