2016-11-29

1-9位數不重複印出來 (練習問題)

使用者輸入1 印1-9
使用者輸入2 印1-98 (11, 22, 33等重複的不印)
使用者輸入3 印1-987 (121, 988, 667等有重複的不印)


#!/usr/bin/tclsh
#
# Test on Tcl 8.6
#

puts -nonewline "Please input a number: "
flush stdout
gets stdin number
if {$number <= 0 || $number >= 10} {
   puts "The range is 1 - 9."
   exit
}

set max [expr 10 ** $number]

puts "\nNow get the result:"
puts "==========="
puts "Start"
puts "==========="
puts -nonewline "1"
for {set i 2} {$i < $max} {incr i} {
    set var [regexp "1.*1|2.*2|3.*3|4.*4|5.*5|6.*6|7.*7|8.*8|9.*9|0.*0" $i]
    if {$var != 1} {
        puts -nonewline ", $i"
    }
}
puts "\n==========="
puts "End"
puts "==========="

2016-11-18

tcl.mqttc

Source code


tcl.mqttc

About


This Tcl extension is based on Paho MQTT C Client, but only support synchronous API and basic SSL/TLS support (server needs setup needClientAuth to false).

Test server: Apache ActiveMQ

我發現 Apache ActiveMQ 有支援 MQTT,所以使用 Paho MQTT C Client 的實作,包裝了一個 Tcl extension 來測試。

TLS/SSL 只支援 Server authentication/Anonymous connection,Mutual authentication 則有問題(應該說我不知道怎麼正確設定,稍微搜尋了一下網路上的解法,還是設不起來),所以只有放上去關於 Server authentication 的部份。


2016/11/19 更新
我重新檢視了一下 log,發現我好像沒有正確的加入資料到 server 端的 trueStore,重做一次以後就可以正常工作。所以我把 Mutual authentication 相關的部份也推送上去 github 了。

2016-11-14

tclmonetdb v0.9.3

Homepage


tclmonetdb

About


MonetDB is an open source column-oriented database management system developed at the Centrum Wiskunde & Informatica (CWI) in the Netherlands.

MonetDB excessively uses main memory for processing, but does not require that all data fit in the available physical memory. To handle a dataset that exceeds the available physical memory, MonetDB does not (only) rely on the available swap space, but (also) uses memory-mapped files to exploit disk storage beyond the swap space as virtual memory.

tclmonetdb is a Tcl extension by using MAPI library to connect MonetDB.

一些說明

  1. Free memory when connect fail

這是一個小更新的版本。

tclcubrid v0.9.3

Source code

tclcubrid

About


CUBRID is an open source SQL-based relational database management system with object extensions developed by Naver Corporation for web applications.

tclcubrid is a Tcl extension by using CUBRID CCI (CCI Client Interface) driver to connect CUBRID. I write this extension to research CUBRID and CCI (CCI Client Interface) driver.

Main changelog

  1. Free memory when connect fail

 這是一個小更新的版本。

2016-11-11

MonetDB ODBC (Linux/openSUSE) test

MonetDB ODBC driver 的部份,首先必須要先安裝 unixODBC,然後編譯的時候需要有編譯 ODBC driver。 unixODBC 需要設定二個檔案。/etc/unixODBC/odbc.ini 與 /etc/unixODBC/odbcinst.ini。


首先是 odbcinst.ini 的內容:
[MonetDB]
Description     = ODBC driver for MonetDB server
Driver          = /usr/local/lib64/libMonetODBC.so
Setup           = /usr/local/lib64/libMonetODBCs.so
FileUsage       = 1

再來是 odbc.ini,
[MonetDB]
Description     = MonetDB
Driver          = MonetDB
Trace           = No
TraceFile       =
Database        = demo
Host            = localhost
UserName        = monetdb
Password        = monetdb
Port            = 50000
ConfigFile      =

我們使用 TDBCODBC 進行驗證:
package require tdbc::odbc

set connStr "DSN=MonetDB; UID=monetdb; PWD=monetdb;"
tdbc::odbc::connection create db $connStr

set statement [db prepare {create table person (id integer, name varchar(40))}]
$statement execute
$statement close

set statement [db prepare {insert into person values(1, 'leo')}]
$statement execute
$statement close

set statement [db prepare {insert into person values(2, 'yui')}]
$statement execute
$statement close

set statement [db prepare {SELECT * FROM person}]

$statement foreach row {
    puts [dict get $row id]
    puts [dict get $row name]
}

$statement close

set statement [db prepare {drop table person}]
$statement execute
$statement close

2016-11-07

tclmonetdb v0.9.2

Homepage


tclmonetdb

About


MonetDB is an open source column-oriented database management system developed at the Centrum Wiskunde & Informatica (CWI) in the Netherlands.

MonetDB excessively uses main memory for processing, but does not require that all data fit in the available physical memory. To handle a dataset that exceeds the available physical memory, MonetDB does not (only) rely on the available swap space, but (also) uses memory-mapped files to exploit disk storage beyond the swap space as virtual memory.

tclmonetdb is a Tcl extension by using MAPI library to connect MonetDB.

一些說明

  1. Update MAPI header
  2. Update Thread_Exit method

這是一個小更新的版本。

2016-11-06

tclcubrid v0.9.2

Source code

tclcubrid

About


CUBRID is an open source SQL-based relational database management system with object extensions developed by Naver Corporation for web applications.

tclcubrid is a Tcl extension by using CUBRID CCI (CCI Client Interface) driver to connect CUBRID. I write this extension to research CUBRID and CCI (CCI Client Interface) driver.

Main changelog

  1. Update Thread_Exit method

 這是一個小更新的版本。

2016-11-04

tclmonetdb v0.9.1

Homepage

tclmonetdb

About

tclmonetdb is a Tcl extension by using MAPI library to connect MonetDB.

一些說明

  1. Update README.md
  2. Update TDBC configure method
更新 TDBC configure method,加入 -encoding, -isolation and -readonly option(只有傳回目前的設定值)

tclcubrid v0.9.1

Source code:
tclcubrid


About:

CUBRID is an open source SQL-based relational database management system with object extensions developed by Naver Corporation for web applications.

tclcubrid is a Tcl extension by using CUBRID CCI (CCI Client Interface) driver to connect CUBRID. I write this extension to research CUBRID and CCI (CCI Client Interface) driver.


Main changelog:

  1. Update TDBC configure method

 這是一個小更新的版本,更新 TDBC configure method(加入 -readonly option)。

2016-10-25

pgintcl and PREPARE

pgintcl 是純粹使用 Tcl 所撰寫的 PostgreSQL client。

不過沒有實作 PQprepare 相關的部份,那麼如果要使用 prepared statement,要怎麼使用?答案是使用 PostgreSQL 的 PREPARE statement。

下面是一段簡單的 test code 的內容:
package require pgintcl

# connect to database
set db [pg_connect -conninfo "dbname=danilo user=danilo password=danilo"]

pg_execute $db "CREATE TABLE IF NOT EXISTS contact (id int, name varchar(200), primary key(id));"
pg_execute $db "PREPARE test1 AS INSERT INTO contact (id, name) VALUES (\$1, \$2);"
set res [pg_describe_prepared $db test1]
# Although Get the param type, it is the Object IDs for the Postgres data types
pg_result $res -paramTypes
pg_result $res -clear

# Need setup text or binary format, here is setup to all TEXT format
set res [pg_exec_prepared $db test1 TEXT  TEXT 1 "Raynor"]
pg_result $res -status
pg_result $res -clear

# Need setup text or binary format, here is setup to all TEXT format
set res [pg_exec_prepared $db test1 TEXT  TEXT 2 "Tassadra"]
pg_result $res -status
pg_result $res -clear

# Need setup text or binary format, here is setup to all TEXT format
set res [pg_exec_prepared $db test1 TEXT  TEXT 3 "Kavin"]
pg_result $res -status
pg_result $res -clear

pg_execute $db "PREPARE test2 AS select * from contact;"
set res [pg_describe_prepared $db test2]
# Get column number and attributes
pg_result $res -numAttrs 
pg_result $res -lAttributes
# Get param types
pg_result $res -paramTypes
pg_result $res -clear

set res [pg_exec_prepared $db test2 TEXT  TEXT]
# Get the result numbers
pg_result $res -numTuples
# Returns the query results as a Tcl dictionary
pg_result $res -dict

pg_execute $db "DROP TABLE IF EXISTS contact;"

pg_disconnect $db

這樣就可以在 pgintcl 中使用 prepared statement 了。另外 PostgreSQL 不是使用 ?,而是使用 $1, $2 來代表。