尝试在Sqlite3

时间:2016-11-08 19:25:58

标签: python sqlite select where pyqt5

Sqlite3 pyqt5和python3

inpsearch = ('%'+self.lineEdit.text()+'%',)
conn = sqlite3.connect('formuladatabase')
c = conn.cursor()
c.execute('DROP TABLE IF EXISTS search')
c.execute('CREATE TABLE search(rowid, Name TEXT, Surname TEXT, datestamp TEXT, Stylist TEXT, formula TEXT, Price REAL)')

这是原作下面的工作

#c.execute('INSERT INTO search SELECT * FROM clientsformula WHERE Name LIKE ?', inpsearch)

一栏工作得很好,但我希望通过2栏搜索

c.execute('INSERT INTO search SELECT * FROM clientsformula WHERE Name=? OR Surname=?', inpsearch, inpsearch)

此返回:类型错误函数最多需要2个参数(3)

conn.commit()
c.close()
conn.close()

希望解决这个问题好几天......还有一个侧面问题是否有人知道如何使用Pyqt5为QlineEdit制作自动完成(.setCompleter)

谢谢

1 个答案:

答案 0 :(得分:0)

$.fn.dataTable.ext.search.push( function( settings, data, dataIndex ) { var mini = document.getElementById('datepicker').value; var maxi = document.getElementById('datepicker2').value; var mini2 = document.getElementById('datepicker3').value; var maxi2 = document.getElementById('datepicker4').value; if((mini !== '') && (maxi !== '')){ var taena = data[10]; // use data for the date column var ifMin = mini.substring(0,2) + mini.substring(3,5) + mini.substring(6,10); var ifMax = maxi.substring(0,2) + maxi.substring(3,5) + maxi.substring(6,10); var ifTaena = taena.substring(0,2) + taena.substring(3,5) + taena.substring(6,10); if ( ( ifMin === '' && ifMax === '' ) || ( ifMin === '' && ifTaena <= ifMax ) || ( ifMin <= ifTaena && ifMax === '' ) || ( ifMin <= ifTaena && ifTaena <= ifMax ) ){ return true; } return false; } if((mini2 !== '') && (maxi2 !== '')){ var taena2 = data[9]; // use data for the date column console.log(taena2); var ifMin2 = mini2.substring(0,2) + mini2.substring(3,5) + mini2.substring(6,10); var ifMax2 = maxi2.substring(0,2) + maxi2.substring(3,5) + maxi2.substring(6,10); var ifTaena2 = taena2.substring(0,2) + taena2.substring(3,5) + taena2.substring(6,10); if ( ( ifMin2 === '' && ifMax2 === '' ) || ( ifMin2 === '' && ifTaena2 <= ifMax2 ) || ( ifMin2 <= ifTaena2 && ifMax2 === '' ) || ( ifMin2 <= ifTaena2 && ifTaena2 <= ifMax2 ) ){ return true; } return false; } return false; } ); 需要2个参数,sql语句和参数元组(在你的情况下是2个绑定值)。您提供sql语句和2个元组和1个参数。

这应该有效:

cursor.execute()

或者:

bv = '%'+self.lineEdit.text()+'%'
inpsearch = (bv, bv, )
c.execute('INSERT INTO search SELECT * FROM clientsformula WHERE Name=? OR Surname=?', inpsearch)