pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Bug in SQLRowCount ?
7+ messages / 6 participants
[nested] [flat]

* Bug in SQLRowCount ?
@ 2013-01-17 09:31  j.letzel@t-online.de <j.letzel@t-online.de>
  0 siblings, 1 reply; 7+ messages in thread

From: j.letzel@t-online.de @ 2013-01-17 09:31 UTC (permalink / raw)
  To: pgsql-odbc

Hello ! 

	I maintain a backend in a commercial context. The backend provides
access to MS SQLServer (via ODBC) and Oracle (via OCI). Now I want to
make it ready for PostgreSQL via ODBC. 

	For performance reasons we use bulk inserts/updates. 

	This is done in this manner: 

	SQLAllocStmt 

	SQLPrepare // insert into kfztest.KP values (?,?,...,?) 

	SQBindParameter // for each column 

	... 

	SQLSetStmtAttr // SQL_ATTR_PARAMSET_SIZE to 523 

	SQLSetStmtAttr // SQL_ATTR_PARAM_STATUS_PTR to an array of
SQLSMALLINT 

	SQLSetStmtAttr // SQL_ATTR_PARAMS_PROCESSED_PTR to an SQLULEN
variable 

	SQLExecute // ends with SQL_SUCCESS 

	SQLRowCount // delivers 1 !!!! 

	SQLEndTrans // with COMMIT 

	When necessary I can provide a full ODBC trace. 

	All records were written into table. 

	Thanks in advance. 

	Regards 

	Johann Letzel

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Bug in SQLRowCount ?
@ 2013-01-17 13:08  Hiroshi Inoue <inoue@tpf.co.jp>
  parent: j.letzel@t-online.de <j.letzel@t-online.de>
  0 siblings, 1 reply; 7+ messages in thread

From: Hiroshi Inoue @ 2013-01-17 13:08 UTC (permalink / raw)
  To: j.letzel@t-online.de <j.letzel@t-online.de>; +Cc: pgsql-odbc

(2013/01/17 18:31), j.letzel@t-online.de wrote:
> Hello !
>
> I maintain a backend in a commercial context. The backend provides
> access to MS SQLServer (via ODBC) and Oracle (via OCI). Now I want to
> make it ready for PostgreSQL via ODBC.
>
> For performance reasons we use bulk inserts/updates.
>
> This is done in this manner:
>
> SQLAllocStmt
>
> SQLPrepare // insert into kfztest.KP values (?,?,...,?)
>
> SQBindParameter // for each column
>
> ...
>
> SQLSetStmtAttr // SQL_ATTR_PARAMSET_SIZE to 523
>
> SQLSetStmtAttr // SQL_ATTR_PARAM_STATUS_PTR to an array of SQLSMALLINT
>
> SQLSetStmtAttr // SQL_ATTR_PARAMS_PROCESSED_PTR to an SQLULEN variable
>
> SQLExecute // ends with SQL_SUCCESS
>
> SQLRowCount // delivers 1 !!!!

The driver gives individual row counts for each parameter set.
SQLGetInfo(.., SQL_PARAM_ARRAY_ROW_COUNTS) returns SQL_PARC_BATCH.

regards,
Hiroshi Inoue



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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Bug in SQLRowCount ?
@ 2013-01-17 14:05  Johann Letzel <j.letzel@t-online.de>
  parent: Hiroshi Inoue <inoue@tpf.co.jp>
  0 siblings, 1 reply; 7+ messages in thread

From: Johann Letzel @ 2013-01-17 14:05 UTC (permalink / raw)
  To: Hiroshi Inoue <inoue@tpf.co.jp>; +Cc: pgsql-odbc

Hi !

Tanks for the reply. 

But according to the ODBC API SQLRowCount should retrieve the number of affected rows by the statement.

Why does PostgreSQL gives a 1 and MSSQL the number of inserted/updated rows ?

Regards

Johann 



Hiroshi Inoue <inoue@tpf.co.jp> schrieb:

>(2013/01/17 18:31), j.letzel@t-online.de wrote:
>> Hello !
>>
>> I maintain a backend in a commercial context. The backend provides
>> access to MS SQLServer (via ODBC) and Oracle (via OCI). Now I want to
>> make it ready for PostgreSQL via ODBC.
>>
>> For performance reasons we use bulk inserts/updates.
>>
>> This is done in this manner:
>>
>> SQLAllocStmt
>>
>> SQLPrepare // insert into kfztest.KP values (?,?,...,?)
>>
>> SQBindParameter // for each column
>>
>> ...
>>
>> SQLSetStmtAttr // SQL_ATTR_PARAMSET_SIZE to 523
>>
>> SQLSetStmtAttr // SQL_ATTR_PARAM_STATUS_PTR to an array of
>SQLSMALLINT
>>
>> SQLSetStmtAttr // SQL_ATTR_PARAMS_PROCESSED_PTR to an SQLULEN
>variable
>>
>> SQLExecute // ends with SQL_SUCCESS
>>
>> SQLRowCount // delivers 1 !!!!
>
>The driver gives individual row counts for each parameter set.
>SQLGetInfo(.., SQL_PARAM_ARRAY_ROW_COUNTS) returns SQL_PARC_BATCH.
>
>regards,
>Hiroshi Inoue
>
>
>
>-- 
>Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
>To make changes to your subscription:
>http://www.postgresql.org/mailpref/pgsql-odbc

^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Bug in SQLRowCount ?
@ 2013-01-17 17:03  Heikki Linnakangas <hlinnakangas@vmware.com>
  parent: Johann Letzel <j.letzel@t-online.de>
  0 siblings, 1 reply; 7+ messages in thread

From: Heikki Linnakangas @ 2013-01-17 17:03 UTC (permalink / raw)
  To: Johann Letzel <j.letzel@t-online.de>; +Cc: Hiroshi Inoue <inoue@tpf.co.jp>; pgsql-odbc

On 17.01.2013 16:05, Johann Letzel wrote:
> But according to the ODBC API SQLRowCount should retrieve the number of affected rows by the statement.
>
> Why does PostgreSQL gives a 1 and MSSQL the number of inserted/updated rows ?

According to this: 
http://msdn.microsoft.com/en-us/library/windows/desktop/ms711818%28v=vs.85%29.aspx, 
both behaviors are permitted. When the driver returns SQL_PARC_BATCH, 
when you call SQLGetInfo(conn, SQL_PARAM_ARRAY_ROW_COUNTS, ... ), the 
driver returns a separate row count for each parameter (PostgreSQL). 
When it returns SQL_PARC_NO_BATCH, it returns a single row count that's 
the sum of all parameters (MSSQL). In a portable application, you need 
to call SQLGetInfo, and deal with both behaviors.

- Heikki


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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Bug in SQLRowCount ?
@ 2013-01-22 06:02  Johann Letzel <j.letzel@t-online.de>
  parent: Heikki Linnakangas <hlinnakangas@vmware.com>
  0 siblings, 1 reply; 7+ messages in thread

From: Johann Letzel @ 2013-01-22 06:02 UTC (permalink / raw)
  To: Heikki Linnakangas <hlinnakangas@vmware.com>; +Cc: Hiroshi Inoue <inoue@tpf.co.jp>; pgsql-odbc

Hi !

A big thanks for the tips :)

I solved it now by the use of SQL_ATTR_PARAMS_PROCESSED_PTR and 
SQL_ATTR_PARAM_STATUS_PTR.

By the way: MSSQL also returns SQL_PARC_BATCH ;)

Regards

Johann

Am 17.01.2013 18:03, schrieb Heikki Linnakangas:
> On 17.01.2013 16:05, Johann Letzel wrote:
>> But according to the ODBC API SQLRowCount should retrieve the number
>> of affected rows by the statement.
>>
>> Why does PostgreSQL gives a 1 and MSSQL the number of inserted/updated
>> rows ?
>
> According to this:
> http://msdn.microsoft.com/en-us/library/windows/desktop/ms711818%28v=vs.85%29.aspx,
> both behaviors are permitted. When the driver returns SQL_PARC_BATCH,
> when you call SQLGetInfo(conn, SQL_PARAM_ARRAY_ROW_COUNTS, ... ), the
> driver returns a separate row count for each parameter (PostgreSQL).
> When it returns SQL_PARC_NO_BATCH, it returns a single row count that's
> the sum of all parameters (MSSQL). In a portable application, you need
> to call SQLGetInfo, and deal with both behaviors.
>
> - Heikki
>


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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Bug in SQLRowCount ?
@ 2018-04-04 11:59  Jaydip <jaydeep.thakkar92@gmail.com>
  parent: Johann Letzel <j.letzel@t-online.de>
  0 siblings, 1 reply; 7+ messages in thread

From: Jaydip @ 2018-04-04 11:59 UTC (permalink / raw)
  To: pgsql-odbc

Hello,

I has also face same issue. I am just curious to know, how are you using
SQL_ATTR_PARAM_STATUS_PTR?
I have tried to use that in my code and I was incrementing the count based
on the status "SQL_PARAM_SUCCESS" i.e. 0.
However, I found that when I send let's say 3 rows in batch and there is no
row to delete, the status was still "SQL_PARAM_SUCCESS". When I called
"SQLRowCount" it was returning me 0.



--
Sent from: http://www.postgresql-archive.org/PostgreSQL-odbc-f2186591.html




^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: Bug in SQLRowCount ?
@ 2018-04-04 13:02  Clemens Ladisch <clemens@ladisch.de>
  parent: Jaydip <jaydeep.thakkar92@gmail.com>
  0 siblings, 0 replies; 7+ messages in thread

From: Clemens Ladisch @ 2018-04-04 13:02 UTC (permalink / raw)
  To: pgsql-odbc@lists.postgresql.org

Jaydip wrote:
> I has also face same issue. I am just curious to know, how are you using
> SQL_ATTR_PARAM_STATUS_PTR?

Please note that the mail you were replying to is over five years old.
It is unlikely that the original author still reads this list.

> I have tried to use that in my code and I was incrementing the count based
> on the status "SQL_PARAM_SUCCESS" i.e. 0.
> However, I found that when I send let's say 3 rows in batch and there is no
> row to delete, the status was still "SQL_PARAM_SUCCESS". When I called
> "SQLRowCount" it was returning me 0.

The SQL_ATTR_PARAM_STATUS_PTR array returns whether a statement resulted in
an error.  But a WHERE clause that matches zero rows is not considered an
error by the SQL standard.

To find out how many rows were deleted, you _must_ call SQLRowCount.
For a SQL_PARC_BATCH driver, you have to get each row count separately by
calling SQLRowCount/SQLMoreResults in a loop, as documented here:
<https://docs.microsoft.com/en-us/sql/odbc/reference/develop-app/multiple-results;


Regards,
Clemens




^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2018-04-04 13:02 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-01-17 09:31 Bug in SQLRowCount ? j.letzel@t-online.de <j.letzel@t-online.de>
2013-01-17 13:08 ` Hiroshi Inoue <inoue@tpf.co.jp>
2013-01-17 14:05   ` Johann Letzel <j.letzel@t-online.de>
2013-01-17 17:03     ` Heikki Linnakangas <hlinnakangas@vmware.com>
2013-01-22 06:02       ` Johann Letzel <j.letzel@t-online.de>
2018-04-04 11:59         ` Jaydip <jaydeep.thakkar92@gmail.com>
2018-04-04 13:02           ` Clemens Ladisch <clemens@ladisch.de>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox