do not require sqlalchemy, except for sqlite
This commit is contained in:
parent
d2380ba738
commit
fe72b6edad
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
#Copyright 2008 Steffen Jobbagy-Felso
|
#Copyright 2008 Steffen Jobbagy-Felso
|
||||||
#This program is free software: you can redistribute it and/or modify
|
#This program is free software: you can redistribute it and/or modify
|
||||||
|
@ -20,7 +21,14 @@ import re
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
from time import time, strftime
|
from time import time, strftime
|
||||||
|
|
||||||
|
use_pool = False
|
||||||
|
try:
|
||||||
import sqlalchemy.pool as pool
|
import sqlalchemy.pool as pool
|
||||||
|
use_pool = True
|
||||||
|
except:
|
||||||
|
logging.info("Not using sqlalchemy connection pool.")
|
||||||
|
|
||||||
|
|
||||||
import fpdb_simple
|
import fpdb_simple
|
||||||
import FpdbSQLQueries
|
import FpdbSQLQueries
|
||||||
|
@ -66,6 +74,7 @@ class fpdb_db:
|
||||||
self.database=database
|
self.database=database
|
||||||
if backend==fpdb_db.MYSQL_INNODB:
|
if backend==fpdb_db.MYSQL_INNODB:
|
||||||
import MySQLdb
|
import MySQLdb
|
||||||
|
if use_pool:
|
||||||
MySQLdb = pool.manage(MySQLdb, pool_size=5)
|
MySQLdb = pool.manage(MySQLdb, pool_size=5)
|
||||||
try:
|
try:
|
||||||
self.db = MySQLdb.connect(host = host, user = user, passwd = password, db = database, use_unicode=True)
|
self.db = MySQLdb.connect(host = host, user = user, passwd = password, db = database, use_unicode=True)
|
||||||
|
@ -74,6 +83,7 @@ class fpdb_db:
|
||||||
elif backend==fpdb_db.PGSQL:
|
elif backend==fpdb_db.PGSQL:
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import psycopg2.extensions
|
import psycopg2.extensions
|
||||||
|
if use_pool:
|
||||||
psycopg2 = pool.manage(psycopg2, pool_size=5)
|
psycopg2 = pool.manage(psycopg2, pool_size=5)
|
||||||
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
|
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
|
||||||
# If DB connection is made over TCP, then the variables
|
# If DB connection is made over TCP, then the variables
|
||||||
|
@ -106,7 +116,10 @@ class fpdb_db:
|
||||||
elif backend==fpdb_db.SQLITE:
|
elif backend==fpdb_db.SQLITE:
|
||||||
logging.info("Connecting to SQLite:%(database)s" % {'database':database})
|
logging.info("Connecting to SQLite:%(database)s" % {'database':database})
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
if use_pool:
|
||||||
sqlite3 = pool.manage(sqlite3, pool_size=1)
|
sqlite3 = pool.manage(sqlite3, pool_size=1)
|
||||||
|
else:
|
||||||
|
logging.warning("SQLite won't work well without 'sqlalchemy' installed.")
|
||||||
self.db = sqlite3.connect(database,detect_types=sqlite3.PARSE_DECLTYPES)
|
self.db = sqlite3.connect(database,detect_types=sqlite3.PARSE_DECLTYPES)
|
||||||
sqlite3.register_converter("bool", lambda x: bool(int(x)))
|
sqlite3.register_converter("bool", lambda x: bool(int(x)))
|
||||||
sqlite3.register_adapter(bool, lambda x: "1" if x else "0")
|
sqlite3.register_adapter(bool, lambda x: "1" if x else "0")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user