for row in iter_data():
connection.execute('INSERT INTO my_table VALUES (?)', row)
connection.executemany( 'INSERT INTO my_table VALUE (?)', iter_data() )
connection = sqlite3.connect(':memory:')
cursor = connection.cursor()
# Do something with cursor
import sqlite3
connection = sqlite3(':memory:')
# Create a table
connection.execute('CREATE TABLE events(ts, msg)')
# Insert values
connection.executemany(
'INSERT INTO events VALUES (?,?)',
[
(1, 'foo'),
(2, 'bar'),
(3, 'baz')
]
)
# Print inserted rows
for row in connnection.execute('SELECT * FROM events'):
print(row)
for row in connection.execute('SELECT * FROM events'):
print(row)
import sqlite3
connection = sqlite3.connect(':memory:')
with connection:
connection.execute(
'CREATE TABLE events(ts, msg, PRIMARY KEY(ts, msg))')
try:
with connection:
connection.executemany('INSERT INTO events VALUES (?, ?)', [
(1, 'foo'),
(2, 'bar'),
(3, 'baz'),
(1, 'foo'),
])
except (sqlite3.OperationalError, sqlite3.IntegrityError) as e:
print('Could not complete operation:', e)
# No row was inserted because transaction failed
for row in connection.execute('SELECT * FROM events'):
print(row)
connection.close()
connection.execute('PRAGMA synchronous = OFF')
# Do not do this!
my_timestamp = 1
c.execute("SELECT * FROM events WHERE ts = '%s'" % my_timestamp)
# Do this instead
my_timestamp = (1,)
c.execute('SELECT * FROM events WHERE ts = ?', my_timestamp)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有