Note: This is a message thread from the old pgfoundry.org forum for pgtclng.
Back to pgtclng home page
Back to archived forum page
By: Siqsuruq Siqsuruq pg_result on windows question 2011-03-18 01:25 |
Hi, first of all I want to thank you for this great package. My question is. Im developing multi platform application, and get some problems with -dict switch on windows (I think its experimental swich, but it really cool), my app. give me message: bad switch "-dict": must be -status, -error, -errorField, -conn, -oid, -numTuples, -cmdTuples, -numAttrs, -assign, -assignbyidx, -getTuple, -tupleArray, -attributes, -lAttributes, -lxAttributes, -clear, -list, -llist, -getNull, -cmdStatus, -numParams, or -paramTypes while executing "pg_result $res -dict" But the same code working fine on my Slack box, both of them have ActiveState 8.6 installed with dict support. Sorry if I missed smth and my english. |
By: Siqsuruq Siqsuruq RE: pg_result on windows question 2011-03-18 12:49 |
Today Ive compiled lib from source on windows, but the same result. There is some way to get dict from pg_result or I have to remake my code? |
By: L J Bayuk RE: pg_result on windows question 2011-03-18 16:58 |
Hello, sorry for the confusion. There are 3 different implementations of the Pgtcl interface to PostgreSQL. Two of them (pgtclng and the pure-Tcl version pgintcl) are developed by me. The third one is called "pgtcl" and is developed by others. All 3 can be found on pgfoundry.org. After the split-up a number of years ago, "pgtcl" and my two have diverged, and only the core commands and options are compatible. The feature you are asking about, pg_result -dict, has never been implemented in pgtclng nor pgin.tcl. I think it was implemented in "pgtcl" but I do not track their development. |
By: Siqsuruq Siqsuruq RE: pg_result on windows question 2011-03-19 00:21 |
Thank you for your answer. Ok, my bad about names :) I did changes in my code, also now im using your package pgtclng 1.8, but now I have another problem. My slack box working fine, windows also, but there is a huge difference between showing result on linux box and windows, I have only 38 rows in my table. Im using pg_result with llist. Here is the code (now I have no idea whats going on) set result [pg_result $res -llist] pg_result $res -clear my llist_to_dict $result [my select_columns_names $table] And method to make dict from llist: method llist_to_dict {vllist columnslist} { set result [dict create] set vllist_size [llength $vllist] for {set i 0} {$i < $vllist_size} {incr i} { set templist {} set a [lindex $vllist $i] for {set s 0} {$s < [llength $a]} {incr s} { lappend templist [lindex $columnslist $s] lappend templist [lindex $a $s] } dict set result $i $templist } return $result } Can you tell me please, if it smth wrong with my code or its specific to platform or smth? Thank you. |
By: Siqsuruq Siqsuruq RE: pg_result on windows question 2011-03-19 00:56 |
Ive tried pgintcl, same result. Slow on windows fast on linux, so it has to be my code somehow. Bill Gates hates me :( |
By: L J Bayuk RE: pg_result on windows question 2011-03-19 01:38 |
I'm not completely clear on your code, confused a little by "method" (is this a form of "proc"?) and "my" (why are you not saving the return result from llist_to_dict?), and I guess select_columns_names gets you a list of table column names (but what I think you really want is query field names, which you can get from pg_result -attributes). Aside from that, it seems to convert the -llist result to a dictionary OK. It doesn't actually create a nested dictionary, like "pgtcl" does, but the result is the same with your dictionary of lists. So no, I don't see anything wrong with your function, nor are there any platform issues I know of - and I do test on both Windows and Linux (Slackware, in fact). So let's make sure you are running the versions you think on both systems, and also can you provide more details about how the results differ? By the way, I think I'm going to add pg_result -dict to both pgtclng and pgintcl. Oh, and here is my version of your llist_to_dict. I think it is cleaner, and I will be using something like it in pgintcl. (Unfortunately this forum messes with the indents.) proc llist_to_dict2 {vllist columnslist} { set result [dict create] set rownum 0 foreach row $vllist { foreach fieldname $columnslist value $row { dict set result $rownum $fieldname $value } incr rownum } return $result } |
By: Siqsuruq Siqsuruq RE: pg_result on windows question 2011-03-19 13:04 |
Method is a just a proc from my class. I have a little class, which creates queries execute them and send back a result (normally dict) to my xml wrapper. Xml wrapper just convert dictionaries to forms, like data entries ,tables, dropdowns, spinboxes etc. I found problem in my code after timing my code, it was just "puts $result" in my xml wrapper. On linux im running my app from terminal, on windows just clicking on it :) Thank you for your version of llist_to_dict2 proc. So i did proc for your pgintcl :), its lamsy but working -dict { set my_dict [dict create] set columnslist $result(attrs) for {set irow 0} {$irow < $ntuple} {incr irow} { set my_list {} for {set icol 0} {$icol < $nattr} {incr icol} { lappend my_list [lindex $columnslist $icol] $result($irow,$icol) } dict set my_dict $irow $my_list } return $my_dict } Just insert in pgin.tcl on line 850. Thank you again |
By: L J Bayuk RE: pg_result on windows question 2011-03-19 15:54 |
OK, good that you found the problem. Thanks, but I coded pg_result -dict for pgin.tcl last night, a little different from yours (I prefer to avoid lindex and use loops over lists). Also I still support Tcl8.4 which has no dicts, so it has to fail with a reasonable error. That is the easy part, so I do that first. I still need to write tests for it, code it in pgtclng, and update the manual. |
By: Nobody RE: pg_result on windows question 2011-03-19 18:29 |
Ok, good luck :) If you need some help sometimes, just ask. |
By: L J Bayuk RE: pg_result on windows question 2011-03-21 14:25 |
FYI, I have now implemented pg_result -dict for both pgtclng and pgintcl. New tests for this are done, and the manual is updated. There is still a problem with Tcl versions (if I build on Tcl8.5 and run with Tcl8.4 it crashes in this new function, and I would rather it failed with an error). Also I need to do the full testing on Windows and Linux with different Tcl and PostgreSQL versions. I expect to have new releases soon, perhaps today or tomorrow. |