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.
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.
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.
If you are doing this to get the table structure then you should look at QSqlDatabase::tables(), QSqlDatabase::record(), and QSqlDatabase::primaryIndex().
In psql:
Qt Code:
create table name(id serial primary key, name varchar(12)); create table other_info(id serial primary key, ref integer references name(id)); zygmunt=> \d other_info Table "public.other_info" Column | Type | Modifiers --------+---------+--------------------------------------------------------- id | integer | not null default nextval('other_info_id_seq'::regclass) ref | integer | Indexes: "other_info_pkey" PRIMARY KEY, btree (id) Foreign-key constraints: "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:
"other_info_ref_fkey" FOREIGN KEY (ref) REFERENCES name(id)To copy to clipboard, switch view to plain text mode
How to do it?
zygmunt (19th January 2011)
@wysota:
My qustion:Query like: "\d my_table" isn't compatible with SQL standard, for me is query, but non-sql.Is it posible to use non sql query in Qt?
Thanks for -E switch.
Now it work, but i have strange value in query:
Qt Code:
SELECT conname, pg_catalog.pg_get_constraintdef(r.oid, true) as condef FROM pg_catalog.pg_constraint r WHERE r.conrelid = '19264' AND r.contype = 'f' ORDER BY 1To 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.
Bookmarks