aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2001-08-02 15:45:55 +0000
committerBruce Momjian <bruce@momjian.us>2001-08-02 15:45:55 +0000
commit84d2c518fe24e5b95b8113ff175ac5c13d2869d2 (patch)
treecb17caac17d0d944926fdb1eaefab98da5d4568c /src
parentd00b272299f1fdccfcca9c8df183f1cfc35cbb54 (diff)
downloadpostgresql-84d2c518fe24e5b95b8113ff175ac5c13d2869d2.tar.gz
postgresql-84d2c518fe24e5b95b8113ff175ac5c13d2869d2.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/pl/tcl/pltcl.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/pl/tcl/pltcl.c b/src/pl/tcl/pltcl.c
index 0f847a61bfe..3991d9dc1cf 100644
--- a/src/pl/tcl/pltcl.c
+++ b/src/pl/tcl/pltcl.c
@@ -31,7 +31,7 @@
* ENHANCEMENTS, OR MODIFICATIONS.
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.37 2001/06/09 02:19:07 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.38 2001/08/02 15:45:55 momjian Exp $
*
**********************************************************************/
@@ -144,6 +144,8 @@ static void pltcl_set_tuple_values(Tcl_Interp *interp, char *arrayname,
int tupno, HeapTuple tuple, TupleDesc tupdesc);
static void pltcl_build_tuple_argument(HeapTuple tuple, TupleDesc tupdesc,
Tcl_DString *retval);
+static int pltcl_SPI_lastoid(ClientData cdata, Tcl_Interp *interp,
+ int argc, char *argv[]);
/*
* This routine is a crock, and so is everyplace that calls it. The problem
@@ -251,7 +253,9 @@ pltcl_init_interp(Tcl_Interp *interp)
pltcl_SPI_prepare, NULL, NULL);
Tcl_CreateCommand(interp, "spi_execp",
pltcl_SPI_execp, NULL, NULL);
-
+ Tcl_CreateCommand(interp, "spi_lastoid",
+ pltcl_SPI_lastoid, NULL, NULL);
+
#ifdef ENABLE_PLTCL_UNKNOWN
/************************************************************
* Try to load the unknown procedure from pltcl_modules
@@ -2276,6 +2280,21 @@ pltcl_SPI_execp(ClientData cdata, Tcl_Interp *interp,
/**********************************************************************
+ * 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,"%u",SPI_lastoid);
+ Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ return TCL_OK;
+}
+
+
+/**********************************************************************
* pltcl_set_tuple_values() - Set variables for all attributes
* of a given tuple
**********************************************************************/