【问题标题】:modifying the contents of the sqlilte database修改sqlilte数据库的内容
【发布时间】:2011-09-02 18:43:57
【问题描述】:

我有以下 sqlite3 数据库:

name : sampledb

table  : main



fields :  id, name description and gender

示例元素是:

"1" "John"  "Fat-Head"  "M"

我有大约 2000 行,并且想从每个字段值中删除引号,以便我的 db 元素看起来像:

1 John Fat-Head M

什么是这样做的有效方法?

谢谢。

【问题讨论】:

  • 您是否使用 python 来完成此任务(如果是,请发布您目前拥有的内容),还是您想要?这是您(错误地)用引号生成的数据库吗?如果是这样,您可能需要修改生成代码,使其不首先插入引号。
  • 您确定这些引号确实在数据库中吗?您如何确定是这种情况?
  • 我使用 sqliteman 来查看数据库表,不,我没有使用过 python,但在 python 中的答案将不胜感激。

标签: python sqlite


【解决方案1】:

我不确定这是否会达到 100%,或者非常有效,但试试这个:

import sqlite3

db = sqlite3.connect('sampledb')
c = db.cursor()

new_set = []

c.execute('select * from main')

temp_value = []
for row in c:
     for item in row:
          temp_value.append(item[1:-1])
     new_set.append(temp_value)
     temp_value = []

# place it back into the database

希望这是一个足够的指导方针!

【讨论】:

    猜你喜欢
    • 2011-05-18
    • 2021-01-26
    • 2021-08-17
    • 1970-01-01
    • 2021-01-26
    • 2017-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多