aboutsummaryrefslogtreecommitdiff
path: root/sqlite3/test-sqlite.tcl
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2021-01-10 13:12:36 +1000
committerSteve Bennett <steveb@workware.net.au>2021-01-10 15:33:15 +1000
commit8f3e1ce80995c42a200db98fbfe02e4a60771c26 (patch)
tree79cfcc498292df506fb71660caa3527f03823246 /sqlite3/test-sqlite.tcl
parenta95647743db1816f54368c8b515b6cc6d4c3c745 (diff)
downloadjimtcl-8f3e1ce80995c42a200db98fbfe02e4a60771c26.zip
jimtcl-8f3e1ce80995c42a200db98fbfe02e4a60771c26.tar.gz
jimtcl-8f3e1ce80995c42a200db98fbfe02e4a60771c26.tar.bz2
package: add ABI version checking
jim.h now includes JIM_ABI_VERSION that should be incremented whenever the ABI changes. Then all loadable modules should call Jim_CheckAbiVersion() to make sure they are loaded against the correct version. Add Jim_PackageProvideCheck() that does both Jim_CheckAbiVersion() and Jim_PackageProvide() to simplify the implementation of loadable extensions. Also rename the "big" sqlite3 extension to just sqlite to avoid a naming conflict with the smaller jim-sqlite3 extension. Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'sqlite3/test-sqlite.tcl')
-rw-r--r--sqlite3/test-sqlite.tcl51
1 files changed, 51 insertions, 0 deletions
diff --git a/sqlite3/test-sqlite.tcl b/sqlite3/test-sqlite.tcl
new file mode 100644
index 0000000..82cce40
--- /dev/null
+++ b/sqlite3/test-sqlite.tcl
@@ -0,0 +1,51 @@
+# A simple test of the "big" sqlite extension
+
+set auto_path [list . {*}$auto_path]
+
+package require sqlite
+
+# Create an in-memory database and add some data
+sqlite db :memory:
+db eval {CREATE TABLE history (type, time, value)}
+foreach t [range 1 50] {
+ set temp [rand 100]
+ db eval {INSERT INTO history (type, time, value) VALUES ('temp', :t, :temp)}
+}
+foreach t [range 2 50 2] {
+ set v $([rand 200] / 10.0 + 5)
+ db eval {INSERT INTO history (type, time, value) VALUES ('voltage', :t, :v)}
+}
+
+# Output some data in SVG format.
+puts "\nSVG Example\n"
+
+set points {}
+db eval {SELECT time,value FROM history
+ WHERE (time >= 10 and time <= 30) and type = 'voltage'
+ ORDER BY time DESC} row {
+ lappend points $row(time),$row(value)
+}
+puts "<polyline points=\"$points\" />"
+
+# And tabular format with a self outer join
+puts "\nTabular Self Outer Join Example\n"
+
+proc showrow {args} {
+ puts [format "%-12s %-12s %-12s" {*}$args]
+}
+
+showrow Time Temp Voltage
+showrow ---- ---- -------
+db eval {SELECT * FROM (SELECT time, value AS temp FROM history WHERE type = 'temp') AS A
+ LEFT OUTER JOIN (SELECT time, value AS voltage FROM history WHERE type = 'voltage') AS B
+ USING (time)
+ WHERE time >= 10 AND time <= 30
+ ORDER BY time} row {
+ showrow $row(time) $row(temp) $row(voltage)
+}
+set maxtemp [db eval {SELECT max(value) FROM history WHERE type = 'temp'}]
+set maxvolt [db eval {SELECT max(value) AS maxvolt FROM history WHERE type = 'voltage'}]
+showrow ---- ---- -------
+showrow max $maxtemp $maxvolt
+
+db close