Results 1 to 7 of 7

Thread: QSqlQuery and non-sql query

  1. #1
    Join Date
    Oct 2008
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSqlQuery and non-sql query

    Hi!
    Is it posible to use non sql query in Qt?
    I need to get the result from query: "\d my_table".

    PS: i use postgresql, but it will be good trick for other dbms.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlQuery and non-sql query

    What you mean is not a query but a command of postgresql console client (psql). Try querying for "SHOW CREATE TABLE my_table" or "DESCRIBE my_table" instead. If that's not enough, run psql with -E option and then issue the \d my_table command to see what the SQL query for getting the result is.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSqlQuery and non-sql query

    If you are doing this to get the table structure then you should look at QSqlDatabase::tables(), QSqlDatabase::record(), and QSqlDatabase::primaryIndex().

  4. #4
    Join Date
    Oct 2008
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQuery and non-sql query

    In psql:
    Qt Code:
    1. create table name(id serial primary key, name varchar(12));
    2. create table other_info(id serial primary key, ref integer references name(id));
    3.  
    4. zygmunt=> \d other_info
    5. Table "public.other_info"
    6. Column | Type | Modifiers
    7. --------+---------+---------------------------------------------------------
    8. id | integer | not null default nextval('other_info_id_seq'::regclass)
    9. ref | integer |
    10. Indexes:
    11. "other_info_pkey" PRIMARY KEY, btree (id)
    12. Foreign-key constraints:
    13. "other_info_ref_fkey" FOREIGN KEY (ref) REFERENCES name(id)
    To copy to clipboard, switch view to plain text mode 

    And i need to parse this line:
    Qt Code:
    1. "other_info_ref_fkey" FOREIGN KEY (ref) REFERENCES name(id)
    To copy to clipboard, switch view to plain text mode 

    How to do it?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlQuery and non-sql query

    Did you do what I said about the -E switch?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    zygmunt (19th January 2011)

  7. #6
    Join Date
    Oct 2008
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlQuery and non-sql query

    @wysota:
    My qustion:
    Is it posible to use non sql query in Qt?
    Query like: "\d my_table" isn't compatible with SQL standard, for me is query, but non-sql.
    Thanks for -E switch.

    Now it work, but i have strange value in query:
    Qt Code:
    1. SELECT conname,
    2. pg_catalog.pg_get_constraintdef(r.oid, true) as condef
    3. FROM pg_catalog.pg_constraint r
    4. WHERE r.conrelid = '19264' AND r.contype = 'f' ORDER BY 1
    To copy to clipboard, switch view to plain text mode 

    Thanks anyway, thread is solved,
    and i go to search what is it 19264

    PS: Query like: "SHOW CREATE TABLE my_table", or
    "DESCRIBE my_table" doesn't work in postgresql.

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlQuery and non-sql query

    Quote Originally Posted by zygmunt View Post
    Query like: "\d my_table" isn't compatible with SQL standard, for me is query, but non-sql.
    It's not a query. The same as \q which quits the console is not a query. It's a command of the psql program.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QSqlQuery
    By yasher in forum Qt Programming
    Replies: 2
    Last Post: 23rd July 2010, 15:25
  2. MS SQL Query
    By baray98 in forum General Programming
    Replies: 0
    Last Post: 14th July 2009, 05:25
  3. QSqlquery
    By codeman in forum Qt Programming
    Replies: 10
    Last Post: 4th June 2009, 13:57
  4. what is going on a QSqlQuery?
    By mismael85 in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2008, 14:35
  5. Complex query in QSqlQuery
    By xgoan in forum Qt Programming
    Replies: 20
    Last Post: 17th March 2008, 13:04

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.