* ENHANCEMENTS, OR MODIFICATIONS.
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.64 2002/09/26 05:39:03 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.65 2002/10/14 04:20:52 momjian Exp $
*
**********************************************************************/
#include <tcl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
#include <unistd.h>
#include <fcntl.h>
-#include <string.h>
#include <setjmp.h>
#include "access/heapam.h"
************************************************************/
spi_rc = SPI_exec("select 1 from pg_class "
"where relname = 'pltcl_modules'", 1);
+ SPI_freetuptable(SPI_tuptable);
if (spi_rc != SPI_OK_SELECT)
elog(ERROR, "pltcl_init_load_unknown(): select from pg_class failed");
if (SPI_processed == 0)
if (SPI_processed == 0)
{
Tcl_DStringFree(&unknown_src);
+ SPI_freetuptable(SPI_tuptable);
elog(WARNING, "pltcl: Module unknown not found in pltcl_modules");
return;
}
}
tcl_rc = Tcl_GlobalEval(interp, Tcl_DStringValue(&unknown_src));
Tcl_DStringFree(&unknown_src);
+ SPI_freetuptable(SPI_tuptable);
}
* Build our internal proc name from the functions Oid
************************************************************/
if (!is_trigger)
- sprintf(internal_proname, "__PLTcl_proc_%u", fn_oid);
+ snprintf(internal_proname, sizeof(internal_proname),
+ "__PLTcl_proc_%u", fn_oid);
else
- sprintf(internal_proname, "__PLTcl_proc_%u_trigger", fn_oid);
+ snprintf(internal_proname, sizeof(internal_proname),
+ "__PLTcl_proc_%u_trigger", fn_oid);
/************************************************************
* Lookup the internal proc name in the hashtable
prodesc->arg_is_rel[i] = 1;
if (i > 0)
strcat(proc_internal_args, " ");
- sprintf(buf, "__PLTcl_Tup_%d", i + 1);
+ snprintf(buf, sizeof(buf), "__PLTcl_Tup_%d", i + 1);
strcat(proc_internal_args, buf);
ReleaseSysCache(typeTup);
continue;
if (i > 0)
strcat(proc_internal_args, " ");
- sprintf(buf, "%d", i + 1);
+ snprintf(buf, sizeof(buf), "%d", i + 1);
strcat(proc_internal_args, buf);
ReleaseSysCache(typeTup);
{
if (!prodesc->arg_is_rel[i])
continue;
- sprintf(buf, "array set %d $__PLTcl_Tup_%d\n", i + 1, i + 1);
+ snprintf(buf, sizeof(buf), "array set %d $__PLTcl_Tup_%d\n",
+ i + 1, i + 1);
Tcl_DStringAppend(&proc_internal_body, buf, -1);
}
}
int ntuples;
HeapTuple *volatile tuples;
volatile TupleDesc tupdesc = NULL;
+ SPITupleTable *tuptable;
sigjmp_buf save_restart;
char *usage = "syntax error - 'SPI_exec "
{
case SPI_OK_UTILITY:
Tcl_SetResult(interp, "0", TCL_VOLATILE);
+ SPI_freetuptable(SPI_tuptable);
return TCL_OK;
case SPI_OK_SELINTO:
case SPI_OK_INSERT:
case SPI_OK_DELETE:
case SPI_OK_UPDATE:
- sprintf(buf, "%d", SPI_processed);
+ snprintf(buf, sizeof(buf), "%d", SPI_processed);
Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ SPI_freetuptable(SPI_tuptable);
return TCL_OK;
case SPI_OK_SELECT:
return TCL_ERROR;
default:
- sprintf(buf, "%d", spi_rc);
+ snprintf(buf, sizeof(buf), "%d", spi_rc);
Tcl_AppendResult(interp, "pltcl: SPI_exec() failed - ",
"unknown RC ", buf, NULL);
return TCL_ERROR;
{
if (ntuples > 0)
pltcl_set_tuple_values(interp, arrayname, 0, tuples[0], tupdesc);
- sprintf(buf, "%d", ntuples);
+ snprintf(buf, sizeof(buf), "%d", ntuples);
Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ SPI_freetuptable(SPI_tuptable);
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
return TCL_OK;
}
+ tuptable = SPI_tuptable;
+
/************************************************************
* There is a loop body - process all tuples and evaluate
* the body on each
continue;
if (loop_rc == TCL_RETURN)
{
+ SPI_freetuptable(tuptable);
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
return TCL_RETURN;
}
if (loop_rc == TCL_BREAK)
break;
+ SPI_freetuptable(tuptable);
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
return TCL_ERROR;
}
+ SPI_freetuptable(tuptable);
+
/************************************************************
* Finally return the number of tuples
************************************************************/
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
- sprintf(buf, "%d", ntuples);
+ snprintf(buf, sizeof(buf), "%d", ntuples);
Tcl_SetResult(interp, buf, TCL_VOLATILE);
return TCL_OK;
}
/**********************************************************************
* pltcl_SPI_prepare() - Builtin support for prepared plans
* The Tcl command SPI_prepare
- * allways saves the plan using
+ * always saves the plan using
* SPI_saveplan and returns a key for
* access. There is no chance to prepare
* and not save the plan currently.
* Allocate the new querydesc structure
************************************************************/
qdesc = (pltcl_query_desc *) malloc(sizeof(pltcl_query_desc));
- sprintf(qdesc->qname, "%lx", (long) qdesc);
+ snprintf(qdesc->qname, sizeof(qdesc->qname), "%lx", (long) qdesc);
qdesc->nargs = nargs;
qdesc->argtypes = (Oid *) malloc(nargs * sizeof(Oid));
qdesc->arginfuncs = (FmgrInfo *) malloc(nargs * sizeof(FmgrInfo));
break;
default:
- sprintf(buf, "unknown RC %d", SPI_result);
+ snprintf(buf, sizeof(buf), "unknown RC %d", SPI_result);
reason = buf;
break;
break;
default:
- sprintf(buf, "unknown RC %d", SPI_result);
+ snprintf(buf, sizeof(buf), "unknown RC %d", SPI_result);
reason = buf;
break;
int ntuples;
HeapTuple *volatile tuples = NULL;
volatile TupleDesc tupdesc = NULL;
+ SPITupleTable *tuptable;
sigjmp_buf save_restart;
Tcl_HashTable *query_hash;
{
case SPI_OK_UTILITY:
Tcl_SetResult(interp, "0", TCL_VOLATILE);
+ SPI_freetuptable(SPI_tuptable);
return TCL_OK;
case SPI_OK_SELINTO:
case SPI_OK_INSERT:
case SPI_OK_DELETE:
case SPI_OK_UPDATE:
- sprintf(buf, "%d", SPI_processed);
+ snprintf(buf, sizeof(buf), "%d", SPI_processed);
Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ SPI_freetuptable(SPI_tuptable);
return TCL_OK;
case SPI_OK_SELECT:
return TCL_ERROR;
default:
- sprintf(buf, "%d", spi_rc);
+ snprintf(buf, sizeof(buf), "%d", spi_rc);
Tcl_AppendResult(interp, "pltcl: SPI_exec() failed - ",
"unknown RC ", buf, NULL);
return TCL_ERROR;
if (ntuples > 0)
pltcl_set_tuple_values(interp, arrayname, 0, tuples[0], tupdesc);
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
- sprintf(buf, "%d", ntuples);
+ snprintf(buf, sizeof(buf), "%d", ntuples);
Tcl_SetResult(interp, buf, TCL_VOLATILE);
+ SPI_freetuptable(SPI_tuptable);
return TCL_OK;
}
+ tuptable = SPI_tuptable;
+
/************************************************************
* There is a loop body - process all tuples and evaluate
* the body on each
continue;
if (loop_rc == TCL_RETURN)
{
+ SPI_freetuptable(tuptable);
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
return TCL_RETURN;
}
if (loop_rc == TCL_BREAK)
break;
+ SPI_freetuptable(tuptable);
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
return TCL_ERROR;
}
+ SPI_freetuptable(tuptable);
+
/************************************************************
* Finally return the number of tuples
************************************************************/
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
- sprintf(buf, "%d", ntuples);
+ snprintf(buf, sizeof(buf), "%d", ntuples);
Tcl_SetResult(interp, buf, TCL_VOLATILE);
return TCL_OK;
}
{
char buf[64];
- sprintf(buf, "%u", SPI_lastoid);
+ snprintf(buf, sizeof(buf), "%u", SPI_lastoid);
Tcl_SetResult(interp, buf, TCL_VOLATILE);
return TCL_OK;
}
{
arrptr = &arrayname;
nameptr = &attname;
- sprintf(buf, "%d", tupno);
+ snprintf(buf, sizeof(buf), "%d", tupno);
Tcl_SetVar2(interp, arrayname, ".tupno", buf, 0);
}