PDA

View Full Version : Fetch default values from MySQL?



arimaniac
1st February 2011, 19:17
Hello guys...

One question of faith... :P

I wrote an application that uses QSqlTableModel to access MySQL, add, insert, delete, update records in several tables etc etc etc...

How do I get the default values for each table after I use the insertRow() to insert new records
AS THEY ARE specified in MySQL...

In other words:
I need to read those values from MySQL, NOT to set them programmatically
within Qt (i.e setData)....

Does this functionality even exist???

Thanks
Aris

arimaniac
1st February 2011, 20:36
ok.. so query the db for default values...


desc <table name>;

should also work then..
THANKS!

Added after 25 minutes:

SOLUTION :



QSqlQuery query("desc "+TableName);
int i = 0;
while (query.next()) {
if(i)
{
QString val = query.value(4).toString();
if( val!= "")
{
myDataModel->setData(DataModel->index(DataModel->rowCount()-1 , i ) , val , Qt::EditRole);
}
}
i++;
}