From 17b5bd33e415404734d9f904615a54814b80900b Mon Sep 17 00:00:00 2001 From: "Marc G. Fournier" Date: Wed, 2 Apr 1997 18:16:49 +0000 Subject: [PATCH] From: Anton de Wet Subject: [HACKERS] Small patch to pgtclCmds.c Hi I have made the following small change to the extensions I made to pgtclCmds.c quite a while ago. At the moment there is a -assignbyidx option to pg_result assigning the returned tuples to an array by using the 1st field of the select statement as the key to the array. eg "select name,age from vitalstatistics" will result in an array with myarray(peter) = 32 myarray(paul) = 45 Often I need to have a pseudo-multi dimentional array eg. "select name,age from vitalstatistics where occupation='plummer' I would like to be able to generate an array newarray(peter,overpaid) = 32 So to add a arbitrary string to the key value I have extended pg_result $res -assignbyidx $arrayname to have an optional argument pg_result $res -assignbyidx $arrayname $appendstr So that that string is appended to the key value. --- src/interfaces/libpgtcl/pgtclCmds.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/interfaces/libpgtcl/pgtclCmds.c b/src/interfaces/libpgtcl/pgtclCmds.c index 1babd8890e..6ad9ca1767 100644 --- a/src/interfaces/libpgtcl/pgtclCmds.c +++ b/src/interfaces/libpgtcl/pgtclCmds.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.12 1997/01/23 19:47:18 scrappy Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.13 1997/04/02 18:16:49 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -437,8 +437,10 @@ Pg_exec(ClientData cData, Tcl_Interp *interp, int argc, char* argv[]) the connection that produced the result -assign arrayName assign the results to an array - -assignbyidx arrayName + -assignbyidx arrayName ?appendstr? assign the results to an array using the first field as a key + optional appendstr append that string to the key name. Usefull for + creating pseudo-multi dimentional arrays in tcl. -numTuples the number of tuples in the query -attributes @@ -462,9 +464,10 @@ Pg_result(ClientData cData, Tcl_Interp *interp, int argc, char* argv[]) int tupno; char prearrayInd[MAX_MESSAGE_LEN]; char arrayInd[MAX_MESSAGE_LEN]; + char *appendstr; char *arrVar; - if (argc != 3 && argc != 4) { + if (argc != 3 && argc != 4 && argc != 5) { Tcl_AppendResult(interp, "Wrong # of arguments\n",0); goto Pg_result_errReturn; } @@ -523,18 +526,24 @@ Pg_result(ClientData cData, Tcl_Interp *interp, int argc, char* argv[]) return TCL_OK; } else if (strcmp(opt, "-assignbyidx") == 0) { - if (argc != 4) { - Tcl_AppendResult(interp, "-assignbyidx option must be followed by a variable name",0); + if (argc !=4 && argc != 5) { + Tcl_AppendResult(interp, "-assignbyidx requires the array name and takes one optional argument as an append string",0); return TCL_ERROR; } arrVar = argv[3]; /* this assignment assigns the table of result tuples into a giant array with the name given in the argument, the indices of the array or (tupno,attrName)*/ + if (argc == 5) { + appendstr = argv[4]; + } else { + appendstr = ""; + } for (tupno = 0; tupno