本文整理汇总了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")
示例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()
示例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()
示例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
示例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)
示例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
示例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
示例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))
示例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))
示例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))
示例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]
示例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]
示例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))
示例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)
示例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()