Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    SQLite column datatype

    General and Desktop
    2
    3
    3013
    Loading More Posts
    • 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
      Sibyx last edited by

      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 Reply Quote 0
      • F
        fluca1978 last edited by

        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 Reply Quote 0
        • S
          Sibyx last edited by

          Thanks! It works!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post