Overview
| Artifact ID: | 4512ce1983a0a9efd905e7be649f1113484bd2fd95cfa68347884ae82c69321f |
|---|---|
| Ticket: | 93c149626935bb9c7e4d7b727af6a0192b5a59a8
tdbc::odbc resultset foreach needs an option to allow empty values |
| User & Date: | willbprog2762 on 2021-04-08 05:22:15 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/html"
- comment changed to:
<p>Running on Windows 10 Pro 64-bit Build 19042</p> <p>While writing a Tcl script to export MS Access tables to CSV files, I was using the <code>tdbc::odbc</code> package along with the system Access driver in 64-bit mode.</p> <p>As mentioned in the documentation for <code>tdbc::resultset nextdict</code> (which <code>foreach</code> uses): <blockquote><em>"If a column's value in the row is NULL, its key is omitted from the dictionary."</em></blockquote> Unfortunately I didn't see this detail until I had finished writing the bulk of my code. Because the key and value both are missing from the resultset dictionary when the value is NULL, this leaves unwanted missing fields in the CSV output when using something like this (untested concept code): </p> <pre> set f [open "c:/users/will/desktop/table-dump.csv" "w"] $resultset foreach row { foreach {key value} $row { puts -nonewline $f "$key," puts $f "$value" } } ... </pre> <p> I worked around this issue by using a <code>nextlist</code> with <code>while</code> and more complicated support code, but I feel this shouldn't have been necessary. If the <code>$resultset foreach</code> had an <code>-emptystringsfornulls</code> (or some other better-named) option that would allow the key to remain in the dictionary, but with an empty string as a value, this would have allowed me to use my simple <code>$resultset foreach</code> code without outputing missing keys. - foundin changed to: "8.6.10"
- is_private changed to: "0"
- login: "willbprog2762"
- priority changed to: "5 Medium"
- private_contact changed to: "937334650b1c1edd786dc48f2296354a1a36004a"
- resolution changed to: "None"
- severity changed to: "Minor"
- status changed to: "Open"
- submitter changed to: "willbprog2762"
- subsystem changed to: "81. Bundled Packages"
- title changed to:
tdbc::odbc resultset foreach needs an option to allow empty values
- type changed to: "RFE"