Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get field default value from the database #40

Open
embabi2005 opened this issue Feb 24, 2024 · 4 comments
Open

Cannot get field default value from the database #40

embabi2005 opened this issue Feb 24, 2024 · 4 comments

Comments

@embabi2005
Copy link

embabi2005 commented Feb 24, 2024

Cannot get columns default values from the database either through QSqlTableModel.record() nor QDatabase().record(), always None. Also setDefaultValue() does nothing. all field datatypes. Working with sqlite database.

I use Windows 11 x64, PyQt6 v6.6.2 and MySql Community server v8.0.32. I tried also with PyQt5 and other versions of PyQt6

@thecodemonkey86
Copy link
Owner

please show your code

@embabi2005
Copy link
Author

First, thanks for your attention.
my code as below
`import sys

from PySide6.QtWidgets import QApplication, QWidget, QTableView, QVBoxLayout
from PySide6.QtSql import QSqlDatabase, QSqlTableModel, QSqlRecord

app = QApplication(sys.argv)
db = QSqlDatabase.addDatabase("QMYSQL")
db.setHostName("localhost")
db.setDatabaseName("WeighBridge")
db.setUserName("root")
db.setPassword("password")
db.setPort(3306)
db.open()

window = QWidget()
layout = QVBoxLayout(window)

model = QSqlTableModel()
model.setEditStrategy(QSqlTableModel.EditStrategy.OnManualSubmit)
model.setTable("tickets")
model.select()

tblView = QTableView()
tblView.setModel(model)
layout.addWidget(tblView)

dbRecord = db.record("tickets")
for i in range(dbRecord.count()):
print(dbRecord.field(i).name(), dbRecord.field(i).defaultValue())

dbRecord.field(1).setDefaultValue("someValue")
print(dbRecord.field(1).defaultValue())

modelRecord = model.record()
for i in range(modelRecord.count()):
print(modelRecord.field(i).name(), modelRecord.field(i).defaultValue())

modelRecord.field(1).setDefaultValue("someValue")
print(modelRecord.field(1).defaultValue())

window.show()
sys.exit(app.exec())
`

All results None

@thecodemonkey86
Copy link
Owner

apparently this already has been reported 12 years ago in Qt's bug tracker, but didn't get a fix: https://bugreports.qt.io/browse/QTBUG-19487

@embabi2005
Copy link
Author

Thank you

Really appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants