mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-21 05:43:16 -07:00
parent
d3bbcb6b63
commit
455915907b
1 changed files with 28 additions and 2 deletions
|
@ -11,11 +11,37 @@ import re
|
|||
import sqlite3
|
||||
import time
|
||||
|
||||
from six import text_type
|
||||
from six import text_type, PY2
|
||||
|
||||
import core
|
||||
from core import logger
|
||||
|
||||
if PY2:
|
||||
class Row(sqlite3.Row, object):
|
||||
"""
|
||||
Row factory that uses Byte Strings for keys.
|
||||
|
||||
The sqlite3.Row in Python 2 does not support unicode keys.
|
||||
This overrides __getitem__ to attempt to encode the key to bytes first.
|
||||
"""
|
||||
|
||||
def __getitem__(self, item):
|
||||
"""
|
||||
Get an item from the row by index or key.
|
||||
|
||||
:param item: Index or Key of item to return.
|
||||
:return: An item from the sqlite3.Row.
|
||||
"""
|
||||
try:
|
||||
# sqlite3.Row column names should be Bytes in Python 2
|
||||
item = item.encode()
|
||||
except AttributeError:
|
||||
pass # assume item is a numeric index
|
||||
|
||||
return super(Row, self).__getitem__(item)
|
||||
else:
|
||||
from sqlite3 import Row
|
||||
|
||||
|
||||
def db_filename(filename='nzbtomedia.db', suffix=None):
|
||||
"""
|
||||
|
@ -37,7 +63,7 @@ class DBConnection(object):
|
|||
|
||||
self.filename = filename
|
||||
self.connection = sqlite3.connect(db_filename(filename), 20)
|
||||
self.connection.row_factory = sqlite3.Row
|
||||
self.connection.row_factory = Row
|
||||
|
||||
def check_db_version(self):
|
||||
result = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue