pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Serial columns and ADO
11+ messages / 3 participants
[nested] [flat]

* Serial columns and ADO
@ 2006-11-09 10:32 Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 00:41 ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  0 siblings, 1 reply; 11+ messages in thread

From: Dmitry Samokhin @ 2006-11-09 10:32 UTC (permalink / raw)
  To: pgsql-odbc

As far as I understand, since the driver exposes 'serial' columns 
as 'AutoNumber', ADO issues 'SELECT @@IDENTITY' to retreive the new 
generated values just after inserts. The driver, in turn, has to modify that 
query into 'SELECT currval(...)'.

When working with PG tables from inside MS Access, it all works perfectly! 
But here is a small test suite that doesn't work as expected:

----------------------------------------------------------------------------
Server side:

CREATE TABLE t1
(
  col1 serial NOT NULL,
  col2 varchar(50)
)
WITHOUT OIDS;

Client side (Visual Basic 6.0 or VBA):

Sub Test()
  Dim strSql As String
  Dim cn As New ADODB.Connection
  Dim rs As New ADODB.Recordset

  cn.Open "Provider=MSDASQL.1;Data Source=Test_pg;"

  strSql = "SELECT * FROM t1"

  rs.ActiveConnection = cn
  rs.CursorLocation = adUseClient
  rs.CursorType = adOpenStatic
  rs.LockType = adLockOptimistic
  rs.Source = strSql

  rs.Open

  rs.AddNew
  rs("col2") = "Sample string"
  rs.Update
  MsgBox rs("col1")

  rs.Close
End Sub
----------------------------------------------------------------------------

Try this and you will see '0' in the messagebox shown and the entries in 
psqlodbc_xxxx.log similar to the following:

.................
conn=04973D90, query='INSERT INTO "public"."t1" ("col2") VALUES (E'Sample 
string')'
conn=04973D90, query='SELECT 0'
.................

My environment:
PostgreSQL 8.1.0 backend
ODBC driver 08.02.0200 Unicode (the latest at the moment of writing) on 
WinXP SP2

Any ideas?
Dmitry.




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

* Re: Serial columns and ADO
  2006-11-09 10:32 Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
@ 2006-11-10 00:41 ` Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-10 09:25   ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  0 siblings, 1 reply; 11+ messages in thread

From: Hiroshi Inoue @ 2006-11-10 00:41 UTC (permalink / raw)
  To: Dmitry Samokhin <sdld@mail.ru>; +Cc: pgsql-odbc

Dmitry Samokhin wrote:
> As far as I understand, since the driver exposes 'serial' columns 
> as 'AutoNumber', ADO issues 'SELECT @@IDENTITY' to retreive the new 
> generated values just after inserts. The driver, in turn, has to modify that 
> query into 'SELECT currval(...)'.
> 
> When working with PG tables from inside MS Access, it all works perfectly! 
> But here is a small test suite that doesn't work as expected:

Please try the snapshot dll at
	http://www.geocities.jp/inocchichichi/psqlodbc/index.html
.

regards,
Hiroshi Inoue



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

* Re: Serial columns and ADO
  2006-11-09 10:32 Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 00:41 ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
@ 2006-11-10 09:25   ` Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 09:28     ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  0 siblings, 1 reply; 11+ messages in thread

From: Dmitry Samokhin @ 2006-11-10 09:25 UTC (permalink / raw)
  To: pgsql-odbc

Hiroshi-san,
I've tried your snapshot (8.2.0201) and found no difference in behaviour. It 
sends 'SELECT 0' as before. Is it really corrected in the snapshot? Maybe I 
have incorrect driver settings. Which ones affect most of all?
Dmitry.


"Hiroshi Inoue" <inoue@tpf.co.jp> wrote in message 
news:4553CAC6.5020001@tpf.co.jp...
> Dmitry Samokhin wrote:
>> As far as I understand, since the driver exposes 'serial' columns as 
>> 'AutoNumber', ADO issues 'SELECT @@IDENTITY' to retreive the new 
>> generated values just after inserts. The driver, in turn, has to modify 
>> that query into 'SELECT currval(...)'.
>>
>> When working with PG tables from inside MS Access, it all works 
>> perfectly! But here is a small test suite that doesn't work as expected:
>
> Please try the snapshot dll at
> http://www.geocities.jp/inocchichichi/psqlodbc/index.html
> .
>
> regards,
> Hiroshi Inoue
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
> 





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

* Re: Serial columns and ADO
  2006-11-09 10:32 Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 00:41 ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-10 09:25   ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
@ 2006-11-10 09:28     ` Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-10 13:09       ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  0 siblings, 1 reply; 11+ messages in thread

From: Hiroshi Inoue @ 2006-11-10 09:28 UTC (permalink / raw)
  To: Dmitry Samokhin <sdld@mail.ru>; +Cc: pgsql-odbc

Dmitry Samokhin wrote:
> Hiroshi-san,
> I've tried your snapshot (8.2.0201) and found no difference in behaviour. It 
> sends 'SELECT 0' as before.

Hmm could you send me the Mylog output ?

regards,
Hiroshi Inoue



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

* Re: Serial columns and ADO
  2006-11-09 10:32 Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 00:41 ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-10 09:25   ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 09:28     ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
@ 2006-11-10 13:09       ` Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 14:53         ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  0 siblings, 1 reply; 11+ messages in thread

From: Dmitry Samokhin @ 2006-11-10 13:09 UTC (permalink / raw)
  To: pgsql-odbc

Just sent to your e-mail found at
http://www.geocities.jp/inocchichichi/psqlodbc/index.html

Dmitry.


"Hiroshi Inoue" <inoue@tpf.co.jp> wrote in message 
news:4554463D.6000301@tpf.co.jp...
> Dmitry Samokhin wrote:
>> Hiroshi-san,
>> I've tried your snapshot (8.2.0201) and found no difference in behaviour. 
>> It
>> sends 'SELECT 0' as before.
>
> Hmm could you send me the Mylog output ?
>
> regards,
> Hiroshi Inoue
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
>               http://archives.postgresql.org
> 





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

* Re: Serial columns and ADO
  2006-11-09 10:32 Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 00:41 ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-10 09:25   ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 09:28     ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-10 13:09       ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
@ 2006-11-10 14:53         ` Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-12 23:44           ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  0 siblings, 1 reply; 11+ messages in thread

From: Hiroshi Inoue @ 2006-11-10 14:53 UTC (permalink / raw)
  To: Dmitry Samokhin <sdld@mail.ru>; +Cc: pgsql-odbc

Dmitry Samokhin wrote:
> Just sent to your e-mail found at
> http://www.geocities.jp/inocchichichi/psqlodbc/index.html

Could you try to set the Extra Opts option to 0x2 ?

regards,
Hiroshi Inoue



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

* Re: Serial columns and ADO
  2006-11-09 10:32 Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 00:41 ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-10 09:25   ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 09:28     ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-10 13:09       ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 14:53         ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
@ 2006-11-12 23:44           ` Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-13 09:24             ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  0 siblings, 1 reply; 11+ messages in thread

From: Hiroshi Inoue @ 2006-11-12 23:44 UTC (permalink / raw)
  To: Dmitry Samokhin <sdld@mail.ru>; +Cc: pgsql-odbc

Hiroshi Inoue wrote:
> Dmitry Samokhin wrote:
>> Just sent to your e-mail found at
>> http://www.geocities.jp/inocchichichi/psqlodbc/index.html
> 
> Could you try to set the Extra Opts option to 0x2 ?

With the current snapshot, please.
I was able to reproduce the behavior here.

regards,
Hiroshi Inoue



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

* Re: Serial columns and ADO
  2006-11-09 10:32 Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 00:41 ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-10 09:25   ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 09:28     ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-10 13:09       ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 14:53         ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-12 23:44           ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
@ 2006-11-13 09:24             ` Dmitry Samokhin <sdld@mail.ru>
  2006-11-16 14:02               ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  0 siblings, 1 reply; 11+ messages in thread

From: Dmitry Samokhin @ 2006-11-13 09:24 UTC (permalink / raw)
  To: pgsql-odbc

>> Could you try to set the Extra Opts option to 0x2 ?
>
> With the current snapshot, please.
> I was able to reproduce the behavior here.
>
> regards,
> Hiroshi Inoue

OK, now it works! Thanks for your attention.
But with Extra Opts = 0x0 it still issues 'SELECT 0' and assignes 0 to an 
identity field. IMHO, if I don't want to read any server-assigned defaults 
for a newly inserted row, any field not set explicitly should contain NULL 
both before and after insert operation, not 0.

Regards,
Dmitry. 





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

* Re: Serial columns and ADO
  2006-11-09 10:32 Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 00:41 ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-10 09:25   ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 09:28     ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-10 13:09       ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 14:53         ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-12 23:44           ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-13 09:24             ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
@ 2006-11-16 14:02               ` Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-17 08:22                 ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  0 siblings, 1 reply; 11+ messages in thread

From: Hiroshi Inoue @ 2006-11-16 14:02 UTC (permalink / raw)
  To: Dmitry Samokhin <sdld@mail.ru>; +Cc: pgsql-odbc

Dmitry Samokhin wrote:
>>> Could you try to set the Extra Opts option to 0x2 ?
>>>       
>> With the current snapshot, please.
>> I was able to reproduce the behavior here.
>>
>> regards,
>> Hiroshi Inoue
>>     
>
> OK, now it works! Thanks for your attention.
> But with Extra Opts = 0x0 it still issues 'SELECT 0' and assignes 0 to an 
> identity field. IMHO, if I don't want to read any server-assigned defaults 
> for a newly inserted row, any field not set explicitly should contain NULL 
> both before and after insert operation, not 0.
>   

OK try the snapshot dll.
0x2 Extra Opts option is no longer needed for the case.
Also changed to SELECT NULL in case of failure.

regards,
Hiroshi Inoue




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

* Re: Serial columns and ADO
  2006-11-09 10:32 Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 00:41 ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-10 09:25   ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 09:28     ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-10 13:09       ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 14:53         ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-12 23:44           ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-13 09:24             ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-16 14:02               ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
@ 2006-11-17 08:22                 ` Dmitry Samokhin <sdld@mail.ru>
  2006-11-17 17:22                   ` Re: Serial columns and ADO Dmitriy Ivanov <divanov-NOSP@M-aha.ru>
  0 siblings, 1 reply; 11+ messages in thread

From: Dmitry Samokhin @ 2006-11-17 08:22 UTC (permalink / raw)
  To: pgsql-odbc

> OK try the snapshot dll.
> 0x2 Extra Opts option is no longer needed for the case.

>
> regards,
> Hiroshi Inoue

OK, 'SELECT 0' has been swept out.

> Also changed to SELECT NULL in case of failure.
What failure do you mean?

But there's still another problem. Let our table 't1' be initially empty and 
the sequence reset to 1. Consider the following ADO operations:

  rs.AddNew
  rs("col2") = "Sample string"
  rs.Update
  MsgBox rs("col1")

  rs.AddNew
  rs("col1") = 2
  rs("col2") = "Sample string"
  rs.Update
  MsgBox rs("col1")

Look, the second insert operation sets the identity field explicitly. But 
the driver still lets 'SELECT currval...' to pass. As a result, my explicit 
value '2' is replaced by the currval()=1. Such distortion should be avoided 
anyway.

Dmitry. 





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

* Re: Serial columns and ADO
  2006-11-09 10:32 Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 00:41 ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-10 09:25   ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 09:28     ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-10 13:09       ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-10 14:53         ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-12 23:44           ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-13 09:24             ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
  2006-11-16 14:02               ` Re: Serial columns and ADO Hiroshi Inoue <inoue@tpf.co.jp>
  2006-11-17 08:22                 ` Re: Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
@ 2006-11-17 17:22                   ` Dmitriy Ivanov <divanov-NOSP@M-aha.ru>
  0 siblings, 0 replies; 11+ messages in thread

From: Dmitriy Ivanov @ 2006-11-17 17:22 UTC (permalink / raw)
  To: pgsql-odbc

Hello Dmitry,
"Dmitry Samokhin" <sdld@mail.ru> wrote:

DS> But there's still another problem. Let our table 't1' be initially
DS> empty and the sequence reset to 1. Consider the following ADO operations:
DS>
DS>   rs.AddNew
DS>   rs("col2") = "Sample string"
DS>   rs.Update
DS>   MsgBox rs("col1")
DS>
DS>   rs.AddNew
DS>   rs("col1") = 2
DS>   rs("col2") = "Sample string"
DS>   rs.Update
DS>   MsgBox rs("col1")
DS>
DS> Look, the second insert operation sets the identity field
DS> explicitly. But the driver still lets 'SELECT currval...' to pass.
DS> As a result, my explicit value '2' is replaced by the currval()=1.
DS> Such distortion should be avoided anyway.

Generally, if you declared the column type as serial, you should not set it
explicitly while inserting records. In your example, rs.Update does not
guarantee changing the cursor position to the record inserted most recently.
(At least, with DAO against MS Access database.)  IMHO, it is not the ODBC
driver to blame.
--
Sincerely,
Dmitriy Ivanov





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


end of thread, other threads:[~2006-11-17 17:22 UTC | newest]

Thread overview: 11+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-11-09 10:32 Serial columns and ADO Dmitry Samokhin <sdld@mail.ru>
2006-11-10 00:41 ` Hiroshi Inoue <inoue@tpf.co.jp>
2006-11-10 09:25   ` Dmitry Samokhin <sdld@mail.ru>
2006-11-10 09:28     ` Hiroshi Inoue <inoue@tpf.co.jp>
2006-11-10 13:09       ` Dmitry Samokhin <sdld@mail.ru>
2006-11-10 14:53         ` Hiroshi Inoue <inoue@tpf.co.jp>
2006-11-12 23:44           ` Hiroshi Inoue <inoue@tpf.co.jp>
2006-11-13 09:24             ` Dmitry Samokhin <sdld@mail.ru>
2006-11-16 14:02               ` Hiroshi Inoue <inoue@tpf.co.jp>
2006-11-17 08:22                 ` Dmitry Samokhin <sdld@mail.ru>
2006-11-17 17:22                   ` Dmitriy Ivanov <divanov-NOSP@M-aha.ru>

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