/ Check-in [4ded1965]
Login

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

Overview
Comment:Fix for ticket #297 - bug in sqliteSortCompare(). (CVS 917)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4ded1965eb83dee0f28c27ba935d615c77331571
User & Date: drh 2003-04-18 17:45:14
Context
2003-04-18
22:52
fix a memory leak in btree_rb.c. (CVS 918) check-in: 1e3d0d09 user: drh tags: trunk
17:45
Fix for ticket #297 - bug in sqliteSortCompare(). (CVS 917) check-in: 4ded1965 user: drh tags: trunk
02:31
The VACUUM command is now functioning (again). Need to do more testing. (CVS 916) check-in: 6e948d9a user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/util.c.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
...
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
**
*************************************************************************
** Utility functions used throughout sqlite.
**
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.61 2003/04/16 02:17:36 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
#include <ctype.h>

/*
** If malloc() ever fails, this global variable gets set to 1.
................................................................................
**
** Note that the sort order imposed by the rules above is the same
** from the ordering defined by the "<", "<=", ">", and ">=" operators
** of expressions and for indices.  This was not the case for version
** 2.6.3 and earlier.
*/
int sqliteSortCompare(const char *a, const char *b){
  int len;
  int res = 0;
  int isNumA, isNumB;
  int dir = 0;

  while( res==0 && *a && *b ){
    if( a[0]=='N' || b[0]=='N' ){
      if( a[0]==b[0] ){
................................................................................
        res = +1;
        break;
      }else{
        res = strcmp(&a[1],&b[1]);
        if( res ) break;
      }
    }
    len = strlen(&a[1]) + 2;
    a += len;
    b += len;
  }
  if( dir=='-' || dir=='D' ) res = -res;
  return res;
}

/*
** Some powers of 64.  These constants are needed in the







|







 







<







 







|
|
<







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
904
905
906
907
908
909
910

911
912
913
914
915
916
917
...
955
956
957
958
959
960
961
962
963

964
965
966
967
968
969
970
**
*************************************************************************
** Utility functions used throughout sqlite.
**
** This file contains functions for allocating memory, comparing
** strings, and stuff like that.
**
** $Id: util.c,v 1.62 2003/04/18 17:45:14 drh Exp $
*/
#include "sqliteInt.h"
#include <stdarg.h>
#include <ctype.h>

/*
** If malloc() ever fails, this global variable gets set to 1.
................................................................................
**
** Note that the sort order imposed by the rules above is the same
** from the ordering defined by the "<", "<=", ">", and ">=" operators
** of expressions and for indices.  This was not the case for version
** 2.6.3 and earlier.
*/
int sqliteSortCompare(const char *a, const char *b){

  int res = 0;
  int isNumA, isNumB;
  int dir = 0;

  while( res==0 && *a && *b ){
    if( a[0]=='N' || b[0]=='N' ){
      if( a[0]==b[0] ){
................................................................................
        res = +1;
        break;
      }else{
        res = strcmp(&a[1],&b[1]);
        if( res ) break;
      }
    }
    a += strlen(&a[1]) + 2;
    b += strlen(&b[1]) + 2;

  }
  if( dir=='-' || dir=='D' ) res = -res;
  return res;
}

/*
** Some powers of 64.  These constants are needed in the

Changes to test/sort.test.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
343
344
345
346
347
348
349











350
#    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 file is testing the CREATE TABLE statement.
#
# $Id: sort.test,v 1.8 2003/01/18 20:11:07 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Create a bunch of data to sort against
#
do_test sort-1.0 {
................................................................................
} {1 11 12 2}
do_test sort-7.14 {
  execsql {
    SELECT b FROM t4 UNION SELECT b FROM v4 ORDER BY 1 COLLATE varchar;
  }
} {1 11 12 2}












finish_test







|







 







>
>
>
>
>
>
>
>
>
>
>

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#    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 file is testing the CREATE TABLE statement.
#
# $Id: sort.test,v 1.9 2003/04/18 17:45:15 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Create a bunch of data to sort against
#
do_test sort-1.0 {
................................................................................
} {1 11 12 2}
do_test sort-7.14 {
  execsql {
    SELECT b FROM t4 UNION SELECT b FROM v4 ORDER BY 1 COLLATE varchar;
  }
} {1 11 12 2}

# Ticket #297
#
do_test sort-8.1 {
  execsql {
    CREATE TABLE t5(a real, b text);
    INSERT INTO t5 VALUES(100,'A1');
    INSERT INTO t5 VALUES(100.0,'A2');
    SELECT * FROM t5 ORDER BY a, b;
  }
} {100 A1 100.0 A2}

finish_test