1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
class Database_prix:
is_instantiated = False
def __init__(self):
if not Database_prix.is_instantiated:
# print ("Database has been instantiated:")
self.db = QSqlDatabase.addDatabase("QSQLITE")
self.db.setDatabaseName("C:/Users/yatamant/Documents/Mes fichiers reçus/Dev_Env/database_prix.db")
self.db.removeDatabase("QSQLITE")
self.db.open()
Database_prix.is_instantiated =True
else:
print("Has already been created")
def get_prix_selectionne(self):
global design_prix
query = QSqlQuery()
query_string = "SELECT PU.ref_pu, PU.desig_pu, PU.prix FROM PU WHERE replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace( lower(desig_pu), 'á','a'), 'ã','a'), 'â','a'), 'é','e'), 'ê','e'), 'í','i'),'ó','o') ,'õ','o') ,'ô','o'),'ú','u'), 'ç','c') LIKE :des "
query.prepare(query_string)
query.bindValue(":des","%" + design_prix + "%")
query.exec(query_string)
record = query.record()
column_number = record.count()
header_list = []
for i in range(column_number):
header_list.append(record.field(i).name())
result_list = []
while query.next():
sublist = []
for i in range(column_number):
sublist.append(query.value(i))
result_list.append(sublist)
return [header_list, result_list] |
Partager