Get content of cell from QTableView
-
@Karoluss96 said in Get content of cell from QTableView:
This what you sent to me works correct!
Do you mean the code block I wrote a couple of posts ago above? You should be able to get that working so long as you do not yet have any
None
values in your data, have you tested that, does it work fully so long as noNone
values? Please answer!change automatic the default python NoneType to sql's NULL
The problem is that there is no "sql's NULL" in Python, so we don't yet know what to do about
None
s to get what we need across to SQL.If and when you confirm all is working from my code with no
None
s involved, I will have a think aboutNone
/NULL
. But not until you confirm my code works withoutNone
s! -
@JonB said in Get content of cell from QTableView:
Do you mean the code block I wrote a couple of posts ago above? You should be able to get that working so long as you do not yet have any None values in your data, have you tested that, does it work fully so long as no None values? Please answer!
If I go through the all values (by tabs or putting blank space or one digit sign) code work without Exception!
The problem is that there is no "sql's NULL" in Python, so we don't yet know what to do about Nones to get what we need across to SQL.
If and when you confirm all is working from my code with no Nones involved, I will have a think about None/NULL. But not until you confirm my code works without Nones!That the main reason for all this discussion- how to auto-change None to NULL?!
-
@Karoluss96 said in Get content of cell from QTableView:
That the main reason for all this discussion- how to auto-change None to NULL?!
I can give you some suggestions to try. But first I know you are using Python but not which Python binding you are using for Qt. It could be any of: PySide2, PyQt5, PySide6, PyQt6. Which one?
-
I suppose PyQt5
as at beginng appears a line:
from PyQt5.QtCore import QSettings
-
@Karoluss96
In place of theraise Exception(...)
line try the following:-
val = None
. If this works it would be simplest! It means that binding aNone
, does result in aNULL
, so you can remove the special case completely. -
val = QVariant()
. Try this next. You may find you need afrom PyQt5.QtCore import QVariant
statement at the head of the file near the other PyQt5 imports.
If #2 does not work I would be interested to know if you get an error message anywhere (e.g. perhaps on the
query.exec_()
) and what the message says. -
-
Well... that all makes (and maybe also you) me tired. My chef will help me with this...
If finally works I'll informe you!
-
@Karoluss96
Did you not just try those two? Having spent this much time I am keen to know now...! -
Well... I tried, but I won't to answer it's correct or not as the code with previous versions become messy.
I saw that you're solved a little problem here: https://forum.qt.io/topic/90363/inexplicable-qsqlquerymodel-handling-of-null-value/14
-
@Karoluss96
That is so long ago I barely remember! Except that I didn't feel I got much from the PyQt author/mailing list :(In the last post there a guy says:
though Oracle treats empty strings as NULL
You seem to be using PLSQL. So another thing to try, if no joy from my previous two suggestions, might be
val = ""
for theNone
case if that really is true. -
Yes, but now I try by my chef's suggestions with a little returing for a starting point.
I'll answer if finally goes... or returning to your version if doesn't go -
After a long fight my chef find the working answer:
for col in range(model.columnCount()): rowData = [model.index(row, col).data() for col in range(model.columnCount()) ] letersBind = [':a',':bb',':bc',':bd',':be',':bf',':bg',':bh',':bi',':bj',':bk',':bl',':bm',':bn',':bo',':bp',':cba',':cbb',':cbc',':cbd', ':cbe',':cbf',':cbg',':cbh',':cbi',':cbj',':cbk',':cbl',':cbn',':cbo',':cbp',':cca',':ccb',':ccc'] if rowData[col] is None: query.addBindValue('') print(col,' 1') else: query.bindValue(letersBind[col],rowData[col]) query.exec_() print (query.lastError().text()) while query.next(): self.model4.insertRow(row)
I' don't from what come the letters, which exchange the ? singns in () for Values
-
@Karoluss96 said in Get content of cell from QTableView:
After a long fight my chef find the working answer:
if rowData[col] is None: query.addBindValue('')
@JonB said in Get content of cell from QTableView:
You seem to be using PLSQL. So another thing to try, if no joy from my previous two suggestions, might be
val = ""
for theNone
case if that really is true. -
Thanks for all helping!