SQLite

Check-in [c085d6dfc0]
Login

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

Overview
Comment:Add comments, assertions, and test cases to demonstrate that the problem described in ticket #2742 is not a real problem. (CVS 4510)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c085d6dfc0f5849113986cb2a25e64d0c95b3dfb
User & Date: drh 2007-10-23 18:55:49.000
Context
2007-10-24
21:52
fts3.c buildTerms() passes -1 for nInput. (CVS 4511) (check-in: e87c883a12 user: shess tags: trunk)
2007-10-23
18:55
Add comments, assertions, and test cases to demonstrate that the problem described in ticket #2742 is not a real problem. (CVS 4510) (check-in: c085d6dfc0 user: drh tags: trunk)
15:59
Add comments to the code warning that _XOPEN_SOURCE might need to be defined manually if using USE_PREAD or USE_PREAD64. (CVS 4509) (check-in: d7ed7cd077 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/expr.c.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.314 2007/10/23 15:39:45 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Return the 'affinity' of the expression pExpr if any.
**







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.315 2007/10/23 18:55:49 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>

/*
** Return the 'affinity' of the expression pExpr if any.
**
1690
1691
1692
1693
1694
1695
1696




1697
1698
1699
1700
1701
1702

1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713




1714
1715
1716
1717
1718

1719
1720
1721
1722
1723
1724
1725
  }
  return out;
}

/*
** Generate an instruction that will put the floating point
** value described by z[0..n-1] on the stack.




*/
static void codeReal(Vdbe *v, const char *z, int n, int negateFlag){
  assert( z || v==0 || sqlite3VdbeDb(v)->mallocFailed );
  if( z ){
    double value;
    char *zV;

    sqlite3AtoF(z, &value);
    if( negateFlag ) value = -value;
    zV = dup8bytes(v, (char*)&value);
    sqlite3VdbeOp3(v, OP_Real, 0, 0, zV, P3_REAL);
  }
}


/*
** Generate an instruction that will put the integer describe by
** text z[0..n-1] on the stack.




*/
static void codeInteger(Vdbe *v, const char *z, int n, int negateFlag){
  assert( z || v==0 || sqlite3VdbeDb(v)->mallocFailed );
  if( z ){
    int i;

    if( sqlite3GetInt32(z, &i) ){
      if( negateFlag ) i = -i;
      sqlite3VdbeAddOp(v, OP_Integer, i, 0);
    }else if( sqlite3FitsIn64Bits(z, negateFlag) ){
      i64 value;
      char *zV;
      sqlite3Atoi64(z, &value);







>
>
>
>






>











>
>
>
>





>







1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
  }
  return out;
}

/*
** Generate an instruction that will put the floating point
** value described by z[0..n-1] on the stack.
**
** The z[] string will probably not be zero-terminated.  But the 
** z[n] character is guaranteed to be something that does not look
** like the continuation of the number.
*/
static void codeReal(Vdbe *v, const char *z, int n, int negateFlag){
  assert( z || v==0 || sqlite3VdbeDb(v)->mallocFailed );
  if( z ){
    double value;
    char *zV;
    assert( !isdigit(z[n]) );
    sqlite3AtoF(z, &value);
    if( negateFlag ) value = -value;
    zV = dup8bytes(v, (char*)&value);
    sqlite3VdbeOp3(v, OP_Real, 0, 0, zV, P3_REAL);
  }
}


/*
** Generate an instruction that will put the integer describe by
** text z[0..n-1] on the stack.
**
** The z[] string will probably not be zero-terminated.  But the 
** z[n] character is guaranteed to be something that does not look
** like the continuation of the number.
*/
static void codeInteger(Vdbe *v, const char *z, int n, int negateFlag){
  assert( z || v==0 || sqlite3VdbeDb(v)->mallocFailed );
  if( z ){
    int i;
    assert( !isdigit(z[n]) );
    if( sqlite3GetInt32(z, &i) ){
      if( negateFlag ) i = -i;
      sqlite3VdbeAddOp(v, OP_Integer, i, 0);
    }else if( sqlite3FitsIn64Bits(z, negateFlag) ){
      i64 value;
      char *zV;
      sqlite3Atoi64(z, &value);
Changes to test/capi3.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2003 January 29
#
# 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 testing the callback-free C/C++ API.
#
# $Id: capi3.test,v 1.55 2007/08/29 19:15:09 drh Exp $
#

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

# Return the UTF-16 representation of the supplied UTF-8 string $str.
# If $nt is true, append two 0x00 bytes as a nul terminator.













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 2003 January 29
#
# 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 testing the callback-free C/C++ API.
#
# $Id: capi3.test,v 1.56 2007/10/23 18:55:50 drh Exp $
#

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

# Return the UTF-16 representation of the supplied UTF-8 string $str.
# If $nt is true, append two 0x00 bytes as a nul terminator.
1016
1017
1018
1019
1020
1021
1022













































1023
1024
1025
1026
1027
1028
1029
do_test capi3-15.2 {
  sqlite3_step $STMT
  sqlite3_column_int $STMT 0
} {2}
do_test capi3-15.3 {
  sqlite3_finalize $STMT
} {SQLITE_OK}














































# Make sure code is always generated even if an IF EXISTS or 
# IF NOT EXISTS clause is present that the table does not or
# does exists.  That way we will always have a prepared statement
# to expire when the schema changes.
#
do_test capi3-16.1 {







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
do_test capi3-15.2 {
  sqlite3_step $STMT
  sqlite3_column_int $STMT 0
} {2}
do_test capi3-15.3 {
  sqlite3_finalize $STMT
} {SQLITE_OK}
do_test capi3-15.4 {
  #        123456789 1234567
  set sql {SELECT 1234567890}
  set STMT [sqlite3_prepare $DB $sql 8 TAIL]
  sqlite3_step $STMT
  set v1 [sqlite3_column_int $STMT 0]
  sqlite3_finalize $STMT
  set v1
} {1}
do_test capi3-15.5 {
  #        123456789 1234567
  set sql {SELECT 1234567890}
  set STMT [sqlite3_prepare $DB $sql 9 TAIL]
  sqlite3_step $STMT
  set v1 [sqlite3_column_int $STMT 0]
  sqlite3_finalize $STMT
  set v1
} {12}
do_test capi3-15.6 {
  #        123456789 1234567
  set sql {SELECT 1234567890}
  set STMT [sqlite3_prepare $DB $sql 12 TAIL]
  sqlite3_step $STMT
  set v1 [sqlite3_column_int $STMT 0]
  sqlite3_finalize $STMT
  set v1
} {12345}
do_test capi3-15.7 {
  #        123456789 1234567
  set sql {SELECT 12.34567890}
  set STMT [sqlite3_prepare $DB $sql 12 TAIL]
  sqlite3_step $STMT
  set v1 [sqlite3_column_double $STMT 0]
  sqlite3_finalize $STMT
  set v1
} {12.34}
do_test capi3-15.8 {
  #        123456789 1234567
  set sql {SELECT 12.34567890}
  set STMT [sqlite3_prepare $DB $sql 14 TAIL]
  sqlite3_step $STMT
  set v1 [sqlite3_column_double $STMT 0]
  sqlite3_finalize $STMT
  set v1
} {12.3456}

# Make sure code is always generated even if an IF EXISTS or 
# IF NOT EXISTS clause is present that the table does not or
# does exists.  That way we will always have a prepared statement
# to expire when the schema changes.
#
do_test capi3-16.1 {