本文整理匯總了Python中sqlite3.PARSE_COLNAMES屬性的典型用法代碼示例。如果您正苦於以下問題:Python sqlite3.PARSE_COLNAMES屬性的具體用法?Python sqlite3.PARSE_COLNAMES怎麽用?Python sqlite3.PARSE_COLNAMES使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類sqlite3
的用法示例。
在下文中一共展示了sqlite3.PARSE_COLNAMES屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: migrate_db_v1_to_v2
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import PARSE_COLNAMES [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)
示例2: sql_connect
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import PARSE_COLNAMES [as 別名]
def sql_connect(self):
if self.uri.scheme == "mysql":
import mysql.connector
conn = mysql.connector.connect(
user=self.uri.username,
password=self.uri.password,
host=self.uri.hostname,
database=self.uri.path[1:])
elif self.uri.scheme == "sqlite":
if self.uri.netloc:
raise ValueError("Malformed database URI %s" % self.uri)
import sqlite3
conn = sqlite3.connect(self.uri.path,
detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES)
else:
raise NotImplementedError("Unsupported database scheme %s, currently only mysql://user:pass@host/database or sqlite:///path/to/database.sqlite is supported" % o.scheme)
if self.SQL_CREATE_TABLES and self.SQL_CREATE_TABLES not in SCRIPTS:
cur = conn.cursor()
buf, path = self.sql_load(self.SQL_CREATE_TABLES)
click.echo("Executing: %s" % path)
if self.uri.scheme == "sqlite":
cur.executescript(buf)
else:
cur.execute(buf, multi=True)
conn.commit()
cur.close()
return conn
示例3: CheckPragmaSchemaVersion
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import PARSE_COLNAMES [as 別名]
def CheckPragmaSchemaVersion(self):
# This still crashed pysqlite <= 2.2.1
con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES)
try:
cur = self.con.cursor()
cur.execute("pragma schema_version")
finally:
cur.close()
con.close()
示例4: setUp
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import PARSE_COLNAMES [as 別名]
def setUp(self):
self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES)
self.cur = self.con.cursor()
self.cur.execute("create table test(x foo)")
sqlite.converters["FOO"] = lambda x: "[%s]" % x
sqlite.converters["BAR"] = lambda x: "<%s>" % x
sqlite.converters["EXC"] = lambda x: 5 // 0
sqlite.converters["B1B1"] = lambda x: "MARKER"
示例5: setUp
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import PARSE_COLNAMES [as 別名]
def setUp(self):
self.con = sqlite.connect(":memory:", detect_types=sqlite.PARSE_COLNAMES)
self.cur = self.con.cursor()
self.cur.execute("create table test(x foo)")
sqlite.converters["FOO"] = lambda x: "[%s]" % x.decode("ascii")
sqlite.converters["BAR"] = lambda x: "<%s>" % x.decode("ascii")
sqlite.converters["EXC"] = lambda x: 5/0
sqlite.converters["B1B1"] = lambda x: "MARKER"
示例6: __init__
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import PARSE_COLNAMES [as 別名]
def __init__(self, dbfile=None, scan_changes=True, silent=False):
if not dbfile:
dblocation = appdirs.user_data_dir("PythonJukebox", "Razorvine")
os.makedirs(dblocation, mode=0o700, exist_ok=True)
dbfile = os.path.join(dblocation, "tracks.sqlite")
dbfile = os.path.abspath(dbfile)
self.dbfile = dbfile
self.dbconn = sqlite3.connect(dbfile, detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES)
self.dbconn.row_factory = sqlite3.Row # make sure we can get results by column name
self.dbconn.execute("PRAGMA foreign_keys=ON")
try:
self.dbconn.execute("SELECT COUNT(*) FROM tracks").fetchone()
if not silent:
print("Connected to database.")
print("Database file:", dbfile)
if scan_changes:
self.scan_changes()
except sqlite3.OperationalError:
# the table does not yet exist, create the schema
if not silent:
print("Creating new database.")
print("Database file:", dbfile)
self.dbconn.execute("""CREATE TABLE tracks
(
id integer PRIMARY KEY,
title nvarchar(260),
artist nvarchar(260),
album nvarchar(260),
year int,
genre nvarchar(100),
duration real NOT NULL,
modified timestamp NOT NULL,
location nvarchar(500) NOT NULL,
hash char(40) NOT NULL UNIQUE
);""")
示例7: connect
# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import PARSE_COLNAMES [as 別名]
def connect(self):
self.conn = sqlite3.connect(self._filename, detect_types=sqlite3.PARSE_COLNAMES)
self.conn.row_factory = sqlite3.Row