运行Pyinstaller后,Sqlite3更新查询中断了

时间:2017-09-15 23:12:53

标签: python sqlite pyinstaller

以下函数正常工作,直到我使用PyInstaller编译:然后我得到"错误绑定参数0.可能不支持的类型。"显示错误的行是" cur.execute"线。我检查了Pyinstaller文档,但无法找到与此问题相关的任何内容。我使用的是Python 2.7。

更新**我已将其缩小到Iron Python和控制台python2.7之间的某种不兼容性。我使用Python(x,y)包和Spyder2 IDE开发了程序。我在Iron Python控制台中运行程序。我在普通的python控制台中运行时也遇到了上述问题并得到了同样的错误。问题不是Pyinstaller,它只是IP和Python2.7之间的某种不兼容性。我还在研究,如果有人有答案,请告诉我。

def update_clients(self):
    #Get client id from list
    cid = None
    try:
        cid = self.client_list_id()
    except:            
        QtGui.QMessageBox.warning(self, 'Warning', 'You must first select a client before you update')


    if cid:
        #Get update items
        first = self.lineEdit_c_first.text()        
        last = self.lineEdit_c_last.text()
        add1 = self.lineEdit_c_address1.text()
        add2 = self.lineEdit_c_address2.text()
        city = self.lineEdit_c_city.text()
        state = self.lineEdit_c_state.text()
        zipp = self.lineEdit_c_zip.text()        
        phone = self.lineEdit_c_phone.text()
        cell = self.lineEdit_c_phone_cell.text()
        off = self.lineEdit_c_phone_office.text()
        email = self.lineEdit_c_email.text()  
        notes = self.textEdit_c_notes.toPlainText() 
        #Update database
        conn = sqlite3.connect('gibbs.db')
        cur = conn.cursor()
        sql = ("""
        UPDATE clients
        SET 
        firstname = ?, 
        lastname = ?,
        address1 = ?,
        address2 = ?,
        city = ?,
        state = ?,
        zip = ?,
        phone = ?,
        officephone = ?,
        cell = ?,
        email = ?,
        notes = ?        
        WHERE rowid = ?
        """)
        cur.execute(sql, (first, last, add1, add2, city, state, zipp, phone, off, cell, email, notes, cid,))
        conn.commit()
        conn.close()

        QtGui.QMessageBox.information(self, 'Success', 'Database successfully updated')

使用下面的代码创建表,其中显示了数据类型。

def create_clients():
    try:
        conn = create_connection()
        print conn
        c = conn.cursor()
        c.execute("""
        CREATE TABLE clients (
        id INTEGER PRIMARY KEY,
        timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
        firstname TEXT,
        lastname TEXT,
        address1 TEXT,
        address2 TEXT,
        city TEXT,
        state TEXT,
        zip TEXT,
        phone TEXT,
        officephone TEXT,
        cell TEXT,
        email TEXT,
        notes TEXT    
        )     
        """)
        conn.close()
    except:
        print "table already exists"       

1 个答案:

答案 0 :(得分:0)

在查询之前添加行print type(first)并运行程序后,两个控制台中的输出不同.Tron Python控制台输出:<type 'unicode'>,在Python2.7控制台中输出:{ {1}}。我从PYQT4 lineEdits获取文本时通过添加'str'函数解决了问题。例如:<class 'PyQt4.QtCore.QString'>