From: Anton de Wet Date: Mon, 18 Mar 1996 10:14:53 +0200 (GMT+0200) Subject: Re: [PG95]: Assigning to arrays with libpgtcl On Sat, 16 Mar 1996, Jesus Chrysler wrote: > I found that when I assign a result of a pg_exec to an array, I get odd > results: > > (by the way, dragnet is a tcl/tclx/pgtcl shell I made) > > dragnet>set result [pg_exec $db "SELECT * FROM account_info WHERE login = > 'jchryslr'"] > dragnet>pg_result $result -assign Row(user) > Row(user) > dragnet>array names Row > dragnet>array names Row(user) > 0,name 0,address 0,telephone > so.... I'm thinking that when an array is given as the argument, it should be > added to the array, so that in this case the variable Row(user,0,name) should > have been created? I've had a similar problem. All my tables have a unique (enforced by external programs) field called idnr. I wanted to be able to assign the result to a array and use the first field returned (idnr in my case) to be used as the first index of the array. I've made a quick hack to pgtclCmds.c to add an option to pg_result (which I called -assignbyidx) to do this. To use it, (for example) dragnet> set result [pg_exec $db "SELECT user, passwd, shell FROM account_info WHERE login ='myname'] dragnet> pg_result $result -assignbyidx Row And you should have dragnet> array names Row user,passwd user,shell Hope this helps Anton Here is the patch: (to pgtclCmds.c) - -------------------------------Cut-here---------------------------------------- 197,198d196 < -assignbyidx arrayName < assign the results to an array using the first field as a key 216d213 < char prearrayInd[MAX_MESSAGE_LEN]; 274,294d270 < else if (strcmp(opt, "-assignbyidx") == 0) { < if (argc != 4) { < Tcl_AppendResult(interp, "-assignbyidx option must be followed by a variable name",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)*/ < for (tupno = 0; tupno