Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的python程序是否有任何特定的方法可以从终止行继续?_Python_Sqlite_Exception - Fatal编程技术网

我的python程序是否有任何特定的方法可以从终止行继续?

我的python程序是否有任何特定的方法可以从终止行继续?,python,sqlite,exception,Python,Sqlite,Exception,我有一个工作程序,可以进行一些转换,但我很担心,如果数据库太大,会发生什么 我会告诉你,如果下面的程序在中间爆炸,我会如何让程序恢复,让它从指定的代码行工作。 防御地说,在执行一段代码后,进程将被终止 程序是否能够从出错的位置继续返回,或者从被终止的位置继续返回 import sqlite3 as sqlite import ConfigParser config = ConfigParser.RawConfigParser() config.read('removespecial.ini')

我有一个工作程序,可以进行一些转换,但我很担心,如果数据库太大,会发生什么

<>我会告诉你,如果下面的程序在中间爆炸,我会如何让程序恢复,让它从指定的代码行工作。 防御地说,在执行一段代码后,进程将被终止

程序是否能够从出错的位置继续返回,或者从被终止的位置继续返回

import sqlite3 as sqlite
import ConfigParser
config = ConfigParser.RawConfigParser()
config.read('removespecial.ini')

con = sqlite.connect('listofcomp.sqlite')
cur = con.cursor()

def transremovechars():
    char_cfg = open('specialchars.txt', 'r')        #Reads all the special chars to be           removed from specialchars.txt#
    special_chars = char_cfg.readline()
    char_cfg.close()
    cur.execute('select * from originallist')       
for row in cur:                                 #Applies transformation to remove chars for each row in a loop#
    company = row[0]
    for bad_char in special_chars:
            company =  company.replace(bad_char, '')
            cur.execute('Create table transform1 (Names Varchar, Transformtype Varchar')
            cur.execute('Insert into transform1 (Names)', company)


def transtolower():
    cur.execute('select * from transform1')         #Transformation to convert all the namesto lower cases#
    for row in cur:
        company = row[0]
        company = company.lower()
        cur.execute('Create table transform2 (Names Varchar, Transformtype Varchar')        #Creates another table named transform2#
        cur.execute('Insert into transform2 (Names)', company)                              #Copies all the lower cased names to transform2#



if __name__=="__main__":

transremovechars()
transtolower()  

如果在中间的下一个程序炸弹,我将如何从程序的指定代码行中恢复程序? 你不能

您的代码非常神秘,因为除了第一次插入之外,create表在每次插入之前都会出错

但是,如果要从一个旧表向一个新表执行长系列插入, 您担心它可能无法正确完成,您有两种选择来维护所需的状态信息

  • 唯一的钥匙

  • 批次

  • 询问

  • 唯一键

    如果每一行都有一个唯一的键,那么一些插入操作将得到一个错误,因为该行是重复的

    如果程序“爆炸”,你只需重新启动。你会得到很多重复的(你期望的)。这不是低效的

    批次

    我们使用的另一种技术是查询旧表中的所有行,并包括每1000行递增的“批次”编号<代码>批次号=行数//1000

    您创建了一个编号为
    -1
    的“批次号”文件

    程序启动后,它会读取批次号。这是最后一批完成的

    读取源数据,直到到达a批次号>最后一个完成的批次号

    然后从批处理中执行所有插入操作

    当批号更改时,执行提交,并将批号写入文件。这样,您就可以在任何批上重新启动

    在“爆炸”后重新启动时,您可能会从部分批次(您预期的)中获得一些副本。这不是低效的

    查询

    您可以在每次插入之前进行查询,以查看该行是否存在。这是低效的


    如果没有唯一键,则必须执行复杂查询,以查看该行是否由上一次运行的程序创建。

    请同时修复缩进。这是不对的。请包括您实际收到的错误消息。除了错误的措辞、错误的缩进之外,您正在为每个结果行中要更改的每个字符创建一个数据库表-这可能不对:
    cur.execute('Create table transform1(name Varchar,Transformtype Varchar')) @ S.Lott:也许他是一个十二岁OL.D.S.洛特,你猜对了我的年龄。我会让你明白,如果上面的程序在中间爆炸,我会如何从指定的代码行恢复程序。@初学者:请不要使用!标点符号!请停止!这不是好英语!除了漫画书!或卡通。!!!