繁体   English   中英

无法插入 Sqlite3 数据库

[英]Can't INSERT into Sqlite3 database

我非常绝望,因为我尽我所能让它工作,但没有成功......我创建了一个池,它正在处理一些文本行,然后将它们插入到数据库中。 问题是它不会向表中插入任何内容。

我知道这可能是因为多个工作人员试图修改数据库,但我已经尝试了很多方法来避免这种情况。

例如这个(这是将 url 插入索引表的方法):

def insert_into_index(self, url):
    self.lock.acquire()
    self.cur.execute('INSERT INTO index VALUES(?)', (url,))
    self.conn.commit()
    self.lock.release()

或者这个(该方法的每个新用途都有它自己的光标):

def insert_into_index(self, url):
    cur = self.conn.cursor()
    cur.execute('INSERT INTO index VALUES(?)', (url,))
    self.conn.commit()

我创建池的代码段:

 """ CREATE A POOL """

    pool = Pool(50)
    for category in categories[1:2]:
        task = pool.apply_async(index, args=(category.strip('\n'),))
        task.get()

    pool.close()
    pool.join()

    """ POOL END """

Index() 是一个创建类leaf(text)实例的方法,它对leaf(text)做一些事情,获取strings列表并尝试insert它们插入到数据库中。

class leaf():
    def __init__(self, url):
        self.url = url
        self.results = self.get_all_hrefs(url)
        self.dbm = database_file.manager()

        for res in self.results:
              self.dbm.insert_into_index(res)

但是我在表索引中没有任何内容。 我已经尝试了我所知道的一切,但都没有成功。 你能给我一个建议吗?

编辑:这是一个错误,当我将task.get()附加到循环中时引发。

line 86, in execute
    task.get()
  File "C:\Python27\lib\multiprocessing\pool.py", line 567, in get
    raise self._value
sqlite3.OperationalError: near "index": syntax error

但我认为它并没有说明什么,因为语法与另一个顺序调用并有效的方法完全相同。

index是一个关键字 您必须引用它,或使用不同的名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM