Skip to content

Commit 84d2c51

Browse files
committed
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. bob@redivi.com
1 parent d00b272 commit 84d2c51

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

doc/src/sgml/pltcl.sgml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/pltcl.sgml,v 2.11 2001/06/09 02:19:07 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/pltcl.sgml,v 2.12 2001/08/02 15:45:55 momjian Exp $
33
-->
44

55
<chapter id="pltcl">
@@ -394,6 +394,18 @@ CREATE TRIGGER trig_mytab_modcount BEFORE INSERT OR UPDATE ON mytab
394394
</listitem>
395395
</varlistentry>
396396

397+
<varlistentry>
398+
<indexterm>
399+
<primary>spi_lastoid</primary>
400+
</indexterm>
401+
<term>spi_lastoid</term>
402+
<listitem>
403+
<para>
404+
Returns the OID of the last query if it was an INSERT.
405+
</para>
406+
</listitem>
407+
</varlistentry>
408+
397409
<varlistentry>
398410
<term>spi_exec ?-count <replaceable>n</replaceable>? ?-array <replaceable>name</replaceable>? <replaceable>query</replaceable> ?<replaceable>loop-body</replaceable>?</term>
399411
<listitem>

src/pl/tcl/pltcl.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* ENHANCEMENTS, OR MODIFICATIONS.
3232
*
3333
* IDENTIFICATION
34-
* $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.37 2001/06/09 02:19:07 tgl Exp $
34+
* $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.38 2001/08/02 15:45:55 momjian Exp $
3535
*
3636
**********************************************************************/
3737

@@ -144,6 +144,8 @@ static void pltcl_set_tuple_values(Tcl_Interp *interp, char *arrayname,
144144
int tupno, HeapTuple tuple, TupleDesc tupdesc);
145145
static void pltcl_build_tuple_argument(HeapTuple tuple, TupleDesc tupdesc,
146146
Tcl_DString *retval);
147+
static int pltcl_SPI_lastoid(ClientData cdata, Tcl_Interp *interp,
148+
int argc, char *argv[]);
147149

148150
/*
149151
* This routine is a crock, and so is everyplace that calls it. The problem
@@ -251,7 +253,9 @@ pltcl_init_interp(Tcl_Interp *interp)
251253
pltcl_SPI_prepare, NULL, NULL);
252254
Tcl_CreateCommand(interp, "spi_execp",
253255
pltcl_SPI_execp, NULL, NULL);
254-
256+
Tcl_CreateCommand(interp, "spi_lastoid",
257+
pltcl_SPI_lastoid, NULL, NULL);
258+
255259
#ifdef ENABLE_PLTCL_UNKNOWN
256260
/************************************************************
257261
* Try to load the unknown procedure from pltcl_modules
@@ -2275,6 +2279,21 @@ pltcl_SPI_execp(ClientData cdata, Tcl_Interp *interp,
22752279
}
22762280

22772281

2282+
/**********************************************************************
2283+
* pltcl_SPI_lastoid() - return the last oid. To
2284+
* be used after insert queries
2285+
**********************************************************************/
2286+
static int
2287+
pltcl_SPI_lastoid(ClientData cdata, Tcl_Interp *interp,
2288+
int argc, char *argv[])
2289+
{
2290+
char buf[64];
2291+
sprintf(buf,"%u",SPI_lastoid);
2292+
Tcl_SetResult(interp, buf, TCL_VOLATILE);
2293+
return TCL_OK;
2294+
}
2295+
2296+
22782297
/**********************************************************************
22792298
* pltcl_set_tuple_values() - Set variables for all attributes
22802299
* of a given tuple

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy