2018-05-30 23:44:58 +03:00
|
|
|
# 2018 May 19
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
#
|
|
|
|
|
|
|
|
package require sqlite3
|
|
|
|
package require Pgtcl
|
|
|
|
|
|
|
|
set db [pg_connect -conninfo "dbname=postgres user=postgres password=postgres"]
|
|
|
|
sqlite3 sqlite ""
|
|
|
|
|
|
|
|
proc execsql {sql} {
|
|
|
|
|
|
|
|
set lSql [list]
|
|
|
|
set frag ""
|
|
|
|
while {[string length $sql]>0} {
|
|
|
|
set i [string first ";" $sql]
|
|
|
|
if {$i>=0} {
|
|
|
|
append frag [string range $sql 0 $i]
|
|
|
|
set sql [string range $sql $i+1 end]
|
|
|
|
if {[sqlite complete $frag]} {
|
|
|
|
lappend lSql $frag
|
|
|
|
set frag ""
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
set frag $sql
|
|
|
|
set sql ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if {$frag != ""} {
|
|
|
|
lappend lSql $frag
|
|
|
|
}
|
|
|
|
#puts $lSql
|
|
|
|
|
|
|
|
set ret ""
|
2019-03-16 23:29:54 +03:00
|
|
|
set nChar 0
|
2018-05-30 23:44:58 +03:00
|
|
|
foreach stmt $lSql {
|
|
|
|
set res [pg_exec $::db $stmt]
|
|
|
|
set err [pg_result $res -error]
|
|
|
|
if {$err!=""} { error $err }
|
2019-03-16 23:29:54 +03:00
|
|
|
|
2018-05-30 23:44:58 +03:00
|
|
|
for {set i 0} {$i < [pg_result $res -numTuples]} {incr i} {
|
2019-03-16 23:29:54 +03:00
|
|
|
set t [pg_result $res -getTuple $i]
|
|
|
|
set nNew [string length $t]
|
|
|
|
if {$nChar>0 && ($nChar+$nNew+3)>75} {
|
|
|
|
append ret "\n "
|
|
|
|
set nChar 0
|
2018-05-30 23:44:58 +03:00
|
|
|
} else {
|
2019-03-16 23:29:54 +03:00
|
|
|
if {$nChar>0} {
|
|
|
|
append ret " "
|
|
|
|
incr nChar 3
|
|
|
|
}
|
2018-05-30 23:44:58 +03:00
|
|
|
}
|
2019-03-16 23:29:54 +03:00
|
|
|
incr nChar $nNew
|
|
|
|
append ret $t
|
2018-05-30 23:44:58 +03:00
|
|
|
}
|
|
|
|
pg_result $res -clear
|
|
|
|
}
|
|
|
|
|
|
|
|
set ret
|
|
|
|
}
|
|
|
|
|
|
|
|
proc execsql_test {tn sql} {
|
|
|
|
set res [execsql $sql]
|
2018-06-08 14:45:28 +03:00
|
|
|
set sql [string map {string_agg group_concat} $sql]
|
2019-08-19 22:59:50 +03:00
|
|
|
# set sql [string map [list {NULLS FIRST} {}] $sql]
|
|
|
|
# set sql [string map [list {NULLS LAST} {}] $sql]
|
2018-05-30 23:44:58 +03:00
|
|
|
puts $::fd "do_execsql_test $tn {"
|
|
|
|
puts $::fd " [string trim $sql]"
|
|
|
|
puts $::fd "} {$res}"
|
|
|
|
puts $::fd ""
|
|
|
|
}
|
|
|
|
|
2019-03-05 00:07:11 +03:00
|
|
|
proc errorsql_test {tn sql} {
|
|
|
|
set rc [catch {execsql $sql} msg]
|
|
|
|
if {$rc==0} {
|
|
|
|
error "errorsql_test SQL did not cause an error!"
|
|
|
|
}
|
2019-03-09 23:49:17 +03:00
|
|
|
set msg [lindex [split [string trim $msg] "\n"] 0]
|
|
|
|
puts $::fd "# PG says $msg"
|
2019-03-05 00:07:11 +03:00
|
|
|
set sql [string map {string_agg group_concat} $sql]
|
|
|
|
puts $::fd "do_test $tn { catch { execsql {"
|
|
|
|
puts $::fd " [string trim $sql]"
|
|
|
|
puts $::fd "} } } 1"
|
|
|
|
puts $::fd ""
|
|
|
|
}
|
|
|
|
|
2018-06-04 11:22:09 +03:00
|
|
|
# Same as [execsql_test], except coerce all results to floating point values
|
|
|
|
# with two decimal points.
|
|
|
|
#
|
|
|
|
proc execsql_float_test {tn sql} {
|
2018-07-10 21:50:01 +03:00
|
|
|
set F "%.4f"
|
|
|
|
set T 0.0001
|
2018-06-04 11:22:09 +03:00
|
|
|
set res [execsql $sql]
|
|
|
|
set res2 [list]
|
2018-06-14 23:52:08 +03:00
|
|
|
foreach r $res {
|
|
|
|
if {$r != ""} { set r [format $F $r] }
|
|
|
|
lappend res2 $r
|
|
|
|
}
|
2018-06-04 11:22:09 +03:00
|
|
|
|
2018-07-10 21:50:01 +03:00
|
|
|
set sql [string trim $sql]
|
|
|
|
puts $::fd [subst -nocommands {
|
|
|
|
do_test $tn {
|
|
|
|
set myres {}
|
|
|
|
foreach r [db eval {$sql}] {
|
|
|
|
lappend myres [format $F [set r]]
|
|
|
|
}
|
|
|
|
set res2 {$res2}
|
2019-03-08 23:02:52 +03:00
|
|
|
set i 0
|
2018-07-10 21:50:01 +03:00
|
|
|
foreach r [set myres] r2 [set res2] {
|
|
|
|
if {[set r]<([set r2]-$T) || [set r]>([set r2]+$T)} {
|
|
|
|
error "list element [set i] does not match: got=[set r] expected=[set r2]"
|
|
|
|
}
|
2019-03-08 23:02:52 +03:00
|
|
|
incr i
|
2018-07-10 21:50:01 +03:00
|
|
|
}
|
|
|
|
set {} {}
|
|
|
|
} {}
|
|
|
|
}]
|
2018-06-04 11:22:09 +03:00
|
|
|
}
|
|
|
|
|
2018-05-30 23:44:58 +03:00
|
|
|
proc start_test {name date} {
|
|
|
|
set dir [file dirname $::argv0]
|
|
|
|
set output [file join $dir $name.test]
|
|
|
|
set ::fd [open $output w]
|
|
|
|
puts $::fd [string trimleft "
|
|
|
|
# $date
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
# This file implements regression tests for SQLite library.
|
|
|
|
#
|
|
|
|
|
|
|
|
####################################################
|
|
|
|
# DO NOT EDIT! THIS FILE IS AUTOMATICALLY GENERATED!
|
|
|
|
####################################################
|
|
|
|
"]
|
|
|
|
puts $::fd {set testdir [file dirname $argv0]}
|
|
|
|
puts $::fd {source $testdir/tester.tcl}
|
|
|
|
puts $::fd "set testprefix $name"
|
|
|
|
puts $::fd ""
|
|
|
|
}
|
|
|
|
|
|
|
|
proc -- {args} {
|
|
|
|
puts $::fd "# $args"
|
|
|
|
}
|
|
|
|
|
|
|
|
proc ========== {args} {
|
|
|
|
puts $::fd "#[string repeat = 74]"
|
|
|
|
puts $::fd ""
|
|
|
|
}
|
|
|
|
|
|
|
|
proc finish_test {} {
|
|
|
|
puts $::fd finish_test
|
|
|
|
close $::fd
|
|
|
|
}
|
|
|
|
|
2018-06-22 23:51:35 +03:00
|
|
|
proc ifcapable {arg} {
|
|
|
|
puts $::fd "ifcapable $arg { finish_test ; return }"
|
|
|
|
}
|
|
|
|
|