77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.38 1998/10/14 15:17:51 tgl Exp $
10+ * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.39 1999/01/17 21:12:55 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -472,39 +472,50 @@ Pg_exec(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
472472 get information about the results of a query
473473
474474 syntax:
475- pg_result result ?option?
475+
476+ pg_result result ?option?
476477
477478 the options are:
478- -status
479- the status of the result
480- -error
481- the error message, if the status indicates error; otherwise an empty string
482- -conn
483- the connection that produced the result
484- -oid
485- if command was an INSERT, the OID of the inserted tuple
486- -numTuples
487- the number of tuples in the query
488- -numAttrs
489- returns the number of attributes returned by the query
490- -assign arrayName
491- assign the results to an array, using subscripts of the form
492- (tupno,attributeName)
493- -assignbyidx arrayName ?appendstr?
494- assign the results to an array using the first field's value as a key.
495- All but the first field of each tuple are stored, using subscripts of the form
496- (field0value,attributeNameappendstr)
497- -getTuple tupleNumber
498- returns the values of the tuple in a list
499- -tupleArray tupleNumber arrayName
500- stores the values of the tuple in array arrayName, indexed
501- by the attributes returned
502- -attributes
503- returns a list of the name/type pairs of the tuple attributes
504- -lAttributes
505- returns a list of the {name type len} entries of the tuple attributes
506- -clear
507- clear the result buffer. Do not reuse after this
479+
480+ -statusthe status of the result
481+
482+ -errorthe error message, if the status indicates error; otherwise
483+ an empty string
484+
485+ -connthe connection that produced the result
486+
487+ -oidif command was an INSERT, the OID of the inserted tuple
488+
489+ -numTuplesthe number of tuples in the query
490+
491+ -numAttrsreturns the number of attributes returned by the query
492+
493+ -assign arrayName
494+ assign the results to an array, using subscripts of the form
495+ (tupno,attributeName)
496+
497+ -assignbyidx arrayName ?appendstr?
498+ assign the results to an array using the first field's value
499+ as a key.
500+ All but the first field of each tuple are stored, using
501+ subscripts of the form (field0value,attributeNameappendstr)
502+
503+ -getTuple tupleNumber
504+ returns the values of the tuple in a list
505+
506+ -tupleArray tupleNumber arrayName
507+ stores the values of the tuple in array arrayName, indexed
508+ by the attributes returned
509+
510+ -attributes
511+ returns a list of the name/type pairs of the tuple attributes
512+
513+ -lAttributes
514+ returns a list of the {name type len} entries of the tuple
515+ attributes
516+
517+ -clearclear the result buffer. Do not reuse after this
518+
508519 **********************************/
509520int
510521Pg_result (ClientData cData ,Tcl_Interp * interp ,int argc ,char * argv [])
@@ -621,15 +632,24 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
621632 */
622633for (tupno = 0 ;tupno < PQntuples (result );tupno ++ )
623634{
624- const char * field0 = PQgetvalue (result ,tupno ,0 );
625- char * workspace = malloc (strlen (field0 )+ strlen (appendstr )+ 210 );
635+ const char * field0 =
636+ #ifdef TCL_ARRAYS
637+ tcl_value (PQgetvalue (result ,tupno ,0 ));
638+ #else
639+ PQgetvalue (result ,tupno ,0 );
640+ #endif
641+ char * workspace = malloc (strlen (field0 )+ strlen (appendstr )+ 210 );
626642
627643for (i = 1 ;i < PQnfields (result );i ++ )
628644{
629645sprintf (workspace ,"%s,%.200s%s" ,field0 ,PQfname (result ,i ),
630646appendstr );
631647if (Tcl_SetVar2 (interp ,arrVar ,workspace ,
648+ #ifdef TCL_ARRAYS
649+ tcl_value (PQgetvalue (result ,tupno ,i )),
650+ #else
632651PQgetvalue (result ,tupno ,i ),
652+ #endif
633653TCL_LEAVE_ERR_MSG )== NULL )
634654{
635655free (workspace );
@@ -654,8 +674,15 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
654674Tcl_AppendResult (interp ,"argument to getTuple cannot exceed number of tuples - 1" ,0 );
655675return TCL_ERROR ;
656676}
677+ #ifdef TCL_ARRAYS
678+ for (i = 0 ;i < PQnfields (result );i ++ )
679+ {
680+ Tcl_AppendElement (interp ,tcl_value (PQgetvalue (result ,tupno ,i )));
681+ }
682+ #else
657683for (i = 0 ;i < PQnfields (result );i ++ )
658684Tcl_AppendElement (interp ,PQgetvalue (result ,tupno ,i ));
685+ #endif
659686return TCL_OK ;
660687}
661688else if (strcmp (opt ,"-tupleArray" )== 0 )
@@ -674,7 +701,11 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
674701for (i = 0 ;i < PQnfields (result );i ++ )
675702{
676703if (Tcl_SetVar2 (interp ,argv [4 ],PQfname (result ,i ),
704+ #ifdef TCL_ARRAYS
705+ tcl_value (PQgetvalue (result ,tupno ,i )),
706+ #else
677707PQgetvalue (result ,tupno ,i ),
708+ #endif
678709TCL_LEAVE_ERR_MSG )== NULL )
679710return TCL_ERROR ;
680711}
@@ -1302,7 +1333,13 @@ Pg_select(ClientData cData, Tcl_Interp * interp, int argc, char **argv)
13021333Tcl_SetVar2 (interp ,argv [3 ],".tupno" ,buffer ,0 );
13031334
13041335for (column = 0 ;column < ncols ;column ++ )
1305- Tcl_SetVar2 (interp ,argv [3 ],info [column ].cname ,PQgetvalue (result ,tupno ,column ),0 );
1336+ Tcl_SetVar2 (interp ,argv [3 ],info [column ].cname ,
1337+ #ifdef TCL_ARRAYS
1338+ tcl_value (PQgetvalue (result ,tupno ,column )),
1339+ #else
1340+ PQgetvalue (result ,tupno ,column ),
1341+ #endif
1342+ 0 );
13061343
13071344Tcl_SetVar2 (interp ,argv [3 ],".command" ,"update" ,0 );
13081345