Merge branch 'master' of git://git.assembla.com/fpdb-sql
This commit is contained in:
commit
121d05596d
|
@ -28,12 +28,12 @@ encoder_to_utf = codecs.lookup('utf-8')
|
||||||
encoder_to_sys = codecs.lookup(Configuration.LOCALE_ENCODING)
|
encoder_to_sys = codecs.lookup(Configuration.LOCALE_ENCODING)
|
||||||
|
|
||||||
# I'm saving a few cycles with this one
|
# I'm saving a few cycles with this one
|
||||||
not_needed = False
|
not_needed1, not_needed2, not_needed3 = False, False, False
|
||||||
if Configuration.LOCALE_ENCODING == 'UTF8':
|
if Configuration.LOCALE_ENCODING == 'UTF8':
|
||||||
not_needed = True
|
not_needed1, not_needed2, not_needed3 = True, True, True
|
||||||
|
|
||||||
def to_utf8(s):
|
def to_utf8(s):
|
||||||
if not_needed: return s
|
if not_needed1: return s
|
||||||
|
|
||||||
try:
|
try:
|
||||||
#(_out, _len) = encoder_to_utf.encode(s)
|
#(_out, _len) = encoder_to_utf.encode(s)
|
||||||
|
@ -46,7 +46,7 @@ def to_utf8(s):
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def to_db_utf8(s):
|
def to_db_utf8(s):
|
||||||
if not_needed: return s
|
if not_needed2: return s
|
||||||
|
|
||||||
try:
|
try:
|
||||||
(_out, _len) = encoder_to_utf.encode(unicode(s))
|
(_out, _len) = encoder_to_utf.encode(unicode(s))
|
||||||
|
@ -56,7 +56,7 @@ def to_db_utf8(s):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def to_gui(s):
|
def to_gui(s):
|
||||||
if not_needed: return s
|
if not_needed3: return s
|
||||||
|
|
||||||
try:
|
try:
|
||||||
(_out, _len) = encoder_to_sys.encode(s)
|
(_out, _len) = encoder_to_sys.encode(s)
|
||||||
|
|
|
@ -144,6 +144,11 @@ if LOCALE_ENCODING == "US-ASCII":
|
||||||
print "Default encoding set to US-ASCII, defaulting to CP1252 instead -- If you're not on a Mac, please report this problem."
|
print "Default encoding set to US-ASCII, defaulting to CP1252 instead -- If you're not on a Mac, please report this problem."
|
||||||
LOCALE_ENCODING = "cp1252"
|
LOCALE_ENCODING = "cp1252"
|
||||||
|
|
||||||
|
|
||||||
|
# needs LOCALE_ENCODING (above), imported for sqlite setup in Config class below
|
||||||
|
import Charset
|
||||||
|
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
def string_to_bool(string, default=True):
|
def string_to_bool(string, default=True):
|
||||||
"""converts a string representation of a boolean value to boolean True or False
|
"""converts a string representation of a boolean value to boolean True or False
|
||||||
|
@ -648,6 +653,10 @@ class Config:
|
||||||
db['db-backend'] = 3
|
db['db-backend'] = 3
|
||||||
elif self.supported_databases[name].db_server== DATABASE_TYPE_SQLITE:
|
elif self.supported_databases[name].db_server== DATABASE_TYPE_SQLITE:
|
||||||
db['db-backend'] = 4
|
db['db-backend'] = 4
|
||||||
|
# sqlcoder: this assignment fixes unicode problems for me with sqlite (windows, cp1252)
|
||||||
|
# feel free to remove or improve this if you understand the problems
|
||||||
|
# better than me (not hard!)
|
||||||
|
Charset.not_needed1, Charset.not_needed2, Charset.not_needed3 = True, True, True
|
||||||
else:
|
else:
|
||||||
raise ValueError('Unsupported database backend: %s' % self.supported_databases[name].db_server)
|
raise ValueError('Unsupported database backend: %s' % self.supported_databases[name].db_server)
|
||||||
return db
|
return db
|
||||||
|
|
|
@ -372,7 +372,6 @@ class Database:
|
||||||
print msg
|
print msg
|
||||||
raise FpdbError(msg)
|
raise FpdbError(msg)
|
||||||
elif backend == Database.SQLITE:
|
elif backend == Database.SQLITE:
|
||||||
log.info("Connecting to SQLite: %(database)s" % {'database':database})
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
if use_pool:
|
if use_pool:
|
||||||
sqlite3 = pool.manage(sqlite3, pool_size=1)
|
sqlite3 = pool.manage(sqlite3, pool_size=1)
|
||||||
|
@ -385,7 +384,8 @@ class Database:
|
||||||
log.info("Creating directory: '%s'" % (self.config.dir_databases))
|
log.info("Creating directory: '%s'" % (self.config.dir_databases))
|
||||||
os.mkdir(self.config.dir_databases)
|
os.mkdir(self.config.dir_databases)
|
||||||
database = os.path.join(self.config.dir_databases, database)
|
database = os.path.join(self.config.dir_databases, database)
|
||||||
log.info(" sqlite db: " + database)
|
log.info("Connecting to SQLite: %(database)s" % {'database':database})
|
||||||
|
print "Connecting to SQLite: %(database)s" % {'database':database}
|
||||||
self.connection = sqlite3.connect(database, detect_types=sqlite3.PARSE_DECLTYPES )
|
self.connection = 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")
|
||||||
|
@ -1769,9 +1769,6 @@ class Database:
|
||||||
|
|
||||||
def insertPlayer(self, name, site_id):
|
def insertPlayer(self, name, site_id):
|
||||||
result = None
|
result = None
|
||||||
if self.backend == self.SQLITE:
|
|
||||||
_name = name
|
|
||||||
else:
|
|
||||||
_name = Charset.to_db_utf8(name)
|
_name = Charset.to_db_utf8(name)
|
||||||
c = self.get_cursor()
|
c = self.get_cursor()
|
||||||
q = "SELECT name, id FROM Players WHERE siteid=%s and name=%s"
|
q = "SELECT name, id FROM Players WHERE siteid=%s and name=%s"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user