python sqlite操作_Python sqlite3操作E

这是我的密码。它将以相同的格式读取一堆带有SQL命令的文件(例如,以-开头的注释,以及一些空行,因此在我的循环中有if条件)#!/usr/bin/env python

# -*- coding: utf-8 -*-

import csv,sqlite3,os

conn = sqlite3.connect('db_all.db')

c = conn.cursor()

files = os.listdir('C:\\Users\\ghb\\Desktop\\database_schema')

for file in files:

string = ''

with open(file, 'rb') as read:

for line in read.readlines():

if line[0]!='-' and len(line)!=0: string = string + line.rstrip() #error also occurs if I skip .rstrip

print string #for debugging purposes

c.executescript(string)

string=''

conn.close()

错误:

^{pr2}$

为了避免混乱,这里是string变量的输出(没有INSERT INTO数据,这是机密的):SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

CREATE TABLE IF NOT EXISTS `career` (

`carKey` int(11) NOT NULL AUTO_INCREMENT,

`persID` bigint(10) unsigned zerofill NOT NULL,

`persKey` int(6) unsigned NOT NULL,

`wcKey` int(2) unsigned NOT NULL,

`wtKey` int(2) unsigned DEFAULT NULL,

`pwtKey` int(2) unsigned DEFAULT NULL,

`dptId` bigint(10) unsigned NOT NULL,

`dptNr` int(4) unsigned NOT NULL,

`dptalias` varchar(10) COLLATE utf8_icelandic_ci NOT NULL,

`class` enum('A','B') COLLATE utf8_icelandic_ci NOT NULL,

`getfilm` enum('yes','no') COLLATE utf8_icelandic_ci NOT NULL DEFAULT 'yes',

`finished` enum('true','false') COLLATE utf8_icelandic_ci NOT NULL DEFAULT 'false',

`startDate` date NOT NULL,

`endDate` date DEFAULT NULL,

`regDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

`user` tinyint(4) NOT NULL,

`status` set('LÉST','BRFL','BRFD','BRNN') COLLATE utf8_icelandic_ci DEFAULT NULL,

`descr` text COLLATE utf8_icelandic_ci,

PRIMARY KEY (`carKey`),

KEY `pwtKey` (`pwtKey`),

KEY `wtKey` (`wtKey`),

KEY `dptId` (`dptId`),

KEY `user` (`user`),

KEY `persID` (`persID`),

KEY `persKey` (`persKey`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_icelandic_ci AUTO_INCREMENT=2686 ;

输入样本:INSERT INTO `career` (`carKey`, `persID`, `persKey`, `wcKey`, `wtKey`, `pwtKey`, `dptId`, `dptNr`, `dptalias`, `class`, `getfilm`, `finished`, `startDate`, `endDate`, `regDate`, `user`,

(5, 34536, 346, 22, 44, 34, 3454356, 33, 'asdasd', 'ASDASD', 'ASDSD', 'true', '1991-02-04', '2010-05-02', '2009-05-02 00:01:02', 1, NULL, 'HH:

'),

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值