Changes various values in self.model (in TableView) to gain dat to sql query
-
wrote on 25 Aug 2023, 07:18 last edited by
Good morning,
The main problem for me now is (quote from Chef's list):
"It's a pity that when editing values in many records, you have to enter each value by pressing "tick". When completing records, this is direct speed. Isn't it possible to participate to save only after all changes.[?]”
tick is:
self.dlg.pushButton_18.clicked.connect(self.prwn_zam) #button that trigger function.
What I had earlier was that: only one record had been selected so that the data in self.model4 would run to the SQL query (it has more than 30 records, so only fragments will be shown), but the user, by the "tick" could be used only once - after all changes to self.model4.
Control chief preseted:
self.model4.dataChanged.connect(self.test)
in the plug-in function
then a table was created in the test functionchangedRowsTableView_3 = []
and then used for:
i = self.dlg.tableView_3.selectionModel().currentIndex().row()#a table where data was stored if not and in changedRowsTableView_3: changedRowsTableView_3.append(i) print('Line changed',i)# showed the line number
I've now moved it all to prwn_zam, but I'm not sure if it's right.
After many tries I now have this:
def prwn_zam(self): #confirm changes to order records print('Approve button clicked!') #ticked pushButton_18 con= self.model4.dataChanged.connect(self.prwn_test) if con: print("Connection has been established.") else: print("Failed to create connection.") def prwn_test(self): changedRowsTableView_3 = [] record_count = self.model4.rowCount() i = self.dlg.tableView_3.selectionModel().currentIndex().row() idi = self.dlg.tableView_3.selectionModel().currentIndex().siblingAtRow(i).siblingAtColumn(33).data() # fetches the data from the row which is then queryed country = self.dlg.tableView_3.selectionModel().currentIndex().siblingAtRow(i).siblingAtColumn(0).data() ter = self.dlg.tableView_3.selectionModel().currentIndex().siblingAtRow(i).siblingAtColumn(1).data() act = self.dlg.tableView_3.selectionModel().currentIndex().siblingAtRow(i).siblingAtColumn(2).data() #... if not and in changedRowsTableView_3 : changedRowsTableView_3 .append(i) print('Changed row ',i, ' with ID: ', idi, ter, act) if idi is not None: idi = int(float(idi)) danRek.append(idi) danRek1.append(ter) danRek2.append(act) #danRek[1-32] are tables created earlier. I also have doubts whether they should be created in this function or in the startup plugin?
Then there's my part:
for j, k, l, m, n, o .... in zip(danRek, danRek1, danRek2, danRek3, danRek4, danRek5, ...): if isinstance(k, str) and k != 'NULL': #teryt k ='\'' + k + '\'' if isinstance(n, str) and n != 'NULL': #Orderer n ='\'' + n + '\'' sql = f"UPDATE ORDER.MANAGEMENT SET teryt={k}, ORDERING_CODE={n}, ..., DATA_MOD_REC=TO_DATE(SYSDATE,\'DD.MM.YYYY HH24:MI:SS\') WHERE ID={ j}" print (sql) sql = query.prepare(sql) if query.exec(): print('added!') else: print(query.lastError().text())
which is already working - the query works fine, but the data that goes to it aren't correct, and it is to be executed in a loop as many times as many records have been changed. Not only once by selected record (I have already removed the old code, but I have it in archived - previous version of the code).
I'm sure that I have a problem with the location n of this code- in which function (before the last fragment).
Thank you in advance for every kind of help!
-
Good morning,
The main problem for me now is (quote from Chef's list):
"It's a pity that when editing values in many records, you have to enter each value by pressing "tick". When completing records, this is direct speed. Isn't it possible to participate to save only after all changes.[?]”
tick is:
self.dlg.pushButton_18.clicked.connect(self.prwn_zam) #button that trigger function.
What I had earlier was that: only one record had been selected so that the data in self.model4 would run to the SQL query (it has more than 30 records, so only fragments will be shown), but the user, by the "tick" could be used only once - after all changes to self.model4.
Control chief preseted:
self.model4.dataChanged.connect(self.test)
in the plug-in function
then a table was created in the test functionchangedRowsTableView_3 = []
and then used for:
i = self.dlg.tableView_3.selectionModel().currentIndex().row()#a table where data was stored if not and in changedRowsTableView_3: changedRowsTableView_3.append(i) print('Line changed',i)# showed the line number
I've now moved it all to prwn_zam, but I'm not sure if it's right.
After many tries I now have this:
def prwn_zam(self): #confirm changes to order records print('Approve button clicked!') #ticked pushButton_18 con= self.model4.dataChanged.connect(self.prwn_test) if con: print("Connection has been established.") else: print("Failed to create connection.") def prwn_test(self): changedRowsTableView_3 = [] record_count = self.model4.rowCount() i = self.dlg.tableView_3.selectionModel().currentIndex().row() idi = self.dlg.tableView_3.selectionModel().currentIndex().siblingAtRow(i).siblingAtColumn(33).data() # fetches the data from the row which is then queryed country = self.dlg.tableView_3.selectionModel().currentIndex().siblingAtRow(i).siblingAtColumn(0).data() ter = self.dlg.tableView_3.selectionModel().currentIndex().siblingAtRow(i).siblingAtColumn(1).data() act = self.dlg.tableView_3.selectionModel().currentIndex().siblingAtRow(i).siblingAtColumn(2).data() #... if not and in changedRowsTableView_3 : changedRowsTableView_3 .append(i) print('Changed row ',i, ' with ID: ', idi, ter, act) if idi is not None: idi = int(float(idi)) danRek.append(idi) danRek1.append(ter) danRek2.append(act) #danRek[1-32] are tables created earlier. I also have doubts whether they should be created in this function or in the startup plugin?
Then there's my part:
for j, k, l, m, n, o .... in zip(danRek, danRek1, danRek2, danRek3, danRek4, danRek5, ...): if isinstance(k, str) and k != 'NULL': #teryt k ='\'' + k + '\'' if isinstance(n, str) and n != 'NULL': #Orderer n ='\'' + n + '\'' sql = f"UPDATE ORDER.MANAGEMENT SET teryt={k}, ORDERING_CODE={n}, ..., DATA_MOD_REC=TO_DATE(SYSDATE,\'DD.MM.YYYY HH24:MI:SS\') WHERE ID={ j}" print (sql) sql = query.prepare(sql) if query.exec(): print('added!') else: print(query.lastError().text())
which is already working - the query works fine, but the data that goes to it aren't correct, and it is to be executed in a loop as many times as many records have been changed. Not only once by selected record (I have already removed the old code, but I have it in archived - previous version of the code).
I'm sure that I have a problem with the location n of this code- in which function (before the last fragment).
Thank you in advance for every kind of help!
wrote on 25 Aug 2023, 08:05 last edited by@Karoluss96 said in Changes various values in self.model (in TableView) to gain dat to sql query:
Isn't it possible to participate to save only after all changes.[?]”
Consider changing over to use QSqlTableModel Class. A
QTableView
can use that as its model. It allows you to "buffer" changes in the client program until you are ready to QSqlTableModel::submitAll() to submit all the changes in one go. -
@Karoluss96 said in Changes various values in self.model (in TableView) to gain dat to sql query:
Isn't it possible to participate to save only after all changes.[?]”
Consider changing over to use QSqlTableModel Class. A
QTableView
can use that as its model. It allows you to "buffer" changes in the client program until you are ready to QSqlTableModel::submitAll() to submit all the changes in one go.wrote on 25 Aug 2023, 08:56 last edited by@JonB Look intersting I'll respond if I still next problem appears.
1/3