简体   繁体   English

Mysql 文件未链接到 python

[英]Mysql file is not linking to python

import sqlite3


def ConnectData():
    con = sqlite3.connect("libbooks.db")
    cur = con.cursor()
    cur.execute('''CREATE TABLE IF NOT EXISTS libbooks (id INTEGER PRIMARY KEY, MTy text, Ref text, Title text,
                   Fna text, Sna text, Adr1 text, Adr2 text, Pcd text, MNo text, BkID text, BkT text, Atr text, 
                   DBo text, Ddu text, sPr text, Lrf text, Dod text, DonL text''')
    con.commit()
    con.close()


def addDataRec(MTy, Ref, Title,Fna, Sna, Adr1, Adr2, Pcd, MNo, BkID, BkT, Atr, DBo , Ddu, sPr, Lrf, Dod, DonL):
    con = sqlite3.connect("libbooks.db")

    cur.execute("INSERT INTO libbooks VALUES (NULL,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
                (MTy, Ref, Title,Fna, Sna, Adr1, Adr2, Pcd, MNo, BkID, BkT, Atr, DBo, Ddu, sPr, Lrf, Dod, DonL))
    con.commit()
    con.close()


ConnectData()

The error is :错误是:

Traceback (most recent call last): File "D:\\Python Projects\\Test1\\GUI\\LMS.py", line 3, in import LibBksDatabase File "D:\\Python Projects\\Test1\\GUI\\LibBksDatabase.py", line 23, in ConnectData() File "D:\\Python Projects\\Test1\\GUI\\LibBksDatabase.py", line 7, in ConnectData cur.execute('''CREATE TABLE IF NOT EXISTS libbooks (id INTEGER PRIMARY KEY, MTy text, Ref text, Title text, sqlite3.OperationalError: incomplete input回溯(最近一次调用):文件“D:\\Python Projects\\Test1\\GUI\\LMS.py”,第 3 行,导入 LibBksDatabase 文件“D:\\Python Projects\\Test1\\GUI\\LibBksDatabase.py”,第 23 行, 在 ConnectData() File "D:\\Python Projects\\Test1\\GUI\\LibBksDatabase.py", line 7, 在 ConnectData cur.execute('''CREATE TABLE IF NOT EXISTS libbooks (id INTEGER PRIMARY KEY, MTy text, Ref文本、标题文本、sqlite3.OperationalError:输入不完整

You are missing a closing brace.你缺少一个右括号。

DonL text --> DonL text) DonL text --> DonL text)

the code below works:下面的代码有效:

import sqlite3

con = sqlite3.connect("libbooks.db")
cur = con.cursor()
cur.execute('''CREATE TABLE IF NOT EXISTS libbooks (id INTEGER PRIMARY KEY, MTy text, Ref text, Title text,
               Fna text, Sna text, Adr1 text, Adr2 text, Pcd text, MNo text, BkID text, BkT text, Atr text, 
               DBo text, Ddu text, sPr text, Lrf text, Dod text, DonL text)''')
con.commit()
con.close()

In python, you need to tell the interpreter that the statement continues on the next line.在python中,您需要告诉解释器该语句在下一行继续。

Add a添加一个

\

at the end of a line to continue the statement on the next line.在一行的末尾继续下一行的语句。 In your case:在你的情况下:

cur.execute('''CREATE TABLE IF NOT EXISTS libbooks (id INTEGER PRIMARY KEY, MTy text, Ref text, Title text, \
                   Fna text, Sna text, Adr1 text, Adr2 text, Pcd text, MNo text, BkID text, BkT text, Atr text, \
                   DBo text, Ddu text, sPr text, Lrf text, Dod text, DonL text''')

Let us know how it works out.让我们知道它是如何工作的。

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

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