get number of rows selected

get number of rows selected

am 03.04.2008 15:20:04 von Malm Paul

This is a multi-part message in MIME format.

------_=_NextPart_001_01C8958D.6E07F2AE
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable


Hi,
I dont know much about databases, and I have a question

I've just installed PostgreSLQ.
Now I would like to get the number of rows selected via a ODBC SQL
statement in C++. I would like to know the amount before I do Fetch.
=20
This is a little example of what I do in c++:

selStr=3D"select * from layer where visible =3D 1");
rc =3D SQLAllocHandle(SQL_HANDLE_STMT, ConHandle, &StmtHandle);
if(rc == SQL_SUCCESS)
{
SQLSetStmtOption(StmtHandle, SQL_CONCURRENCY,
SQL_CONCUR_READ_ONLY);
SQLSetStmtOption(StmtHandle, SQL_CURSOR_TYPE,
SQL_CURSOR_KEYSET_DRIVEN);
SQLSetStmtOption(StmtHandle, SQL_ROWSET_SIZE, m_rows);
rc =3D SQLExecDirect(StmtHandle, (SQLCHAR *)selStr,
SQL_NTS);
....
....
....
How do I know how many rows that was found??


Kind regards,

Paul Malm


------_=_NextPart_001_01C8958D.6E07F2AE
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable




charset=3Dus-ascii">
6.5.7652.24">
get number of rows selected






Hi,


I dont know much about databases, and =
I have a question



I've just installed PostgreSLQ.


Now I would like to =
get the number of rows selected via a ODBC SQL statement in C++. I would =
like to know the amount before I do Fetch.



 


This is a little =
example of what I do in c++:



        SIZE=3D2 FACE=3D"Courier New">selStr=3D"select * from layer where =
visible =3D 1");



        =
rc =3D =
SQLAllocHandle(SQL_HANDLE_STMT, ConHandle, =
&StmtHandle);



        =
if(rc == =
SQL_SUCCESS)



        =
{



        =
        FACE=3D"Courier New">SQLSetStmtOption(StmtHandle, SQL_CONCURRENCY, =
SQL_CONCUR_READ_ONLY);



        =
        FACE=3D"Courier New">SQLSetStmtOption(StmtHandle, SQL_CURSOR_TYPE, =
SQL_CURSOR_KEYSET_DRIVEN);



        =
        FACE=3D"Courier New">SQLSetStmtOption(StmtHandle, SQL_ROWSET_SIZE, =
m_rows);



        =
        FACE=3D"Courier New">rc =3D SQLExecDirect(StmtHandle, (SQLCHAR *)selStr, =
SQL_NTS);



...


...


...


How do I know how =
many rows that was found??





Kind =
regards,



Paul =
Malm





------_=_NextPart_001_01C8958D.6E07F2AE--

Connection of postgres

am 03.04.2008 16:04:05 von l7nguyen

Hey,
=20
I have a problem with connection of postgres.
I am using postgres 8.03.01.
=20
I have a telecom program which have 248 channels and each channel hold a co=
nnection to postgres database, mean i have 248 opening connections.
=20
When a channel is run, it means it begin to excute some queries to postgres=
, i got the error : SQL Error State: 08S01

Native Error Code: 1A

ODBC Error: Could not send
Query(connection dead);

Could not send Query(connection dead)

=20
Could you help me on this ?
=20
=20
Thanks you very much
Lam
=20
=20
=20
=20
=20

This email may contain material that is confidential, privileged, and/or at=
torney work product for the sole use of the intended recipient. Any review=
, reliance, or distribution by others or forwarding without express permiss=
ion is strictly prohibited. If you are not the intended recipient, please =
contact the sender and delete all copies.

--=20
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Re: get number of rows selected

am 03.04.2008 18:30:07 von Adam M

Generally you would do that with a count function instead of relying
on something else.

"select * from layer where visible = 1"

so I guess "SELECT COUNT(*) FROM layer WHERE visible=1" would give you
the answer.

- Adam

--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Re: get number of rows selected

am 07.04.2008 03:30:16 von Andrei Kovalevski

This is a multi-part message in MIME format.
--------------090906070702000905030802
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hello,

Take a look at SQLRowCount(
http://msdn2.microsoft.com/en-us/library//ms711835.aspx ). You may note:

*/For other statements and functions, the driver may define the value
returned in *RowCountPtr. For example, some data sources may be able to
return the number of rows returned by a SELECT statement or a catalog
function before fetching the rows./*

You may rely on this when using psqlODBC or ODBCng with buffering mode
ON (default).

Adam M wrote:
> Generally you would do that with a count function instead of relying
> on something else.
>
> "select * from layer where visible = 1"
>
> so I guess "SELECT COUNT(*) FROM layer WHERE visible=1" would give you
> the answer.
>
> - Adam
>
--
Andrei Kovalevski
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, ODBCng - http://www.commandprompt.com/


--------------090906070702000905030802
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit








Hello,



Take a look at SQLRowCount(
). You may note:



For other statements and functions, the driver may define the
value returned in *RowCountPtr. For example, some data sources may be
able to return the number of rows returned by a SELECT statement or a
catalog function before fetching the rows.




You may rely on this when using  psqlODBC or  ODBCng with buffering
mode ON (default).



Adam M wrote:
cite="mid:84b37b360804030930o1b771e47ib9082bf3cecb54f6@mail. gmail.com"
type="cite">

Generally you would do that with a count function instead of relying
on something else.

"select * from layer where visible = 1"

so I guess "SELECT COUNT(*) FROM layer WHERE visible=1" would give you
the answer.

- Adam


-- 
Andrei Kovalevski
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, ODBCng -




--------------090906070702000905030802--

Re: Connection of postgres

am 07.04.2008 03:35:57 von Andrei Kovalevski

Hello,

Does it happen after some idle period?

Nguyen, Lam Thuy wrote:
> Hey,
>
> I have a problem with connection of postgres.
> I am using postgres 8.03.01.
>
> I have a telecom program which have 248 channels and each channel hold a connection to postgres database, mean i have 248 opening connections.
>
> When a channel is run, it means it begin to excute some queries to postgres, i got the error : SQL Error State: 08S01
>
> Native Error Code: 1A
>
> ODBC Error: Could not send
> Query(connection dead);
>
> Could not send Query(connection dead)
>
>
> Could you help me on this ?
>
>
> Thanks you very much
> Lam
>
>
>
>
>
>
> This email may contain material that is confidential, privileged, and/or attorney work product for the sole use of the intended recipient. Any review, reliance, or distribution by others or forwarding without express permission is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
>
>


--
Andrei Kovalevski
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, ODBCng - http://www.commandprompt.com/


--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Re: Connection of postgres

am 07.04.2008 03:38:19 von l7nguyen

yes, it is right.

________________________________

From: Andrei Kovalevski [mailto:andyk@commandprompt.com]
Sent: Sun 4/6/2008 9:35 PM
To: Nguyen, Lam Thuy
Cc: Malm Paul; pgsql-odbc@postgresql.org
Subject: Re: [ODBC] Connection of postgres



Hello,

Does it happen after some idle period?

Nguyen, Lam Thuy wrote:
> Hey,
>=20
> I have a problem with connection of postgres.
> I am using postgres 8.03.01.
>=20
> I have a telecom program which have 248 channels and each channel hold a =
connection to postgres database, mean i have 248 opening connections.
>=20
> When a channel is run, it means it begin to excute some queries to postgr=
es, i got the error : SQL Error State: 08S01
>
> Native Error Code: 1A
>
> ODBC Error: Could not send
> Query(connection dead);
>
> Could not send Query(connection dead)
>
>=20
> Could you help me on this ?
>=20
>=20
> Thanks you very much
> Lam
>=20
>=20
>=20
>=20
>=20
>
> This email may contain material that is confidential, privileged, and/or =
attorney work product for the sole use of the intended recipient. Any revi=
ew, reliance, or distribution by others or forwarding without express permi=
ssion is strictly prohibited. If you are not the intended recipient, pleas=
e contact the sender and delete all copies.
>
>


--
Andrei Kovalevski
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, ODBCng - http://www.commandprompt.com/




This email may contain material that is confidential, privileged, and/or at=
torney work product for the sole use of the intended recipient. Any review=
, reliance, or distribution by others or forwarding without express permiss=
ion is strictly prohibited. If you are not the intended recipient, please =
contact the sender and delete all copies.

--=20
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Re: Connection of postgres

am 07.04.2008 04:26:00 von Andrei Kovalevski

This is a multi-part message in MIME format.
--------------090803040903060905060306
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

I'm figuring similar behaviour with Linux PostgreSQL server and Win32
client, connection over Internet (not LAN). Not sure what is the source
of this problem but it could be something network relative.

Nguyen, Lam Thuy wrote:
> yes, it is right.
>
> ________________________________
>
> From: Andrei Kovalevski [mailto:andyk@commandprompt.com]
> Sent: Sun 4/6/2008 9:35 PM
> To: Nguyen, Lam Thuy
> Cc: Malm Paul; pgsql-odbc@postgresql.org
> Subject: Re: [ODBC] Connection of postgres
>
>
>
> Hello,
>
> Does it happen after some idle period?
>
> Nguyen, Lam Thuy wrote:
>
>> Hey,
>>
>> I have a problem with connection of postgres.
>> I am using postgres 8.03.01.
>>
>> I have a telecom program which have 248 channels and each channel hold a connection to postgres database, mean i have 248 opening connections.
>>
>> When a channel is run, it means it begin to excute some queries to postgres, i got the error : SQL Error State: 08S01
>>
>> Native Error Code: 1A
>>
>> ODBC Error: Could not send
>> Query(connection dead);
>>
>> Could not send Query(connection dead)
>>
>>
>> Could you help me on this ?
>>
>>
>> Thanks you very much
>> Lam
>>
>>
>>
>>
>>
>>
>> This email may contain material that is confidential, privileged, and/or attorney work product for the sole use of the intended recipient. Any review, reliance, or distribution by others or forwarding without express permission is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
>>
>>
>>
>
>
> --
> Andrei Kovalevski
> PostgreSQL Replication, Consulting, Custom Development, 24x7 support
> Managed Services, Shared and Dedicated Hosting
> Co-Authors: plPHP, ODBCng - http://www.commandprompt.com/
>
>
>
>
> This email may contain material that is confidential, privileged, and/or attorney work product for the sole use of the intended recipient. Any review, reliance, or distribution by others or forwarding without express permission is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
>
>


--
Andrei Kovalevski
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, ODBCng - http://www.commandprompt.com/


--------------090803040903060905060306
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit







I'm figuring similar behaviour with Linux PostgreSQL server  and Win32
client, connection over Internet (not LAN). Not sure what is the source
of this problem but it could be something network relative.



Nguyen, Lam Thuy wrote:
cite="mid:C3D5057033EDF145B90A99CD9025BFEA01C601FB@hont05.fc g.com"
type="cite">

yes, it is right.

________________________________

From: Andrei Kovalevski []
Sent: Sun 4/6/2008 9:35 PM
To: Nguyen, Lam Thuy
Cc: Malm Paul;
Subject: Re: [ODBC] Connection of postgres



Hello,

Does it happen after some idle period?

Nguyen, Lam Thuy wrote:


Hey,

I have a problem with connection of postgres.
I am using postgres 8.03.01.

I have a telecom program which have 248 channels and each channel hold a connection to postgres database, mean i have 248 opening connections.

When a channel is run, it means it begin to excute some queries to postgres, i got the error : SQL Error State: 08S01

Native Error Code: 1A

ODBC Error: Could not send
Query(connection dead);

Could not send Query(connection dead)


Could you help me on this ?


Thanks you very much
Lam






This email may contain material that is confidential, privileged, and/or attorney work product for the sole use of the intended recipient. Any review, reliance, or distribution by others or forwarding without express permission is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.






--
Andrei Kovalevski
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, ODBCng -




This email may contain material that is confidential, privileged, and/or attorney work product for the sole use of the intended recipient. Any review, reliance, or distribution by others or forwarding without express permission is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.







-- 
Andrei Kovalevski
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, ODBCng -




--------------090803040903060905060306--

Re: Connection of postgres

am 07.04.2008 04:40:03 von l7nguyen

Kovalevski ,
=20
I am sure there was no prolem with network. I guess maybe postgres database=
can not handle if there are many connections work concurrenly.
=20
Lam

________________________________

From: Andrei Kovalevski [mailto:andyk@commandprompt.com]
Sent: Sun 4/6/2008 10:26 PM
To: Nguyen, Lam Thuy
Cc: Malm Paul; pgsql-odbc@postgresql.org
Subject: Re: [ODBC] Connection of postgres


I'm figuring similar behaviour with Linux PostgreSQL server and Win32 clie=
nt, connection over Internet (not LAN). Not sure what is the source of this=
problem but it could be something network relative.

Nguyen, Lam Thuy wrote:=20

yes, it is right.
=09
________________________________
=09
From: Andrei Kovalevski [mailto:andyk@commandprompt.com]
Sent: Sun 4/6/2008 9:35 PM
To: Nguyen, Lam Thuy
Cc: Malm Paul; pgsql-odbc@postgresql.org
Subject: Re: [ODBC] Connection of postgres
=09
=09
=09
Hello,
=09
Does it happen after some idle period?
=09
Nguyen, Lam Thuy wrote:
=20

Hey,

I have a problem with connection of postgres.
I am using postgres 8.03.01.

I have a telecom program which have 248 channels and each channel hold a =
connection to postgres database, mean i have 248 opening connections.

When a channel is run, it means it begin to excute some queries to postgr=
es, i got the error : SQL Error State: 08S01

Native Error Code: 1A

ODBC Error: Could not send
Query(connection dead);

Could not send Query(connection dead)


Could you help me on this ?


Thanks you very much
Lam






This email may contain material that is confidential, privileged, and/or =
attorney work product for the sole use of the intended recipient. Any revi=
ew, reliance, or distribution by others or forwarding without express permi=
ssion is strictly prohibited. If you are not the intended recipient, pleas=
e contact the sender and delete all copies.

=20


--
Andrei Kovalevski
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, ODBCng - http://www.commandprompt.com/
=09
=09
=09
=09
This email may contain material that is confidential, privileged, and/or a=
ttorney work product for the sole use of the intended recipient. Any revie=
w, reliance, or distribution by others or forwarding without express permis=
sion is strictly prohibited. If you are not the intended recipient, please=
contact the sender and delete all copies.
=09
=20



--=20
Andrei Kovalevski
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Managed Services, Shared and Dedicated Hosting
Co-Authors: plPHP, ODBCng - http://www.commandprompt.com/

This email may contain material that is confidential, privileged, and/or at=
torney work product for the sole use of the intended recipient. Any review=
, reliance, or distribution by others or forwarding without express permiss=
ion is strictly prohibited. If you are not the intended recipient, please =
contact the sender and delete all copies.

--=20
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Re: Connection of postgres

am 07.04.2008 17:05:09 von Rod

On 07/04/2008 03:40, Nguyen, Lam Thuy wrote:

> I am sure there was no prolem with network. I guess maybe postgres
> database can not handle if there are many connections work
> concurrenly.

That's not so - if you've configured it correctly, if your hardware can
handle it, PostgreSQL scales *very* well. What have you got
max_connections set to in postgresql.conf?

Ray.


------------------------------------------------------------ ------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod@iol.ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------ ------

--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Re: Connection of postgres

am 07.04.2008 20:02:30 von l7nguyen

I set it up to 300.
Do you have any solution for me?
=20
Lam

________________________________

From: Raymond O'Donnell [mailto:rod@iol.ie]
Sent: Mon 4/7/2008 11:05 AM
To: Nguyen, Lam Thuy
Cc: Andrei Kovalevski; Malm Paul; pgsql-odbc@postgresql.org
Subject: Re: [ODBC] Connection of postgres



On 07/04/2008 03:40, Nguyen, Lam Thuy wrote:

> I am sure there was no prolem with network. I guess maybe postgres
> database can not handle if there are many connections work
> concurrenly.

That's not so - if you've configured it correctly, if your hardware can
handle it, PostgreSQL scales *very* well. What have you got
max_connections set to in postgresql.conf?

Ray.


------------------------------------------------------------ ------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod@iol.ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------ ------



This email may contain material that is confidential, privileged, and/or at=
torney work product for the sole use of the intended recipient. Any review=
, reliance, or distribution by others or forwarding without express permiss=
ion is strictly prohibited. If you are not the intended recipient, please =
contact the sender and delete all copies.

--=20
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Re: Connection of postgres

am 09.04.2008 20:40:28 von Adam M

I've had a similar "problem". The connection times out and get closed
after a few hours. The solution was to do a query to keep the database
alive, for example "SELECT 1" and that's all. That is done every few
minutes.

The real test is to open 250 connections, and issue queries on each
without idle time. Does connection drop occur on active connections?

--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Re: Connection of postgres

am 09.04.2008 20:57:41 von l7nguyen

i open connection, and leave it for few hour, and then excute query, and ge=
t error.

________________________________

From: pgsql-odbc-owner@postgresql.org on behalf of Adam M
Sent: Wed 4/9/2008 2:40 PM
Cc: pgsql-odbc@postgresql.org
Subject: Re: [ODBC] Connection of postgres



I've had a similar "problem". The connection times out and get closed
after a few hours. The solution was to do a query to keep the database
alive, for example "SELECT 1" and that's all. That is done every few
minutes.

The real test is to open 250 connections, and issue queries on each
without idle time. Does connection drop occur on active connections?

--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



This email may contain material that is confidential, privileged, and/or at=
torney work product for the sole use of the intended recipient. Any review=
, reliance, or distribution by others or forwarding without express permiss=
ion is strictly prohibited. If you are not the intended recipient, please =
contact the sender and delete all copies.

--=20
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Re: get number of rows selected

am 10.03.2010 16:10:56 von VitaliyG

paul malm wrote:
>
>
> Hi,
> I dont know much about databases, and I have a question
>
> I've just installed PostgreSLQ.
> Now I would like to get the number of rows selected via a ODBC SQL
> statement in C++. I would like to know the amount before I do Fetch.
>
> This is a little example of what I do in c++:
>
> selStr="select * from layer where visible = 1");
> rc = SQLAllocHandle(SQL_HANDLE_STMT, ConHandle, &StmtHandle);
> if(rc == SQL_SUCCESS)
> {
> SQLSetStmtOption(StmtHandle, SQL_CONCURRENCY,
> SQL_CONCUR_READ_ONLY);
> SQLSetStmtOption(StmtHandle, SQL_CURSOR_TYPE,
> SQL_CURSOR_KEYSET_DRIVEN);
> SQLSetStmtOption(StmtHandle, SQL_ROWSET_SIZE, m_rows);
> rc = SQLExecDirect(StmtHandle, (SQLCHAR *)selStr,
> SQL_NTS);
> ...
> ...
> ...
> How do I know how many rows that was found??
>
>
> Kind regards,
>
> Paul Malm
>
>
>

Use SQLRowCount ODBC function

--
View this message in context: http://old.nabble.com/get-number-of-rows-selected-tp16475169 p27851040.html
Sent from the PostgreSQL - odbc mailing list archive at Nabble.com.


--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc