我在python(x,y)包中使用Spyder2 IDE。下面的函數在Iron Python中運行良好,但在控制檯中運行時出錯。我需要它在控制檯中運行,以便我可以使用Pyinstaller。我得到的錯誤是:"Error binding parameter 0. Probably unsupported type."
顯示錯誤的行是「cur.execute」行。我也使用Sqlite3並從PYQT4 lineEdit字段獲取文本數據。函數在Iron Python(Python(x,y)Spyder2 IDE)中運行,但不在Python 2.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')
此外,由於問題以某種方式涉及到的數據類型,這裏是我用於創建數據庫表的代碼:
import sqlite3
def create_connection():
try:
conn = sqlite3.connect('gibbs.db')
return conn
except:
pass
return None
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"
在嘗試插入之前,您從「print first」獲得了什麼? – roganjosh
Spyder保持運行之間的狀態;這是一些指定的值仍然存在,並且您可能已刪除的幫助程序功能仍然存在。你的函數是否仍然在新內核上運行(重啓spyder)? –
@roganjosh我打印的sql變量,工作正常。 –