tcl - 如何在画布上将 sqlite3 查询结果打印为矩阵?
问题描述
我想将 sqlite3 查询的结果以矩阵的形式放置并打印在 tk 画布上。该查询从数据库中返回一个表的三列。有人可以帮忙吗?
解决方案
与其使用画布,不如使用 tktable。绘制线条和将项目格式化为列的所有工作都已完成。
#!/usr/bin/tclsh
# We need these otherwise it will not work
package require sqlite3
package require Tktable
# open database - in this case stockbox.db in the current directory
sqlite3 db stockbox.db
# Set up the titles
set models(0,0) "Model"
set models(0,1) "Width"
set models(0,2) "Length"
# Start with 1 for the title
set rows 1
set cols 3
# Perform query, extract result into models
db eval {SELECT model_id,width, length FROM tbl_model} {
set models($rows,0) $model_id
set models($rows,1) $width
set models($rows,2) $length
incr rows
}
db close
# Create the table
table .table -variable models -titlerows 1 -width $cols -height 10 -rows $rows -yscrollcommand ".ys set"
scrollbar .ys -command ".table yview"
pack .table .ys -side left -fill y
推荐阅读
- variables - 可以为不同的补丁“记录”乌龟变量吗?
- java - 即使我禁用 Facebook 分析,Facebook 是否会跟踪我的应用程序事件?
- docker - 如何为 Kafka 本地开发配置 docker-compose.yml?
- mysql - 如何像这样从三个表中查询
- c++ - C++ 在 Windows Vista 操作系统上验证 directx 的版本
- ios - WKWebView 没有填充容器视图
- apache-spark - 火花数据框左外连接需要很多时间
- javascript - 使用 wkhtmltopdf 将 D3 图表转换为 pdf
- idris - 如何改写:Vect (S (S (n + m))) a -> Vect (S (plus n (S m))) a
- ruby - 如何为 Dry::Validation.Params 方案设置默认值?