Fossil

Check-in [2b4b2a50]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:minor th1 doc and script code cleanups.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | th1-query-api
Files: files | file ages | folders
SHA1: 2b4b2a5091dc81ae770c47f915210d4be3275710
User & Date: stephan 2012-07-22 11:39:04.123
Context
2012-07-22
11:55
Reduced the set of th1-exported SQLITE_xxx constants to those which are actually used in script APIs. Minor doc updates. ... (check-in: 8e040551 user: stephan tags: th1-query-api)
11:39
minor th1 doc and script code cleanups. ... (check-in: 2b4b2a50 user: stephan tags: th1-query-api)
2012-07-20
18:54
Fixed a c99ism and a missing return statement. ... (check-in: c01764b0 user: stephan tags: th1-query-api)
Changes
Unified Diff Ignore Whitespace Patch
Changes to test/th1-query-api-1.th1.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
set i 0
set colNames(0) 0
for {set i 0} {$i < $colCount} {incr i} {
    set colNames($i) [query $stmt col name $i]
    puts "colNames($i)=" $colNames($i) "\n"
}

for {set row 0} {0 < [query $stmt step]} {incr row} {
    for {set i 0} {$i < $colCount} {incr i} {
        if {$i > 0} {
            puts $sep
        } else {
            puts "#$row: $sep"
        }
        puts $colNames($i) = [query $stmt col string $i]







|







17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
set i 0
set colNames(0) 0
for {set i 0} {$i < $colCount} {incr i} {
    set colNames($i) [query $stmt col name $i]
    puts "colNames($i)=" $colNames($i) "\n"
}

for {set row 0} {[query $stmt step]} {incr row} {
    for {set i 0} {$i < $colCount} {incr i} {
        if {$i > 0} {
            puts $sep
        } else {
            puts "#$row: $sep"
        }
        puts $colNames($i) = [query $stmt col string $i]
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
proc query_step_each {{stmt} {callback}} {
    set colNames(0) 0
    set colCount [query $stmt col count]
    for {set i 0} {$i < $colCount} {incr i} {
        set colNames($i) [query $stmt col name $i]
    }
    upvar cb $callback
    for {set row 0} {0 < [query $stmt step]} {incr row} {
        #puts "Calling callback: $stmt $colCount colNames\n"
        $callback $stmt $colCount
    }
}

set sql {SELECT uid, login FROM user WHERE uid!=?}
#set sql {SELECT uid, login FROM user WHERE login=?}







|







41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
proc query_step_each {{stmt} {callback}} {
    set colNames(0) 0
    set colCount [query $stmt col count]
    for {set i 0} {$i < $colCount} {incr i} {
        set colNames($i) [query $stmt col name $i]
    }
    upvar cb $callback
    for {set row 0} {[query $stmt step]} {incr row} {
        #puts "Calling callback: $stmt $colCount colNames\n"
        $callback $stmt $colCount
    }
}

set sql {SELECT uid, login FROM user WHERE uid!=?}
#set sql {SELECT uid, login FROM user WHERE login=?}
Changes to test/th1-query-api-2.th1.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<th1>
catch {
    set stmt [query prepare {
        SELECT login, cap, cexpire, mtime, NULL FROM user
        WHERE uid<? AND cexpire IS NOT NULL
        AND mtime IS NOT NULL
    }]
    puts "stmt ID=$stmt\n"
#    query bind int $stmt 1 2
#    query $stmt bind int 1 2
    query $stmt bind 1 int 2
# segfault:    query bind 1 int $stmt 2
    set sep "\n"
    for {} {0 < [query $stmt step]} {} {
        puts [query $stmt col string 0] $sep
        puts [query $stmt col time 2 {%Y%m%d @ %H:%M:%S}] $sep
        puts [query $stmt col time 2 {%Y%m%d @ %H:%M:%S} {+10 years}] $sep
        puts [query $stmt col 2 time {%Y%m%d @ %H:%M:%S} {+10 years}] $sep
#        puts [query col time $stmt 2 %s] $sep
        puts [query col time $stmt 3 %s unixepoch] $sep
#        puts [query strftime %s [query col string $stmt 3] unixepoch]










|


|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<th1>
catch {
    set stmt [query prepare {
        SELECT login, cap, cexpire, mtime, NULL FROM user
        WHERE uid<? AND cexpire IS NOT NULL
        AND mtime IS NOT NULL
    }]
    puts "stmt ID=$stmt\n"
#    query bind int $stmt 1 2
#    query $stmt bind int 1 2
    query $stmt bind 1 int 5
# segfault:    query bind 1 int $stmt 2
    set sep "\n"
    for {} {[query $stmt step]} {} {
        puts [query $stmt col string 0] $sep
        puts [query $stmt col time 2 {%Y%m%d @ %H:%M:%S}] $sep
        puts [query $stmt col time 2 {%Y%m%d @ %H:%M:%S} {+10 years}] $sep
        puts [query $stmt col 2 time {%Y%m%d @ %H:%M:%S} {+10 years}] $sep
#        puts [query col time $stmt 2 %s] $sep
        puts [query col time $stmt 3 %s unixepoch] $sep
#        puts [query strftime %s [query col string $stmt 3] unixepoch]
Changes to www/th1_query.wiki.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<h1>TH1 "query" API</h1>

The "query" API provides limited access to the fossil database.
It restricts usage to queries which return result columns (i.e.
<tt>SELECT</tt> and friends).
Example usage:

<nowiki><pre>
&lt;th1>
catch {
    set stmt [query prepare "SELECT login, cap FROM user"]
    puts "stmt ID=$stmt\n"
    for {} {0 < [query $stmt step]} {} {
        puts [query $stmt col string 0] ": " [query $stmt col string 1] "\n"
    }
    query $stmt finalize
    return 0
} rc
if {0 != $rc} {
    puts "ERROR: $rc\n"
}












|
|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<h1>TH1 "query" API</h1>

The "query" API provides limited access to the fossil database.
It restricts usage to queries which return result columns (i.e.
<tt>SELECT</tt> and friends).
Example usage:

<nowiki><pre>
&lt;th1>
catch {
    set stmt [query prepare "SELECT login, cap FROM user"]
    puts "stmt ID=$stmt\n"
    for {} {[query $stmt step]} {} {
        puts [query $stmt col string 0] " " [query $stmt col string 1] \n
    }
    query $stmt finalize
    return 0
} rc
if {0 != $rc} {
    puts "ERROR: $rc\n"
}