2024-03-01

Tcl/Tk 8.6.14

Tcl/Tk 8.6.14 已經釋出,比較重大的改變可以參考 Changes in Tcl/Tk 8.6.14

Tcl Changes

  • TIP 402: Path normalization revised so UNC path support is cross platform
  • Interpretation of ~ in paths made cross platform.
  • Decoding of incomplete code UTF code sequences generates replacement character
  • Restore [exec %var%\] on Windows
  • Allow [char create {} \$cmd\].
  • Improved handling of non-BMP pathnames on Windows.

Tk Changes

  • Revise number parsing to match that of Tcl.
  • Iconlist ignores the options database entry for foreground text color
  • menu clone bindings corrected
  • Enable treeview display of partial final line
  • Allow return from [tk scaling\] in safe interp
  • Prevent exposure of clues to masked entry contents by navigation bindings

2024-02-27

Ffidl v0.9

Ffidl


後來我發現,openSUSE 的 devel:languages:tcl 上有 Ffidl 這個套件,只是沒有更新到後續維護的版本,所以我發了 一個 request,更新 devel:languages:tcl 上套件到最近的版本,如果被接受,就會刪除我自己的部份。

2024-01-23

List ODBC data sources

這是一個簡單的程式,列出目前環境中 ODBC 的 data sources。

#!/usr/bin/env tclsh

#
# A simple program to list ODBC Data Sources by Tcl/Tk, version 0.1
#

package require Tcl 8.6
package require Tk
package require tablelist
package require tdbc::odbc

if { [catch {package require awthemes}]==0} {
    ttk::setTheme "awlight"
}

wm geometry . 600x400+100+100

frame .menubar -relief raised -bd 2
pack .menubar -side top -fill x

ttk::menubutton .menubar.file -text File -menu .menubar.file.menu
menu .menubar.file.menu -tearoff 0
.menubar.file.menu add command -label Quit -command Exit
ttk::menubutton .menubar.help -text Help -menu .menubar.help.menu
menu .menubar.help.menu -tearoff 0
.menubar.help.menu add command -label About -command HelpAbout
pack .menubar.file .menubar.help -side left

# Contextual Menus
menu .menu
foreach i [list Exit] {
    .menu add command -label $i -command $i
}

if {[tk windowingsystem]=="aqua"} {
    bind . <2> "tk_popup .menu %X %Y"
    bind . <Control-1> "tk_popup .menu %X %Y"
} else {
    bind . <3> "tk_popup .menu %X %Y"
}

# Get data sources list and list
tablelist::tablelist .t -columns {0 "DSN" 0 "Driver"} -stretch all \
    -background white -font {Helvetica -14}
pack .t -fill both -expand 1 -side top
set sources [::tdbc::odbc::datasources]
foreach {dsn driver} $sources {
   .t insert end [list $dsn $driver]
}

# Handle special key
bind all <F1> HelpAbout

#=================================================================
# Event Handler
#=================================================================

proc Exit {} {
    set answer [tk_messageBox -message "Really quit?" -type yesno -icon warning]
    switch -- $answer {
        yes exit
    }
}

proc HelpAbout {} {
    set ans [tk_messageBox -title "About" -type ok -message \
    "Using TDBC-ODBC to list ODBC Data Sources." ]
}

2024-01-21

RSS to HTML

下面的程式使用 TclCurl 自網站下載 RSS XML 的資料, 下載以後使用 tDom 分析並且將 title 與 link 的資料儲存為 html 格式。

#!/usr/bin/env tclsh

package require TclCurl
package require tdom

proc get_rss {url} {
    try {
        set curlHandle [curl::init]
        $curlHandle configure -url $url -bodyvar result
        $curlHandle setopt CURLOPT_HTTP_VERSION 2TLS

        catch { $curlHandle perform } curlErrorNumber
        if { $curlErrorNumber != 0 } {
            throw error [curl::easystrerror $curlErrorNumber]
        }
    } on error {em} {
        error "Error: $em"
    } finally {
       $curlHandle cleanup
    }

    return $result
}

proc parse {XML ofname} {
    set doc [dom parse $XML]
    set root [$doc documentElement]
    set titleList [$root selectNodes //item/title]
    set linkList [$root selectNodes //item/link]

    set out [open $ofname w 0666]
    foreach tnode $titleList lnode $linkList {
        set ntitle [$tnode text]
        set nlink [$lnode text]
        puts $out "<a href=\"$nlink\">$ntitle</a><br>"
    }
    close $out
}

if {$argc == 2} {
    set url [lindex $argv 0]
    set ofile [lindex $argv 1]
} else {
    puts "Usage:"
    puts "\ttclsh rss2html.tcl url filename"
    exit
}

if {[catch {set data [get_rss $url]} err]} {
    puts $err
} else {
    parse $data $ofile
}

2023-12-25

unixODBC isql

unixODBC 提供了 isql 這個命令列工具。要注意的是,有不少資料庫的命令列工具也取名為 isql,使用前應該先使用下列的指令確定:

isql --version

下面是指令的參數:

isql DSN [USER [PASSWORD]] [options]

下面的範例是使用 DSN=PostgreSQL 查詢資料庫版本,並且輸出為 html 的例子:

echo "select version() as version" | isql PostgreSQL -b -w > result.html

(-b 代表不要 interactive mode,而 -w 代表輸出 html table 結果。)

然後接下來撰寫一個 Tcl 程式測試:

#!/usr/bin/env tclsh
if {$argc >= 1} {
    set statement [lindex $argv 0]
} elseif {$argc == 0} {
    puts "Please input a SQL statement"
    exit
}

set var [list echo $statement | isql PostgreSQL -b -w > result.html]
exec {*}$var

2023-11-30

tcl-monetdbe v0.2.0

 tcl-monetdbe


Tcl extension and TDBC driver for MonetDB Embedded.

MonetDB Embedded (MonetDB/e) 已經出現了一段時間,是 MonetDB 的 embedded solution。因為 MonetDB 我只是用來測試一些想法,所以之前一直沒有使用 MonetDB/e 的場合。

不過因為電腦上有裝 MonetDB 而且我也有安裝 MonetDB embedded library,所以考慮了一下,最近嘗試寫一個 Tcl extension 測試看看使用的情況。

2023-11-23

tdbc::mysql

最近我在整理自己的作業環境,這才發現 libmariadb-devel 對於 tdbc::mysql 而言是非必要的(以前因為 so suffixes 的關係需要裝,但是其實 tdbc::mysql 已經修正了,只是我沒注意到)。下面就是目前的 code:

static const char *const mysqlStubLibNames[] = {
    /* @LIBNAMES@: DO NOT EDIT THESE NAMES */
    "mariadbclient", "mariadb", "mysqlclient_r", "mysqlclient", "mysql", NULL
    /* @END@ */
};

/* ABI Version numbers of the MySQL API that we can cope with */

static const char mysqlSuffixes[][4] = {
    "", ".3", ".21", ".20", ".19", ".18", ".17", ".16", ".15"
};

如果說 MariaDB 是為了防止 Oracle 更改 MySQL 的授權而成立的,可是那為什麼 Michael Widenius 除了基金會,還又成立了一家企業?嘴上說我不是要用 MySQL 或者是 MariaDB 賺錢,實際上的行為卻完全相反,這是一個與說法衝突的行為(還可以參考 Uproar: MariaDB Corp. veers away from open source)。如果採用 MySQL 是被騙第一次,那 MariaDB 被騙第二次的人就應該要自我檢討了。我是說如果你擔心 Oracle 會對 MySQL 做出什麼損壞開放原始碼的事情,那麼 Michael Widenius 也可以重施故技,又賣掉 MariaDB 企業或者是上市賺取利益。

也就是說,我不認為應該要採用 MySQL 或者是 MariaDB。當然不是所有人都可以直接切換到其它的資料庫,這個時候可以考慮採用 MySQL protocol 並且高度相容的其它資料庫,在這個情況下,client 端的 source code 的變動理論上要很少,而 server 端則是換掉 MySQL 或者是 MariaDB,採用其它相容方案的資料庫。

在這個情況下,MySQL/MariaDB client API 是很重要的,而又剛好 MySQL/MariaDB client API 極大多數是 LGPL 或者是較為寬鬆的條款,只要採用動態連結的使用方式就可以在商業環境下使用,所以保留 MySQL/MariaDB client library,然後從MySQL 或者是 MariaDB 遷移出去。 

不過如果是因為學習 LAMP 架構而需要安裝一個資料庫,或者是撰寫開放原始碼的軟體,那麼 MySQL 與 MariaDB 我想可以考慮 MariaDB;理由也很簡單,因為大多數的 Linux distribution 都有內建的套件可以安裝(只是版本可能會比較舊不是最新的)。然後要小心資料庫專屬的功能,小心的避掉廠商鎖定的風險。

2023-11-22

tkimg 1.4.16

tkImg

 

tkimg 提供了更多影像格式的支援 (BMP, GIF, ICO, JPEG, PCX, PNG, PPM, PS, SGI, SUN, TGA, TIFF, XBM, XPM),最近釋出了 1.4.16 的新版本。

2023-11-15

DuckDB and ODBC

 DuckDB 是一套 in-process SQL OLAP database management system,所以是使用 DuckDB 在單機分析數據,也可以內嵌到應用程式。

因為有提供 ODBC interface,所以我使用 TDBC-ODBC 測試一下是否可以連線。

下載後解開壓縮檔,將二個檔案放在某個目錄(我是放在家目錄下的 Programs)。

首先在 Linux 執行需要有安裝 unixODBC。雖然 DuckDB 有提供 unixodbc_setup.sh 可以建立設定檔,不過需要python 以及相關的函式庫有安裝,所以我在執行時發生錯誤。不過只是要建立 ODBC 設定,DuckDB 在文件上也有提供相關的內容,所以自行在家目錄下建立以下二個檔案即可。

.odbc.ini

[DuckDB]
Driver = DuckDB Driver
Database=:memory:

.odbcinst.ini

[ODBC]
Trace = yes
TraceFile = /tmp/odbctrace

[DuckDB Driver]
Driver = /home/danilo/Programs/libduckdb_odbc.so

接下來就寫一個簡單的 script 測試。

package require tdbc::odbc

set connStr "DSN=DuckDB;"
if {[catch {tdbc::odbc::connection create db $connStr}]} {
   puts "Connection failed."
   exit
}

set statement [db prepare {SELECT VERSION() as version}]

puts "DuckDB version:"
$statement foreach row {
    puts [dict get $row version]
}

$statement close
db close

如果有印出 DuckDB 的版本,就表示可以透過 ODBC 來使用 DuckDB 了。

2023-11-14

tclcubrid v0.9.6

Source code
tclcubrid


附帶一提,要注意的是,CUBRID 使用 NCURSES 5 API,所以在 openSUSE 上使用,如果 NCRUSES 版本已升級到 6, 那麼需要安裝 NCURSES 6 所提供的與 5 ABI 相容的函式庫:

sudo zypper in libncurses5

我看了一下 tclcubrid 在 CUBRID 11.3 的執行情況,發現會有問題,所以更新了 CCI header files 嘗試解決問題;以及 CUBRID 10.2 有加入 JSON type,我在 v0.9.6 也嘗試加入 JSON type 的支援。