Skip site navigation (1) Skip section navigation (2)

pltcl - lastoid

From: bob(at)redivi(dot)com
To: pgsql-hackers(at)postgresql(dot)org
Subject: pltcl - lastoid
Date: 2001-07-27 02:31:22
Message-ID: 20010726223122.A300@redivi.com (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
I noticed that pltcl didn't have any way to get to SPI_lastoid like plpgsql does.. I started using pltcl a lot because I like to decide when and how my queries get planned.. so I put one together really quick

Sorry I don't have the original around to make a quick diff, but its a very small change... I think this should be in the next release, there's no reason not to have it.

its a function with no expected arguments, so you can use it like:
spi_exec "INSERT INTO mytable(columns...) VALUES(values..)"
set oid [spi_lastoid]
spi_exec "SELECT mytable_id from mytable WHERE oid=$oid"

It just didn't make sense for me to use plpgsql and pltcl, or just screw them both and use SPI from C

these changes are for src/pl/tcl/pltcl.c

/* start C code */

/* forward declaration */
static int pltcl_SPI_lastoid(ClientData cdata, Tcl_Interp *interp,
      int argc, char *argv[]);

/* this needs to go in in pltcl_init_interp with the rest of 'em */
        Tcl_CreateCommand(interp, "spi_lastoid",
                                          pltcl_SPI_lastoid, NULL, NULL);
                                  
                                                  
/**********************************************************************
 * pltcl_SPI_lastoid()  - return the last oid. To
 *        be used after insert queries
 **********************************************************************/
static int
pltcl_SPI_lastoid(ClientData cdata, Tcl_Interp *interp,
      int argc, char *argv[])
{
  char buf[64];
  sprintf(buf,"%d",SPI_lastoid);
  Tcl_SetResult(interp, buf, TCL_VOLATILE);
  return TCL_OK;
}

/* end C code */

-bob

Responses

pgsql-hackers by date

Next:From: Dominic J. EidsonDate: 2001-07-27 03:41:03
Subject: Re: Failed compile PostgreSQL 7.1.2 on AIX 5.1
Previous:From: Philip WarnerDate: 2001-07-27 02:18:56
Subject: Re: Bad timestamp external representation

pgsql-patches by date

Next:From: Jason TishlerDate: 2001-07-27 17:56:08
Subject: Re: libpq.dll (resend)
Previous:From: Bruce MomjianDate: 2001-07-26 21:48:13
Subject: Re: Revised Patch to allow multiple table locks in "Unison"

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group