77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.1.1.1 1996/07/09 06:22:16 scrappy Exp $
10+ * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.2 1996/07/23 03:38:44 scrappy Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -194,6 +194,8 @@ Pg_exec(AlientData cData, Tcl_Interp *interp, int argc, char* argv[])
194194 the connection that produced the result
195195 -assign arrayName
196196 assign the results to an array
197+ -assignbyidx arrayName
198+ assign the results to an array using the first field as a key
197199 -numTuples
198200 the number of tuples in the query
199201 -attributes
@@ -211,6 +213,7 @@ Pg_result(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
211213char * opt ;
212214int i ;
213215int tupno ;
216+ char prearrayInd [MAX_MESSAGE_LEN ];
214217char arrayInd [MAX_MESSAGE_LEN ];
215218char * arrVar ;
216219
@@ -268,6 +271,27 @@ Pg_result(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
268271Tcl_AppendResult (interp ,arrVar ,0 );
269272return TCL_OK ;
270273 }
274+ else if (strcmp (opt ,"-assignbyidx" )== 0 ) {
275+ if (argc != 4 ) {
276+ Tcl_AppendResult (interp ,"-assignbyidx option must be followed by a variable name" ,0 );
277+ return TCL_ERROR ;
278+ }
279+ arrVar = argv [3 ];
280+ /* this assignment assigns the table of result tuples into a giant
281+ array with the name given in the argument,
282+ the indices of the array or (tupno,attrName)*/
283+ for (tupno = 0 ;tupno < PQntuples (result );tupno ++ ) {
284+ sprintf (prearrayInd ,"%s" ,PQgetvalue (result ,tupno ,0 ));
285+ for (i = 1 ;i < PQnfields (result );i ++ ) {
286+ sprintf (arrayInd ,"%s,%s" ,prearrayInd ,PQfname (result ,i ));
287+ Tcl_SetVar2 (interp ,arrVar ,arrayInd ,
288+ PQgetvalue (result ,tupno ,i ),
289+ TCL_LEAVE_ERR_MSG );
290+ }
291+ }
292+ Tcl_AppendResult (interp ,arrVar ,0 );
293+ return TCL_OK ;
294+ }
271295else if (strcmp (opt ,"-getTuple" )== 0 ) {
272296if (argc != 4 ) {
273297Tcl_AppendResult (interp ,"-getTuple option must be followed by a tuple number" ,0 );
@@ -307,6 +331,7 @@ Pg_result(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
307331"\t-status\n" ,
308332"\t-conn\n" ,
309333"\t-assign arrayVarName\n" ,
334+ "\t-assignbyidx arrayVarName\n" ,
310335"\t-numTuples\n" ,
311336"\t-attributes\n"
312337"\t-getTuple tupleNumber\n" ,