12 aur_db_backend
= aurweb
.config
.get('database', 'backend')
14 if aur_db_backend
== 'mysql':
15 aur_db_host
= aurweb
.config
.get('database', 'host')
16 aur_db_name
= aurweb
.config
.get('database', 'name')
17 aur_db_user
= aurweb
.config
.get('database', 'user')
18 aur_db_pass
= aurweb
.config
.get('database', 'password')
19 aur_db_socket
= aurweb
.config
.get('database', 'socket')
20 self
._conn
= mysql
.connector
.connect(host
=aur_db_host
,
24 unix_socket
=aur_db_socket
,
26 self
._paramstyle
= mysql
.connector
.paramstyle
27 elif aur_db_backend
== 'sqlite':
28 aur_db_name
= aurweb
.config
.get('database', 'name')
29 self
._conn
= sqlite3
.connect(aur_db_name
)
30 self
._paramstyle
= sqlite3
.paramstyle
32 raise ValueError('unsupported database backend')
34 def execute(self
, query
, params
=()):
35 if self
._paramstyle
in ('format', 'pyformat'):
36 query
= query
.replace('%', '%%').replace('?', '%s')
37 elif self
._paramstyle
== 'qmark':
40 raise ValueError('unsupported paramstyle')
42 cur
= self
._conn
.cursor()
43 cur
.execute(query
, params
)