当前位置:首页 > 数据库 > SQlite

为什么Windows会给出sqlite3.OperationalError而Linux没有?

问题

我有一个使用storm 0.14的程序,它在Windows上给了我这个错误:

sqlite3.OperationError: database table is locked

问题是,在Linux下它可以正常工作.

我给人的印象是,它只有在进行了一定数量的更改后才会发生,就像在某些代码中那样,它会复制很多对象.

打开调试模式可以在Windows上看到:

83 EXECUTE: 'UPDATE regularorder_product SET discount=? WHERE regularorder_product.order_id = ? AND regularorder_product.product_id = ?', (Decimal("25.00"), 788, 274)
84 DONE
85 EXECUTE: 'UPDATE repeated_orders SET nextDate=? WHERE repeated_orders.id = ?', (datetime.date(2009, 3, 31), 189)
86 ERROR: database table is locked

在Linux上:

83 EXECUTE: 'UPDATE regularorder_product SET discount=? WHERE regularorder_product.order_id = ? AND regularorder_product.product_id = ?', (Decimal("25.00"), 789, 274)
84 DONE
85 EXECUTE: 'UPDATE repeated_orders SET nextDate=? WHERE repeated_orders.id = ?', (datetime.date(2009, 3, 31), 189)
86 DONE

系统信息

视窗

> Windows XP SP 3
> Python 2.5.4
> NTFS分区

的Linux

> Ubuntu 8.10
> Python 2.5.2
> ext3分区

一些代码

def createRegularOrderCopy(self):
    newOrder = RegularOrder()
    newOrder.date = self.nextDate
    # the exception is thrown on the next line,
    # while calling self.products.__iter__
    # this happens when this function is invoked the second time
    for product in self.products:
        newOrder.customer = self.customer
        newOrder.products.add(product)
        return newOrder

orders = getRepeatedOrders(date)
week = timedelta(days=7)

for order in orders:
    newOrder = order.createRegularOrderCopy()
    store.add(newOrder)
    order.nextDate = date + week

问题

关于sqlite3 / python,在Windows和Linux之间有什么区别吗?该错误的原因可能是什么,我该如何解决?

另一个观察

在发生错误的位置添加COMMIT时,将引发此错误:sqlite3.OperationalError:无法提交事务-SQL语句正在进行

答案答案

我没有使用多个线程/进程,因此并发应该不是问题,而且我只有一个Store对象.

解决方法:

“数据库表已锁定”错误通常是SQLite中的常规/默认错误,因此缩小问题范围并不明显.

您可以执行任何SQL查询吗?我将从此处开始,并使一些基本的SELECT语句正常工作.可能只是权限问题.


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!