pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
calling nextval function
3+ messages / 3 participants
[nested] [flat]

* calling nextval function
@ 2004-12-06 15:11  Gosling, Oliver <o.gosling@lancaster.ac.uk>
  0 siblings, 1 reply; 3+ messages in thread

From: Gosling, Oliver @ 2004-12-06 15:11 UTC (permalink / raw)
  To: pgsql-odbc

Does anybody know how to get the next value of a sequence?

 

I'm presuming that nextval is an SQL procedure in postgres which can be
called by passing the name of the sequence as a parameter. The code
below shows what I've done in VB. This does not work however - JET
throws up an error saying that 'nextval' table or query cannot be found.

 

Dim objCmd As New ADODB.Command

Dim objPrm As ADODB.Parameter

        

objCmd.ActiveConnection = CurrentProject.Connection

objCmd.CommandType = adCmdStoredProc

objCmd.CommandText = "nextval"

       

Set objPrm = objCmd.CreateParameter("@name", adBSTR, adParamInput, ,
"bed_id_seq")

objCmd.parameters.Append objPrm

     

Set sequenceNumber = objCmd.Execute

seqNum = sequenceNumber!nextval

 

Can anbody help me with this?

 

Regards,

 

Oliver Gosling

 

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

* Re: calling nextval function
@ 2004-12-06 15:33  Eric E <whalesuit@bonbon.net>
  parent: Gosling, Oliver <o.gosling@lancaster.ac.uk>
  0 siblings, 0 replies; 3+ messages in thread

From: Eric E @ 2004-12-06 15:33 UTC (permalink / raw)
  To: pgsql-odbc

Hi Oliver,
I think the problem with your approach might be in using the nextval 
function as a parameter.
I get sequence values by opening a recordset on the sequence, like this:

Dim cnPGODBC as ADODB.Connection
Dim rsSeqVal as ADODB.Recordset
Dim sSeqValSQL as String
Dim iSeqVal as Integer 'The value returned

sSeqValSQL = "SELECT nextval(bed_id_seq);"
cnPGODBC.Open ("Your ODBC connection string")
Set rsSeqVal = cnPGODBC.Execute(sSeqValSQL)

iSeqVal = rsSeqVal.Fields(0)

Set rsSeqVal = Nothing
Set cnPGODBC = Nothing

Hope this helps,

Eric



Gosling, Oliver wrote:

> Does anybody know how to get the next value of a sequence?
>
> I’m presuming that nextval is an SQL procedure in postgres which can 
> be called by passing the name of the sequence as a parameter. The code 
> below shows what I’ve done in VB. This does not work however - JET 
> throws up an error saying that ‘nextval’ table or query cannot be found.
>
> Dim objCmd As New ADODB.Command
>
> Dim objPrm As ADODB.Parameter
>
> objCmd.ActiveConnection = CurrentProject.Connection
>
> objCmd.CommandType = adCmdStoredProc
>
> objCmd.CommandText = "nextval"
>
> Set objPrm = objCmd.CreateParameter("@name", adBSTR, adParamInput, , 
> "bed_id_seq")
>
> objCmd.parameters.Append objPrm
>
> Set sequenceNumber = objCmd.Execute
>
> seqNum = sequenceNumber!nextval
>
> Can anbody help me with this?
>
> Regards,
>
> Oliver Gosling
>




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

* Re: calling nextval function
@ 2004-12-06 15:37  Merlin Moncure <merlin.moncure@rcsonline.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Merlin Moncure @ 2004-12-06 15:37 UTC (permalink / raw)
  To: Eric E <whalesuit@bonbon.net>; +Cc: pgsql-odbc

> Hi Oliver,
> sSeqValSQL = "SELECT nextval(bed_id_seq);"
> cnPGODBC.Open ("Your ODBC connection string")
> Set rsSeqVal = cnPGODBC.Execute(sSeqValSQL)


I thought the sequence name had to be single quoted to the sequence
functions...can you skip that in VB?

i.e. select nextval('my_seq');

Merlin



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


end of thread, other threads:[~2004-12-06 15:37 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-12-06 15:11 calling nextval function Gosling, Oliver <o.gosling@lancaster.ac.uk>
2004-12-06 15:33 ` Eric E <whalesuit@bonbon.net>
2004-12-06 15:37 Re: calling nextval function Merlin Moncure <merlin.moncure@rcsonline.com>

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