Add the RTRIM collating sequence. Only implemented for UTF8. Still

considered experimental and may be removed if we find adverse impact
elsewhere in the system. (CVS 4732)

FossilOrigin-Name: 0bf4e7fefdbbf7be4e32195473563158f22f1869
This commit is contained in:
drh 2008-01-20 23:19:56 +00:00
parent de4fcfdd7a
commit 9b5adfa220
5 changed files with 175 additions and 14 deletions

View File

@ -1,5 +1,5 @@
C Additional\stest\scoverage\simprovements.\s\sTest\scoverage\snow\sstands\sat\s98.73%.\s(CVS\s4731)
D 2008-01-19T23:50:26
C Add\sthe\sRTRIM\scollating\ssequence.\s\sOnly\simplemented\sfor\sUTF8.\s\sStill\nconsidered\sexperimental\sand\smay\sbe\sremoved\sif\swe\sfind\sadverse\simpact\nelsewhere\sin\sthe\ssystem.\s(CVS\s4732)
D 2008-01-20T23:19:57
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in 30789bf70614bad659351660d76b8e533f3340e9
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -101,7 +101,7 @@ F src/journal.c 807bed7a158979ac8d63953e1774e8d85bff65e2
F src/legacy.c 4ac53191fad2e3c4d59bde1228879b2dc5a96d66
F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35
F src/loadext.c d17a0f760d6866aacf5262f97d8efaaad379cdd7
F src/main.c bdeb906fb112ff60f3612d4fd91abba05ae6d397
F src/main.c 05bba9097e39b14ad03c345baaef3a47b4588cbf
F src/malloc.c 60e392a4c12c839517f9b0db7b995f825444fb35
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/mem1.c 6d1a11864963d249c67e72ad5f6533b040333880
@ -233,6 +233,7 @@ F test/collate6.test 8be65a182abaac8011a622131486dafb8076e907
F test/collate7.test e23677b1fd271505302643a98178952bb65b6f21
F test/collate8.test 7ed2461305ac959886a064dc1e3cf15e155a183f
F test/collate9.test 0867eabc1222ab0bc308fc09a7fb30770334c3cd
F test/collateA.test e86542420ef1b9fd98bbe6d857ea8eec20c177bb
F test/colmeta.test 6505c73ab58796afcb7c89ba9f429d573fbc6e53
F test/conflict.test 79b5214ef7a52f3e58a50ae5c60c37e7594d04e9
F test/corrupt.test 18c7a995b1af76a8c8600b996257f2c7b7bff083
@ -401,7 +402,7 @@ F test/pager2.test c025f91b75fe65e85febda64d9416428b8a5cab5
F test/pager3.test 2323bf27fd5bd887b580247e5bce500ceee994b4
F test/pageropt.test 51e3c091bc2992f5098f7576e3594e1908988939
F test/pagesize.test e0a8b3fe80f8b8e808d94a00734c7a18c76c407e
F test/pragma.test bb77b00e82b25d48140b5ce14dbf5d0b8ebeef63
F test/pragma.test d9f3d80583b80708aa270e8c5038dee949190d78
F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47
F test/printf.test 6bf1a86c6a1e45536f72d782bf44c8e3c76510f8
F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 x
@ -607,7 +608,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P af129b6d158cc90ce9752dd6383c1de47f7b3e43
R 29177cb746663a31c6843d98589f65e8
P 010f7b780cb9c8f21af9ce810494fbd2be98a13f
R a77c92cd50edbd9b3113d32c480fb532
U drh
Z 52f8bb1305af66e6799c302ba2f646a8
Z 428dd7074c3ab6d6dfe6113da7ace6b5

View File

@ -1 +1 @@
010f7b780cb9c8f21af9ce810494fbd2be98a13f
0bf4e7fefdbbf7be4e32195473563158f22f1869

View File

@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.409 2007/12/07 18:55:28 drh Exp $
** $Id: main.c,v 1.410 2008/01/20 23:19:57 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -45,12 +45,23 @@ void (*sqlite3_io_trace)(const char*, ...) = 0;
char *sqlite3_temp_directory = 0;
/*
** Return true if the buffer z[0..n-1] contains all spaces.
*/
static int allSpaces(const char *z, int n){
while( n>0 && z[--n]==' ' ){}
return n==0;
}
/*
** This is the default collating function named "BINARY" which is always
** available.
**
** If the padFlag argument is not NULL then space padding at the end
** of strings is ignored. This implements the RTRIM collation.
*/
static int binCollFunc(
void *NotUsed,
void *padFlag,
int nKey1, const void *pKey1,
int nKey2, const void *pKey2
){
@ -58,7 +69,14 @@ static int binCollFunc(
n = nKey1<nKey2 ? nKey1 : nKey2;
rc = memcmp(pKey1, pKey2, n);
if( rc==0 ){
rc = nKey1 - nKey2;
if( padFlag
&& allSpaces(((char*)pKey1)+n, nKey1-n)
&& allSpaces(((char*)pKey2)+n, nKey2-n)
){
/* Leave rc unchanged at 0 */
}else{
rc = nKey1 - nKey2;
}
}
return rc;
}
@ -994,6 +1012,7 @@ static int openDatabase(
if( createCollation(db, "BINARY", SQLITE_UTF8, 0, binCollFunc, 0) ||
createCollation(db, "BINARY", SQLITE_UTF16BE, 0, binCollFunc, 0) ||
createCollation(db, "BINARY", SQLITE_UTF16LE, 0, binCollFunc, 0) ||
createCollation(db, "RTRIM", SQLITE_UTF8, (void*)1, binCollFunc, 0) ||
(db->pDfltColl = sqlite3FindCollSeq(db, SQLITE_UTF8, "BINARY", 6, 0))==0
){
assert( db->mallocFailed );

141
test/collateA.test Normal file
View File

@ -0,0 +1,141 @@
#
# 2008 January 20
#
# 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. The
# focus of this script is the built-in RTRIM collating
# API.
#
# $Id: collateA.test,v 1.1 2008/01/20 23:19:58 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_test collateA-1.1 {
execsql {
CREATE TABLE t1(
a INTEGER PRIMARY KEY,
b TEXT COLLATE BINARY,
c TEXT COLLATE RTRIM
);
INSERT INTO t1 VALUES(1, 'hello','hello');
INSERT INTO t1 VALUES(2, 'xyzzy ','xyzzy ');
INSERT INTO t1 VALUES(3, 'xyzzy ','xyzzy ');
INSERT INTO t1 VALUES(4, 'xyzzy ','xyzzy ');
SELECT count(*) FROM t1;
}
} {4}
do_test collateA-1.2 {
execsql {SELECT a FROM t1 WHERE b='hello '}
} {}
do_test collateA-1.3 {
execsql {SELECT a FROM t1 WHERE c='hello '}
} {1}
do_test collateA-1.4 {
execsql {SELECT a FROM t1 WHERE b='xyzzy'}
} {}
do_test collateA-1.5 {
execsql {SELECT a FROM t1 WHERE c='xyzzy'}
} {2 3 4}
do_test collateA-1.6 {
execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
do_test collateA-1.7 {
execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
do_test collateA-1.8 {
execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
do_test collateA-1.9 {
execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
do_test collateA-1.10 {
execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
do_test collateA-1.11 {
execsql {SELECT 'abc123'='abc123 ' COLLATE RTRIM;}
} {1}
do_test collateA-1.12 {
execsql {SELECT 'abc123 '='abc123' COLLATE RTRIM;}
} {1}
do_test collateA-2.1 {
execsql {
CREATE INDEX i1b ON t1(b);
CREATE INDEX i1c ON t1(c);
PRAGMA integrity_check;
}
} {ok}
do_test collateA-2.2 {
execsql {SELECT a FROM t1 WHERE b='hello '}
} {}
do_test collateA-2.3 {
execsql {SELECT a FROM t1 WHERE c='hello '}
} {1}
do_test collateA-2.4 {
execsql {SELECT a FROM t1 WHERE b='xyzzy'}
} {}
do_test collateA-2.5 {
execsql {SELECT a FROM t1 WHERE c='xyzzy'}
} {2 3 4}
do_test collateA-2.6 {
execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
do_test collateA-2.7 {
execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
do_test collateA-2.8 {
execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
do_test collateA-2.9 {
execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
do_test collateA-2.10 {
execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
do_test collateA-3.1 {
db close
sqlite3 db test.db
execsql {
REINDEX;
PRAGMA integrity_check;
}
} {ok}
do_test collateA-3.2 {
execsql {SELECT a FROM t1 WHERE b='hello '}
} {}
do_test collateA-3.3 {
execsql {SELECT a FROM t1 WHERE c='hello '}
} {1}
do_test collateA-3.4 {
execsql {SELECT a FROM t1 WHERE b='xyzzy'}
} {}
do_test collateA-3.5 {
execsql {SELECT a FROM t1 WHERE c='xyzzy'}
} {2 3 4}
do_test collateA-3.6 {
execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
do_test collateA-3.7 {
execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
do_test collateA-3.8 {
execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
do_test collateA-3.9 {
execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
do_test collateA-3.10 {
execsql {SELECT a FROM t1 WHERE c='xyzzy '}
} {2 3 4}
finish_test

View File

@ -12,7 +12,7 @@
#
# This file implements tests for the PRAGMA command.
#
# $Id: pragma.test,v 1.56 2007/12/29 13:39:21 danielk1977 Exp $
# $Id: pragma.test,v 1.57 2008/01/20 23:19:58 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -978,13 +978,13 @@ ifcapable schema_pragmas {
execsql2 {
pragma collation_list;
}
} {seq 0 name NOCASE seq 1 name BINARY}
} {seq 0 name NOCASE seq 1 name RTRIM seq 2 name BINARY}
do_test pragma-11.2 {
db collate New_Collation blah...
execsql {
pragma collation_list;
}
} {0 New_Collation 1 NOCASE 2 BINARY}
} {0 New_Collation 1 NOCASE 2 RTRIM 3 BINARY}
}
ifcapable schema_pragmas&&tempdb {