这是我的密码
import sqlite3
conn = sqlite3.connect("path to chrome history")
c = conn.cursor()
c.executemany("UPDATE urls SET url = REPLACE(url,.foo.,.foo-bar.) WHERE url LIKE %foo%;")
conn.close()
它引发以下错误:
c.executemany("UPDATE urls SET url = REPLACE(url,.foo.,.foo-bar.) WHERE url LIK
我正在尝试使用executemany函数在带有一些WHERE约束的一行中获取表中的所有行
import sqlite3
con = sqlite3.connect('test.db')
cur = con.cursor()
cur.execute('CREATE TABLE IF NOT EXISTS Genre (id INTEGER PRIMARY KEY, genre TEXT NOT NULL)')
values = [
(None, 'action'),
(None, 'adventure&
我有一个大约170万行的电子表格,总计1GB,需要对它执行查询。
对Python最满意的是,我的第一种方法是以一种方便我试图进行的查询的方式将一堆关键的字典拼凑在一起。例如,如果我需要用特定的区号和年龄访问每个人,我会制作一个areacode_age二维字典。最后,我需要的内存增加到了10 up,即使我有足够的RAM,进程也是缓慢的。
我导入了sqlite3并将数据导入内存中的数据库中。结果显示,执行像SELECT (a, b, c) FROM foo WHERE date1<=d AND date2>e AND name=f这样的查询需要0.05秒。为我的170万行做这件事需要2
我正在使用Python3.6。我在MSSQL中有一个大表,在该表中,我希望将数据提取出来,在python中处理它,然后保存数据。目前,我遇到了sqlite和pyodbc返回值的问题:
import sqlite3
import pyodbc
tempConn = sqlite3.connect('example.db')
c = tempConn.cursor()
c.execute(
''' CREATE TABLE IF NOT EXISTS addresses
(
amt NUMERIC,
ci
当涉及到将多个行插入到表中时,我试图减少写入Sqlite数据库的次数。
到目前为止,我已经找到了两种方法,使用union select语句或在sqlite3中使用executemany命令。
executemany是否通过一次写入完成工作?
如需参考,请参阅我使用的下列语句(union select):
INSERT INTO table1
SELECT "hello" AS field1, 15 AS field2, 1262340000 AS timestamp
UNION SELECT "byebye", 10, 1262340000
UNION SE
我试图在Python中使用sqlite3,方法是使用for循环迭代列表中的所有项,并使用该数据填充列。希望下面的代码能说明这个问题:
import sqlite3 as lite
test_run = ['tommy', 'olga', 'peter', 'lulu']
con = lite.connect("test.db")
cur = con.cursor()
cur.execute('DROP TABLE IF EXISTS test1;')
cur.execute('CREA
请仔细看我解析器的代码。它从访问它们的网页中获取一些统计信息,并将指定的记录放在SQLite3数据库中。
直到第87行( SQL语句),进程消耗了所有的CPU资源,实际上被阻塞了,一切都很顺利。
文件"./parser.py",第86行,in (j < i):
代码开头的数据库文件是用正确的结构创建的,所以问题在循环中。主循环for season in season_list:的内部块工作得很好。下面是我的脚本的全部代码:
#!/usr/bin/env python
from bs4 import BeautifulStoneSoup
from urllib2 i
我最近开始学习Python和SQL,并且有一个问题。
使用Python与SQLite3一起编写了以下代码:
# Use sqlite3 in the file
import sqlite3
# Create people.db if it doesn't exist or connect to it if it does exist
with sqlite3.connect("people.db") as connection:
c = connection.cursor()
# Create new table called people
我在一个sqlite3数据库中有两个以上的表。我正在尝试将数据插入到一个表中,并更新另一个表中的一些列。这有可能吗?
我尝试过以多种形式使用executemany()和executescript()。我收到了一堆错误消息,主要是因为execute不接受我的参数。
with sqlite3.connect('database.db') as conn:
cur = conn.cursor()
cur.executescript("""INSERT INTO prev_users (
我对SQL和Sqlite3模块非常陌生,我想随机编辑DB中所有记录的时间戳。
import sqlite3
from time import time
import random
conn = sqlite3.connect('database.db')
c = sqlite3.Cursor(conn)
ts_new = round(time())
ts_old = 1537828957
difference = ts_new - ts_old
for i in range(1,309):
#getting a new, random timestamp
我有一个简单的代码,它应该提供给我一个价格和描述,从我的愿望清单位于亚马逊。不幸的是,在执行过程中,我遇到了一个与insert语句相关的错误。
from bs4 import BeautifulSoup
import requests
import sqlite3
import movie
#Getting my wishlist html
page = requests.get("some_url").text
soup = BeautifulSoup(page,'lxml')
soupd = soup.div
#Looking for item pri
我有一个大表(table1,列是name、key、info),其中有大约1,000,000行,我需要对这些行执行以下操作:
选择info是Null或""的所有行
在Python3中执行一个转换函数,将name转换为info (让我们称之为conversion(name))
用新的info值更新行
执行此更新的最快方法是什么?是否有任何SQLite3设置可以被激活以提高性能?
我目前的研究表明,SQLite3库的内容如下:
cursor = db.cursor()
cursor.execute('SELECT longkey, name FROM ta
我必须遍历数据库中的所有行,并必须在某个位置更新它们。我写了这段代码:
import sqlite3
con=sqlite3.connect("Models.db")
c=con.cursor()
c1=con.cursor()
c.execute("CREATE TABLE ABC(id INTEGER PRIMARY KEY, COLVAL text)")
///inserted a few rows........
for row in c.execute("SELECT * FROM ABC"):
if $(any condition
我使用Python3在MySQL中插入了数以百万计的行,但我发现内存使用量一直在增长,最终达到了64‘m。我试着诊断这个问题,下面是问题的复制品:假设我有100个CSV文件。每个文件包含50000行,我想将它们插入到数据库中。下面是一个示例代码:
import mysql.connector
insert_sql = ("INSERT INTO table (Value) VALUES (%s)")
for i in range(100):
cnx = mysql.connector.connect(user='root', password=