| From: | Igor Korot <ikorot01(at)gmail(dot)com> |
|---|---|
| To: | "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
| Subject: | libpq simple SELECT |
| Date: | 2025-12-17 05:49:37 |
| Message-ID: | CA+FnnTzP_9Mh9S7NJL5WFJmbOi2wxw4g=MdoUo-SuXEp3Fyg-g@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Hi, ALL,
On the page https://www.postgresql.org/docs/current/libpq-example.html
in the first program there is a following comment:
[code]
/*
* Our test case here involves using a cursor, for which we must be inside
* a transaction block. We could do the whole thing with a single
* PQexec() of "select * from pg_database", but that's too trivial to make
* a good example.
*/
[/code]
I just tried the following code:
[code]
std::wstring query1 = L"SELECT t.table_catalog AS catalog,
t.table_schema AS schema, t.table_name AS table, u.usename AS owner,
c.oid AS table_id FROM information_schema.tables t,
pg_catalog.pg_class c, pg_catalog.pg_user u WHERE t.table_name =
c.relname AND c.relowner = usesysid AND (t.table_type = 'BASE TABLE'
OR t.table_type = 'VIEW' OR t.table_type = 'LOCAL TEMPORARY') ORDER BY
table_name;";
res = PQexec( m_db, m_pimpl->m_myconv.to_bytes( query1.c_str()
).c_str() );
for( int i = 0; i < PQntuples( res ); i++ )
{
some code handling the results
}
[/code]
The loop is executed exactly 1 time.
My question is - according to the comment above I don't have to use cursor,
but it looks like it's unavoidable?
Thank you.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Igor Korot | 2025-12-17 05:53:58 | Re: PQexecPrepared() question |
| Previous Message | Igor Korot | 2025-12-17 05:26:56 | Re: [GENERAL] Retrieving query results |