DB-API: moved from github:gramps-project/addons-source
This commit is contained in:
parent
64a3b6570d
commit
2cf95cd866
33
gramps/plugins/database/dbapi.gpr.py
Normal file
33
gramps/plugins/database/dbapi.gpr.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#
|
||||||
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
|
#
|
||||||
|
# Copyright (C) 2015 Douglas Blank <doug.blank@gmail.com>
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
#
|
||||||
|
|
||||||
|
register(DATABASE,
|
||||||
|
id = 'dbapi',
|
||||||
|
name = _("DB-API 2.0 Database Backend"),
|
||||||
|
name_accell = _("DB-_API 2.0 Database Backend"),
|
||||||
|
description = _("DB-API 2.0 Database Backend"),
|
||||||
|
version = '1.0.32',
|
||||||
|
gramps_target_version = "5.0",
|
||||||
|
status = STABLE,
|
||||||
|
fname = 'dbapi.py',
|
||||||
|
databaseclass = 'DBAPI',
|
||||||
|
authors=['Doug Blank'],
|
||||||
|
authors_email=["doug.blank@gmail.com"],
|
||||||
|
)
|
1721
gramps/plugins/database/dbapi.py
Normal file
1721
gramps/plugins/database/dbapi.py
Normal file
File diff suppressed because it is too large
Load Diff
0
gramps/plugins/database/dbapi_support/__init__.py
Normal file
0
gramps/plugins/database/dbapi_support/__init__.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
## ----------------------------------------------
|
||||||
|
## Postgresql
|
||||||
|
## ----------------------------------------------
|
||||||
|
|
||||||
|
#from dbapi_support.postgresql import Postgresql
|
||||||
|
#dbapi = Postgresql(dbname='mydb', user='postgres',
|
||||||
|
# host='localhost', password='PASSWORD')
|
||||||
|
|
||||||
|
## ----------------------------------------------
|
||||||
|
## MySQL
|
||||||
|
## ----------------------------------------------
|
||||||
|
|
||||||
|
#from dbapi_support.mysql import MySQL
|
||||||
|
#dbapi = MySQL("localhost", "root", "PASSWORD", "mysqldb",
|
||||||
|
# charset='utf8', use_unicode=True)
|
||||||
|
|
||||||
|
## ----------------------------------------------
|
||||||
|
## Sqlite
|
||||||
|
## ----------------------------------------------
|
||||||
|
|
||||||
|
from dbapi_support.sqlite import Sqlite
|
||||||
|
path_to_db = os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
||||||
|
'sqlite.db')
|
||||||
|
dbapi = Sqlite(path_to_db)
|
37
gramps/plugins/database/dbapi_support/mysql.py
Normal file
37
gramps/plugins/database/dbapi_support/mysql.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import MySQLdb
|
||||||
|
|
||||||
|
MySQLdb.paramstyle = 'qmark' ## Doesn't work
|
||||||
|
|
||||||
|
class MySQL(object):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.connection = MySQLdb.connect(*args, **kwargs)
|
||||||
|
|
||||||
|
def execute(self, query, args=[]):
|
||||||
|
## Workaround: no qmark support
|
||||||
|
query = query.replace("?", "%s")
|
||||||
|
self.cursor = self.connection.cursor()
|
||||||
|
self.cursor.execute(query, args)
|
||||||
|
|
||||||
|
def fetchone(self):
|
||||||
|
return self.cursor.fetchone()
|
||||||
|
|
||||||
|
def fetchall(self):
|
||||||
|
return self.cursor.fetchall()
|
||||||
|
|
||||||
|
def commit(self):
|
||||||
|
self.connection.commit()
|
||||||
|
|
||||||
|
def rollback(self):
|
||||||
|
self.connection.rollback()
|
||||||
|
|
||||||
|
def try_execute(self, sql):
|
||||||
|
try:
|
||||||
|
cursor = self.connection.cursor()
|
||||||
|
cursor.execute(sql)
|
||||||
|
self.connection.commit()
|
||||||
|
except Exception as exc:
|
||||||
|
self.connection.rollback()
|
||||||
|
#print(str(exc))
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.connection.close()
|
36
gramps/plugins/database/dbapi_support/postgresql.py
Normal file
36
gramps/plugins/database/dbapi_support/postgresql.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import pg8000
|
||||||
|
|
||||||
|
pg8000.paramstyle = 'qmark'
|
||||||
|
|
||||||
|
class Postgresql(object):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.connection = pg8000.connect(*args, **kwargs)
|
||||||
|
|
||||||
|
def execute(self, *args, **kwargs):
|
||||||
|
self.cursor = self.connection.cursor()
|
||||||
|
self.cursor.execute(*args, **kwargs)
|
||||||
|
|
||||||
|
def fetchone(self):
|
||||||
|
return self.cursor.fetchone()
|
||||||
|
|
||||||
|
def fetchall(self):
|
||||||
|
return self.cursor.fetchall()
|
||||||
|
|
||||||
|
def commit(self):
|
||||||
|
self.connection.commit()
|
||||||
|
|
||||||
|
def rollback(self):
|
||||||
|
self.connection.rollback()
|
||||||
|
|
||||||
|
def try_execute(self, sql):
|
||||||
|
sql = sql.replace("BLOB", "bytea")
|
||||||
|
try:
|
||||||
|
cursor = self.connection.cursor()
|
||||||
|
cursor.execute(sql)
|
||||||
|
self.connection.commit()
|
||||||
|
except Exception as exc:
|
||||||
|
self.connection.rollback()
|
||||||
|
#print(str(exc))
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.connection.close()
|
34
gramps/plugins/database/dbapi_support/sqlite.py
Normal file
34
gramps/plugins/database/dbapi_support/sqlite.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import os
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
sqlite3.paramstyle = 'qmark'
|
||||||
|
|
||||||
|
class Sqlite(object):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
self.connection = sqlite3.connect(*args, **kwargs)
|
||||||
|
self.queries = {}
|
||||||
|
|
||||||
|
def execute(self, *args, **kwargs):
|
||||||
|
self.cursor = self.connection.execute(*args, **kwargs)
|
||||||
|
|
||||||
|
def fetchone(self):
|
||||||
|
return self.cursor.fetchone()
|
||||||
|
|
||||||
|
def fetchall(self):
|
||||||
|
return self.cursor.fetchall()
|
||||||
|
|
||||||
|
def commit(self):
|
||||||
|
self.connection.commit()
|
||||||
|
|
||||||
|
def rollback(self):
|
||||||
|
self.connection.rollback()
|
||||||
|
|
||||||
|
def try_execute(self, sql):
|
||||||
|
try:
|
||||||
|
self.connection.execute(sql)
|
||||||
|
except Exception as exc:
|
||||||
|
#print(str(exc))
|
||||||
|
pass
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.connection.close()
|
Loading…
Reference in New Issue
Block a user