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. Getting SQLite table schema information
Forum Updated to NodeBB v4.3 + New Features

Getting SQLite table schema information

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.4k 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.
  • D Offline
    D Offline
    dwilliams
    wrote on last edited by dwilliams
    #1

    I am writing a unit test for my "createTables" method in my db class. I've successfully worked with SQLite databases in the past and am comfortable with the QSqlDatabase (and related) classes. However, I'm not sure how to query the list of columns in a table.

    For example, my createTables method creates a table named "metadata" with key TEXT, value TEXT. My unit test can successfuly check if the table has been created. What I want to do now is check to make sure those two columns exist in the table. I'm not exactly sure how to do that. Do I need to craft a SQL query? Or is there a property on some class that I can query?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      If memory serves well, something like:

      SELECT sql 
      FROM sqlite_master 
      WHERE name = 'mytable';
      

      should get you what you want.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Or use QSqlDriver::tables()

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2

        • Login

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