本文整理汇总了Python中sqlite3.PARSE_DECLTYPES属性的典型用法代码示例。如果您正苦于以下问题:Python sqlite3.PARSE_DECLTYPES属性的具体用法?Python sqlite3.PARSE_DECLTYPES怎么用?Python sqlite3.PARSE_DECLTYPES使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类sqlite3
的用法示例。
在下文中一共展示了sqlite3.PARSE_DECLTYPES属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __open
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PARSE_DECLTYPES [as 别名]
def __open(self):
if not self.createIfNotExists and not os.path.exists(self.fileName):
return False
self.connection = sqlite3.connect(self.fileName, detect_types=sqlite3.PARSE_DECLTYPES)
if(self.connection):
self.connection.row_factory = sqlite3.Row
self.connection.text_factory = str
self.cursor = self.connection.cursor()
self.cursor.execute("PRAGMA foreign_keys=1")
self.versionTable = RMVersionTable(self)
return True
return False
示例2: CheckConvertTimestampMicrosecondPadding
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PARSE_DECLTYPES [as 别名]
def CheckConvertTimestampMicrosecondPadding(self):
"""
http://bugs.python.org/issue14720
The microsecond parsing of convert_timestamp() should pad with zeros,
since the microsecond string "456" actually represents "456000".
"""
con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_DECLTYPES)
cur = con.cursor()
cur.execute("CREATE TABLE t (x TIMESTAMP)")
# Microseconds should be 456000
cur.execute("INSERT INTO t (x) VALUES ('2012-04-04 15:06:00.456')")
# Microseconds should be truncated to 123456
cur.execute("INSERT INTO t (x) VALUES ('2012-04-04 15:06:00.123456789')")
cur.execute("SELECT * FROM t")
values = [x[0] for x in cur.fetchall()]
self.assertEqual(values, [
datetime.datetime(2012, 4, 4, 15, 6, 0, 456000),
datetime.datetime(2012, 4, 4, 15, 6, 0, 123456),
])
示例3: init_db
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PARSE_DECLTYPES [as 别名]
def init_db(self):
"""Connect to the database, and create tables if necessary."""
if not self.enabled:
self.db = DummyDB()
return
# use detect_types so that timestamps return datetime objects
kwargs = dict(detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
kwargs.update(self.connection_options)
self.db = sqlite3.connect(self.hist_file, **kwargs)
self.db.execute("""CREATE TABLE IF NOT EXISTS sessions (session integer
primary key autoincrement, start timestamp,
end timestamp, num_cmds integer, remark text)""")
self.db.execute("""CREATE TABLE IF NOT EXISTS history
(session integer, line integer, source text, source_raw text,
PRIMARY KEY (session, line))""")
# Output history is optional, but ensure the table's there so it can be
# enabled later.
self.db.execute("""CREATE TABLE IF NOT EXISTS output_history
(session integer, line integer, output text,
PRIMARY KEY (session, line))""")
self.db.commit()
示例4: cleanup_database
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PARSE_DECLTYPES [as 别名]
def cleanup_database(days=1):
"""
remove any PDFs which have been here for more than
1 day, then compact the database
"""
log.info('Cleaning up database')
conn = sqlite3.connect(robotreviewer.get_data('uploaded_pdfs/uploaded_pdfs.sqlite'),
detect_types=sqlite3.PARSE_DECLTYPES)
d = datetime.now() - timedelta(days=days)
c = conn.cursor()
c.execute("DELETE FROM article WHERE timestamp < datetime(?) AND dont_delete=0", [d])
conn.commit()
conn.execute("VACUUM") # make the database smaller again
conn.commit()
conn.close()
示例5: __init__
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PARSE_DECLTYPES [as 别名]
def __init__(self, bot):
self.bot = bot
self.db = sqlite3.connect(SQLDB, detect_types=sqlite3.PARSE_DECLTYPES)
self.db.row_factory = sqlite3.Row
with self.db as con:
con.executescript(INIT_SQL)
if check_fts4():
self.has_fts = True
con.executescript(FTS_SQL)
con.create_function('bm25', -1, bm25)
else:
self.has_fts = False
self.bot.loop.create_task(self._populate_userinfo())
self.bot.loop.create_task(self._upgrade_210())
self._upgrade_211()
self._upgrade_230()
try:
self.analytics = CogAnalytics(self)
except Exception as e:
self.bot.logger.exception(e)
self.analytics = None
示例6: __init__
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PARSE_DECLTYPES [as 别名]
def __init__(self, filename, debug = False, logLevel = 'INFO'):
if filename == ':memory:':
self.dbname = ""
else:
if not filename.lower().endswith(DB_EXTENSION):
self.dbname = "{}.{}".format(filename, DB_EXTENSION)
else:
self.dbname = filename
self._engine = create_engine("sqlite:///{}".format(self.dbname), echo = debug,
connect_args={'detect_types': sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES},
native_datetime = True)
self._session = orm.Session(self._engine, autoflush = False, autocommit = False)
self._metadata = Base.metadata
#loadInitialData(Node)
Base.metadata.create_all(self.engine)
meta = MetaData(schema_version = CURRENT_SCHEMA_VERSION)
self.session.add(meta)
self.session.flush()
self.session.commit()
self._closed = False
示例7: __init__
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PARSE_DECLTYPES [as 别名]
def __init__(self, db_path, writeable=False, translate_ncbi_namespace=False, check_same_thread=True):
self._db_path = db_path
self._db = None
self._writeable = writeable
self.translate_ncbi_namespace = translate_ncbi_namespace
if self._writeable:
self._upgrade_db()
self._db = sqlite3.connect(self._db_path,
check_same_thread=check_same_thread,
detect_types=sqlite3.PARSE_DECLTYPES)
self._db.row_factory = sqlite3.Row
schema_version = self.schema_version()
# if we're not at the expected schema version for this code, bail
if schema_version != expected_schema_version: # pragma: no cover
raise RuntimeError("Upgrade required: Database schema"
"version is {} and code expects {}".format(schema_version, expected_schema_version))
# ############################################################################
# Special methods
示例8: migrate_db_v1_to_v2
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PARSE_DECLTYPES [as 别名]
def migrate_db_v1_to_v2(db_path):
old_db_path = db_path + datetime.now().strftime("%s") + ".bkp_db_v1"
os.rename(db_path, old_db_path)
old_db = sql.connect(old_db_path,
detect_types=sql.PARSE_DECLTYPES |
sql.PARSE_COLNAMES)
new_db = DB(db_path)
old_db.cursor().execute("PRAGMA foreign_keys = ON")
epoch_list = []
for epoch, schema in old_db.execute('SELECT epoch, schema '
'FROM snapshots_schemas'):
new_db.add_snapshot(epoch, schema)
epoch_list.append(epoch)
for epoch in epoch_list:
file_list = list(old_db.execute("SELECT keyspace, tablename, file "
"FROM snapshots_files WHERE epoch = ?",
(epoch,)))
new_db.add_snapshot_files(epoch, file_list)
示例9: record_daily
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PARSE_DECLTYPES [as 别名]
def record_daily(channelid, channelname, title, start, stop):
channelid = channelid.decode("utf8")
channelname = channelname.decode("utf8")
title = title.decode("utf8")
title = xbmcgui.Dialog().input(_("% is Wildcard"), title).decode("utf8")
start = timestamp2datetime(float(start))
stop = timestamp2datetime(float(stop))
conn = sqlite3.connect(xbmc.translatePath('%sxmltv.db' % plugin.addon.getAddonInfo('profile')), detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
cursor = conn.cursor()
#TODO problem with PRIMARY KEYS, UNIQUE and TIMESTAMP
rule = cursor.execute('SELECT * FROM rules WHERE channelid=? AND channelname=? AND title=? AND start=? AND stop =? AND type=?', (channelid, channelname, title, start, stop, "DAILY")).fetchone()
if not rule:
conn.execute("INSERT OR REPLACE INTO rules(channelid, channelname, title, start, stop, type) VALUES(?, ?, ?, ?, ?, ?)",
[channelid, channelname, title, start, stop, "DAILY"])
conn.commit()
conn.close()
service()
示例10: record_weekly
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PARSE_DECLTYPES [as 别名]
def record_weekly(channelid, channelname, title, start, stop):
channelid = channelid.decode("utf8")
channelname = channelname.decode("utf8")
title = title.decode("utf8")
title = xbmcgui.Dialog().input(_("% is Wildcard"), title).decode("utf8")
start = timestamp2datetime(float(start))
stop = timestamp2datetime(float(stop))
conn = sqlite3.connect(xbmc.translatePath('%sxmltv.db' % plugin.addon.getAddonInfo('profile')), detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
cursor = conn.cursor()
#TODO problem with PRIMARY KEYS, UNIQUE and TIMESTAMP
rule = cursor.execute('SELECT * FROM rules WHERE channelid=? AND channelname=? AND title=? AND start=? AND stop =? AND type=?', (channelid, channelname, title, start, stop, "WEEKLY")).fetchone()
if not rule:
conn.execute("INSERT OR REPLACE INTO rules(channelid, channelname, title, start, stop, type) VALUES(?, ?, ?, ?, ?, ?)",
[channelid, channelname, title, start, stop, "WEEKLY"])
conn.commit()
conn.close()
service()
示例11: record_always_search
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PARSE_DECLTYPES [as 别名]
def record_always_search(channelid, channelname):
channelid = channelid.decode("utf8")
channelname = channelname.decode("utf8")
title = xbmcgui.Dialog().input("IPTV Recorder: " + _("Title Search (% is wildcard)?")).decode("utf8")
if not title:
return
conn = sqlite3.connect(xbmc.translatePath('%sxmltv.db' % plugin.addon.getAddonInfo('profile')), detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
cursor = conn.cursor()
rule = cursor.execute('SELECT * FROM rules WHERE channelid=? AND channelname=? AND title=? AND type=?', (channelid, channelname, title, "SEARCH")).fetchone()
if not rule:
conn.execute("INSERT OR REPLACE INTO rules(channelid, channelname, title, type) VALUES(?, ?, ?, ?)",
[channelid, channelname, title, "SEARCH"])
conn.commit()
conn.close()
service()
示例12: record_always_search_plot
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PARSE_DECLTYPES [as 别名]
def record_always_search_plot(channelid, channelname):
channelid = channelid.decode("utf8")
channelname = channelname.decode("utf8")
description = xbmcgui.Dialog().input("IPTV Recorder: " + _("Plot Search (% is wildcard)?")).decode("utf8")
if not description:
return
conn = sqlite3.connect(xbmc.translatePath('%sxmltv.db' % plugin.addon.getAddonInfo('profile')), detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
cursor = conn.cursor()
rule = cursor.execute('SELECT * FROM rules WHERE channelid=? AND channelname=? AND description=? AND type=?', (channelid, channelname, description, "PLOT")).fetchone()
if not rule:
conn.execute("INSERT OR REPLACE INTO rules(channelid, channelname, description, type) VALUES(?, ?, ?, ?)",
[channelid, channelname, description, "PLOT"])
conn.commit()
conn.close()
service()
示例13: watch_daily
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PARSE_DECLTYPES [as 别名]
def watch_daily(channelid, channelname, title, start, stop):
channelid = channelid.decode("utf8")
channelname = channelname.decode("utf8")
title = title.decode("utf8")
title = xbmcgui.Dialog().input(_("% is Wildcard"), title).decode("utf8")
start = timestamp2datetime(float(start))
stop = timestamp2datetime(float(stop))
conn = sqlite3.connect(xbmc.translatePath('%sxmltv.db' % plugin.addon.getAddonInfo('profile')), detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
cursor = conn.cursor()
#TODO problem with PRIMARY KEYS, UNIQUE and TIMESTAMP
rule = cursor.execute('SELECT * FROM rules WHERE channelid=? AND channelname=? AND title=? AND start=? AND stop =? AND type=?', (channelid, channelname, title, start, stop, "WATCH DAILY")).fetchone()
if not rule:
conn.execute("INSERT OR REPLACE INTO rules(channelid, channelname, title, start, stop, type) VALUES(?, ?, ?, ?, ?, ?)",
[channelid, channelname, title, start, stop, "WATCH DAILY"])
conn.commit()
conn.close()
service()
示例14: watch_weekly
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PARSE_DECLTYPES [as 别名]
def watch_weekly(channelid, channelname, title, start, stop):
channelid = channelid.decode("utf8")
channelname = channelname.decode("utf8")
title = title.decode("utf8")
title = xbmcgui.Dialog().input(_("% is Wildcard"), title).decode("utf8")
start = timestamp2datetime(float(start))
stop = timestamp2datetime(float(stop))
conn = sqlite3.connect(xbmc.translatePath('%sxmltv.db' % plugin.addon.getAddonInfo('profile')), detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
cursor = conn.cursor()
#TODO problem with PRIMARY KEYS, UNIQUE and TIMESTAMP
rule = cursor.execute('SELECT * FROM rules WHERE channelid=? AND channelname=? AND title=? AND start=? AND stop =? AND type=?', (channelid, channelname, title, start, stop, "WATCH WEEKLY")).fetchone()
if not rule:
conn.execute("INSERT OR REPLACE INTO rules(channelid, channelname, title, start, stop, type) VALUES(?, ?, ?, ?, ?, ?)",
[channelid, channelname, title, start, stop, "WATCH WEEKLY"])
conn.commit()
conn.close()
service()
示例15: watch_always
# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import PARSE_DECLTYPES [as 别名]
def watch_always(channelid, channelname, title):
channelid = channelid.decode("utf8")
channelname = channelname.decode("utf8")
title = title.decode("utf8")
title = xbmcgui.Dialog().input(_("% is Wildcard"), title).decode("utf8")
conn = sqlite3.connect(xbmc.translatePath('%sxmltv.db' % plugin.addon.getAddonInfo('profile')), detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
cursor = conn.cursor()
rule = cursor.execute('SELECT * FROM rules WHERE channelid=? AND channelname=? AND title=? AND type=?', (channelid, channelname, title, "WATCH ALWAYS")).fetchone()
if not rule:
conn.execute("INSERT OR REPLACE INTO rules(channelid, channelname, title, type) VALUES(?, ?, ?, ?)",
[channelid, channelname, title, "WATCH ALWAYS"])
conn.commit()
conn.close()
service()