SQLite Forum

null character sorts greater than 0x7f and less than 0x80
Login
The output of the following script is <code>127 0 128</code> rather than the
expected <code>0 127 128</code>

<code><verbatim>
#! /usr/bin/env tclsh
package require sqlite3
sqlite db :memory:

db eval {
    create table t (
        v text
    )
}

foreach val {
    \x80
    \x7f
    \x00
} {
    string range $val 0 end
    #puts [::tcl::unsupported::representation $val]
    db eval {
        insert into t values ($val)
    }
}

set sorted {}
db eval {
    select v from t order by v collate binary asc 
} {
    lappend list $v
    scan $v %c ord
    lappend sorted $ord
}

puts $sorted
</verbatim></code>

The correct output would be <code>0 127 128</code>, woulddn't it?

-- 
Yorick