Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SQLite column datatype
Qt 6.11 is out! See what's new in the release blog

SQLite column datatype

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sibyx
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fluca1978
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sibyx
        wrote on last edited by
        #3

        Thanks! It works!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved