當前位置: 首頁>>代碼示例>>Python>>正文


Python sqlite3.PARSE_COLNAMES屬性代碼示例

本文整理匯總了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) 
開發者ID:helpshift,項目名稱:scyllabackup,代碼行數:23,代碼來源:migrate.py

示例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 
開發者ID:laurivosandi,項目名稱:certidude,代碼行數:30,代碼來源:relational.py

示例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() 
開發者ID:vmware-archive,項目名稱:vsphere-storage-for-docker,代碼行數:11,代碼來源:regression.py

示例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" 
開發者ID:vmware-archive,項目名稱:vsphere-storage-for-docker,代碼行數:11,代碼來源:types.py

示例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" 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:11,代碼來源:types.py

示例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
                );""") 
開發者ID:irmen,項目名稱:synthesizer,代碼行數:37,代碼來源:musicfiledb.py

示例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 
開發者ID:orisi,項目名稱:orisi,代碼行數:5,代碼來源:db_classes.py


注:本文中的sqlite3.PARSE_COLNAMES屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。