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


Python sqlite3.Row方法代碼示例

本文整理匯總了Python中sqlite3.Row方法的典型用法代碼示例。如果您正苦於以下問題:Python sqlite3.Row方法的具體用法?Python sqlite3.Row怎麽用?Python sqlite3.Row使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sqlite3的用法示例。


在下文中一共展示了sqlite3.Row方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: CheckSqliteRowIndex

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Row [as 別名]
def CheckSqliteRowIndex(self):
        self.con.row_factory = sqlite.Row
        row = self.con.execute("select 1 as a, 2 as b").fetchone()
        self.assertTrue(isinstance(row,
                                   sqlite.Row),
                        "row is not instance of sqlite.Row")

        col1, col2 = row["a"], row["b"]
        self.assertTrue(col1 == 1, "by name: wrong result for column 'a'")
        self.assertTrue(col2 == 2, "by name: wrong result for column 'a'")

        col1, col2 = row["A"], row["B"]
        self.assertTrue(col1 == 1, "by name: wrong result for column 'A'")
        self.assertTrue(col2 == 2, "by name: wrong result for column 'B'")

        col1, col2 = row[0], row[1]
        self.assertTrue(col1 == 1, "by index: wrong result for column 0")
        self.assertTrue(col2 == 2, "by index: wrong result for column 1") 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:20,代碼來源:factory.py

示例2: __init__

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Row [as 別名]
def __init__(self,ip,name):
        with lock:
            # Create a database in RAM
            self.db = sqlite3.connect('/home/vagrant/iSDX/xrs/ribs/'+ip+'.db',check_same_thread=False)
            self.db.row_factory = sqlite3.Row
            self.name = name

            qs = ', '.join(['?']*len(labels))
            self.insertStmt = 'insert into %s values (%s)' % (self.name, qs)

            stmt = (
                    'create table if not exists '+self.name+
                    ' ('+ ', '.join([l+' '+t for l,t in zip(labels, types)])+')'
                    )

            cursor = self.db.cursor()
            cursor.execute(stmt)
            self.db.commit() 
開發者ID:sdn-ixp,項目名稱:iSDX,代碼行數:20,代碼來源:rib.py

示例3: check_schema_version

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Row [as 別名]
def check_schema_version(self):
        query = "SELECT  Version FROM  Globals WHERE Id IS 1"
        self.cur.execute(query)
        version = float(self.cur.fetchone()[0])
        if version > self.VERSION:
            raise ValueError("Database version is newer than gphotos-sync")
        elif version < self.VERSION:
            log.warning(
                "Database schema out of date. Flushing index ...\n"
                "A backup of the previous DB has been created"
            )
            self.con.commit()
            self.con.close()
            self.backup_sql_file()
            self.con = lite.connect(str(self.db_file))
            self.con.row_factory = lite.Row
            self.cur = self.con.cursor()
            self.cur2 = self.con.cursor()
            self.clean_db() 
開發者ID:gilesknap,項目名稱:gphotos-sync,代碼行數:21,代碼來源:LocalData.py

示例4: __open

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Row [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 
開發者ID:sprinkler,項目名稱:rainmachine-developer-resources,代碼行數:18,代碼來源:rmDatabase.py

示例5: __init__

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Row [as 別名]
def __init__(self, tableName, attribIndex, keyAttribute='unvocalized'):
        """
        initialisation of dictionary from a data dictionary, create indexes to speed up the access.

        """
        # load data from the brut dictionary into a new dictionary with numeric ids
        self.dictionary={};
        self.attribIndex=attribIndex;
        self.keyAttribute= keyAttribute;
        self.attribNumIndex={};
        # create the attribute num index
        # attribIndex:         attribNumIndex
        # vocalized: 0        0: vocalized
        #unvocalized: 1        1: unvocalized
        #
        for k in self.attribIndex.keys():
            v=self.attribIndex[k];
            self.attribNumIndex[v]=k;
        self.tableName=tableName;
        try:
            self.dbConnect = sqlite.connect(FILE_DB)
            self.dbConnect.row_factory = sqlite.Row                 
            self.cursor = self.dbConnect.cursor()
        except:
            print("Fatal Error Can't find the database file", FILE_DB) 
開發者ID:linuxscout,項目名稱:mishkal,代碼行數:27,代碼來源:collocationdictionary.py

示例6: __init__

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Row [as 別名]
def __init__(self):
        # Create a database in RAM
        self._db = sqlite3.connect(':memory:')
        self._db.row_factory = sqlite3.Row

        # Create the basic contact table.
        self._db.cursor().execute('''
            CREATE TABLE contacts(
                id INTEGER PRIMARY KEY,
                name TEXT,
                phone TEXT,
                address TEXT,
                email TEXT,
                notes TEXT)
        ''')
        self._db.commit()

        # Current contact when editing.
        self.current_id = None 
開發者ID:peterbrittain,項目名稱:asciimatics,代碼行數:21,代碼來源:contact_list.py

示例7: __connect

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Row [as 別名]
def __connect(self):
        """
        Private function for connecting and setting return type for select ops.
        Raises a DbConnectionError when fails to connect.
        """
        if self.conn:
            logging.info("AuthorizationDataManager: Reconnecting to %s on request", self.db_path)
            self.__close()

        try:
            self.conn = sqlite3.connect(self.db_path)
        except sqlite3.Error as e:
            logging.error("Failed to connect to DB (%s): %s", self.db_path, e)
            raise DbConnectionError(self.db_path)

        # Use return rows as Row instances instead of tuples
        self.conn.row_factory = sqlite3.Row 
開發者ID:vmware-archive,項目名稱:vsphere-storage-for-docker,代碼行數:19,代碼來源:auth_data.py

示例8: CheckSqliteRowHashCmp

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Row [as 別名]
def CheckSqliteRowHashCmp(self):
        """Checks if the row object compares and hashes correctly"""
        self.con.row_factory = sqlite.Row
        row_1 = self.con.execute("select 1 as a, 2 as b").fetchone()
        row_2 = self.con.execute("select 1 as a, 2 as b").fetchone()
        row_3 = self.con.execute("select 1 as a, 3 as b").fetchone()

        self.assertEqual(row_1, row_1)
        self.assertEqual(row_1, row_2)
        self.assertTrue(row_2 != row_3)

        self.assertFalse(row_1 != row_1)
        self.assertFalse(row_1 != row_2)
        self.assertFalse(row_2 == row_3)

        self.assertEqual(row_1, row_2)
        self.assertEqual(hash(row_1), hash(row_2))
        self.assertNotEqual(row_1, row_3)
        self.assertNotEqual(hash(row_1), hash(row_3)) 
開發者ID:vmware-archive,項目名稱:vsphere-storage-for-docker,代碼行數:21,代碼來源:factory.py

示例9: CheckSqliteRowHashCmp

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Row [as 別名]
def CheckSqliteRowHashCmp(self):
        """Checks if the row object compares and hashes correctly"""
        self.con.row_factory = sqlite.Row
        row_1 = self.con.execute("select 1 as a, 2 as b").fetchone()
        row_2 = self.con.execute("select 1 as a, 2 as b").fetchone()
        row_3 = self.con.execute("select 1 as a, 3 as b").fetchone()
        row_4 = self.con.execute("select 1 as b, 2 as a").fetchone()
        row_5 = self.con.execute("select 2 as b, 1 as a").fetchone()

        self.assertTrue(row_1 == row_1)
        self.assertTrue(row_1 == row_2)
        self.assertFalse(row_1 == row_3)
        self.assertFalse(row_1 == row_4)
        self.assertFalse(row_1 == row_5)
        self.assertFalse(row_1 == object())

        self.assertFalse(row_1 != row_1)
        self.assertFalse(row_1 != row_2)
        self.assertTrue(row_1 != row_3)
        self.assertTrue(row_1 != row_4)
        self.assertTrue(row_1 != row_5)
        self.assertTrue(row_1 != object())

        self.assertEqual(hash(row_1), hash(row_2)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:factory.py

示例10: CheckSqliteRowHashCmp

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Row [as 別名]
def CheckSqliteRowHashCmp(self):
        """Checks if the row object compares and hashes correctly"""
        self.con.row_factory = sqlite.Row
        row_1 = self.con.execute("select 1 as a, 2 as b").fetchone()
        row_2 = self.con.execute("select 1 as a, 2 as b").fetchone()
        row_3 = self.con.execute("select 1 as a, 3 as b").fetchone()

        self.assertTrue(row_1 == row_1)
        self.assertTrue(row_1 == row_2)
        self.assertTrue(row_2 != row_3)

        self.assertFalse(row_1 != row_1)
        self.assertFalse(row_1 != row_2)
        self.assertFalse(row_2 == row_3)

        self.assertEqual(row_1, row_2)
        self.assertEqual(hash(row_1), hash(row_2))
        self.assertNotEqual(row_1, row_3)
        self.assertNotEqual(hash(row_1), hash(row_3)) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:21,代碼來源:factory.py

示例11: db_connect

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Row [as 別名]
def db_connect(self):
        """Returns a connection for the current thread.

        """
        thread = threading.current_thread()
        if not self.db_is_connected(thread):
            db = minqlbot.get_config()["Core"]["DatabasePath"]
            conn = sqlite3.connect(db)
            conn.row_factory = sqlite3.Row
            cursor = conn.cursor()
            cursor.execute("PRAGMA foreign_keys = ON") # Enforce foreign keys.
            cursor.execute("PRAGMA busy_timeout = 5000") # Wait 5s if it gets locked.
            with self.db_lock:
                self.db_connections[thread] = conn
            return conn
        else:
            with self.db_lock:
                return self.db_connections[thread] 
開發者ID:MinoMino,項目名稱:minqlbot,代碼行數:20,代碼來源:plugin.py

示例12: _GetRowValue

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Row [as 別名]
def _GetRowValue(self, query_hash, row, value_name):
    """Retrieves a value from the row.

    Args:
      query_hash (int): hash of the query, that uniquely identifies the query
          that produced the row.
      row (sqlite3.Row): row.
      value_name (str): name of the value.

    Returns:
      object: value.
    """
    keys_name_to_index_map = self._keys_per_query.get(query_hash, None)
    if not keys_name_to_index_map:
      keys_name_to_index_map = {
          name: index for index, name in enumerate(row.keys())}
      self._keys_per_query[query_hash] = keys_name_to_index_map

    value_index = keys_name_to_index_map.get(value_name)

    # Note that pysqlite does not accept a Unicode string in row['string'] and
    # will raise "IndexError: Index must be int or string".
    return row[value_index] 
開發者ID:log2timeline,項目名稱:plaso,代碼行數:25,代碼來源:interface.py

示例13: _HashRow

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Row [as 別名]
def _HashRow(cls, row):
    """Hashes the given row.

    Args:
      row (sqlite3.Row): row.

    Returns:
      int: hash value of the given row.
    """
    values = []
    for value in row:
      try:
        value = '{0!s}'.format(value)
      except UnicodeDecodeError:
        # In Python 2, blobs are "read-write buffer" and will cause a
        # UnicodeDecodeError exception if we try format it as a string.
        # Since Python 3 does not support the buffer type we cannot check
        # the type of value.
        value = repr(value)

      values.append(value)

    return hash(' '.join(values)) 
開發者ID:log2timeline,項目名稱:plaso,代碼行數:25,代碼來源:interface.py

示例14: __init__

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Row [as 別名]
def __init__(self, name):

        # Open the database
        
        self.name = name
        if ".db" not in name:
            self.name += ".db"

        self._main = sqlite3.connect(self.name)
        self._main.row_factory = sqlite3.Row

        # Load table names and column names into memory
        self._tables = {}
        self._db = self._main.cursor()

        
        for table in self.get_tables():
            self._tables[table] = self.get_columns(table) 
開發者ID:Qirky,項目名稱:PyKinectTk,代碼行數:20,代碼來源:SQL.py

示例15: query

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Row [as 別名]
def query(self, base, depth=None, order="size_desc", children_only=False):
        sqlite = sqlite3.connect(STATS_DB_PATH)
        sqlite.row_factory = sqlite3.Row
        order = self.ORDER_DEFINITION.get(order, self.ORDER_DEFINITION['size_desc'])
        query = f"SELECT *, (size_standard + size_ia + size_glacier) as size " \
                f"FROM stats " \
                f"WHERE {self.format_path_condition(base, children_only)} " \
                f"AND {self.format_depth_condition(base, depth)} " \
                f"order by {order}"
        with Timer(self.logger, f"S3 stats query {query}"):
            try:
                cursor = sqlite.cursor()
                cursor.execute(query)
                return cursor.fetchall() 
            finally:
                cursor.close()
                sqlite.close() 
開發者ID:Wikia,項目名稱:discreETLy,代碼行數:19,代碼來源:statsdb.py


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