SQLite column datatype
-
Hi,
I need to get datatypes of all columns in SQLite table, I found SQLite function and tried this:--@for (int x = 0; x <= provider->model->columnCount()-1; x++) {
QListWidgetItem *item = new QListWidgetItem;
item->setText(provider->model->headerData(x, Qt::Horizontal, Qt::DisplayRole).toString());
QSqlQuery query(provider->db);
query.exec("SELECT typeof(" + provider->model->headerData(x, Qt::Horizontal, Qt::DisplayRole).toString() + ") FROM " + provider->model->tableName());
qDebug() << query.value(0).toString();
//lwColumns->addItem(item);
}@
But my output is: QSqlQuery::value: not positioned on a valid record ""
Can you tell me where is problem or is there another way how to get column datatypes? Thanks -
Try this:
@query.exec("SELECT typeof(" + provider->model->headerData(x, Qt::Horizontal, Qt::DisplayRole).toString() + ") FROM " + provider->model->tableName());
query.next();
qDebug() << query.value(0).toString();@If this is not working there will be a problem with your query, what is the result value of exec? And what is the executed query?