7
7
*
8
8
*
9
9
* 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 $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -194,6 +194,8 @@ Pg_exec(AlientData cData, Tcl_Interp *interp, int argc, char* argv[])
194
194
the connection that produced the result
195
195
-assign arrayName
196
196
assign the results to an array
197
+ -assignbyidx arrayName
198
+ assign the results to an array using the first field as a key
197
199
-numTuples
198
200
the number of tuples in the query
199
201
-attributes
@@ -211,6 +213,7 @@ Pg_result(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
211
213
char * opt ;
212
214
int i ;
213
215
int tupno ;
216
+ char prearrayInd [MAX_MESSAGE_LEN ];
214
217
char arrayInd [MAX_MESSAGE_LEN ];
215
218
char * arrVar ;
216
219
@@ -268,6 +271,27 @@ Pg_result(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
268
271
Tcl_AppendResult (interp , arrVar , 0 );
269
272
return TCL_OK ;
270
273
}
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
+ }
271
295
else if (strcmp (opt , "-getTuple" ) == 0 ) {
272
296
if (argc != 4 ) {
273
297
Tcl_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[])
307
331
"\t-status\n" ,
308
332
"\t-conn\n" ,
309
333
"\t-assign arrayVarName\n" ,
334
+ "\t-assignbyidx arrayVarName\n" ,
310
335
"\t-numTuples\n" ,
311
336
"\t-attributes\n"
312
337
"\t-getTuple tupleNumber\n" ,
0 commit comments