/ Check-in [4438b986]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Fix compiler warnings and boundary cases for the tointeger() and toreal() functions.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | toTypeFuncs
Files: files | file ages | folders
SHA1: 4438b9865826446721b7aa09295fe335bf2fafb7
User & Date: drh 2013-08-20 02:07:50
Context
2013-08-20
09:26
Add test cases for tointeger() and toreal() functions. Fixes for several tests. check-in: 5e1e9fd5 user: mistachkin tags: toTypeFuncs
02:07
Fix compiler warnings and boundary cases for the tointeger() and toreal() functions. check-in: 4438b986 user: drh tags: toTypeFuncs
00:42
Performance optimizations in the VDBE and especially to the OP_Next and related opcodes. check-in: d78c5d89 user: drh tags: toTypeFuncs
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/func.c.

977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
....
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
){
  assert( argc==1 );
  UNUSED_PARAMETER(argc);
  switch( sqlite3_value_type(argv[0]) ){
    case SQLITE_FLOAT: {
      double rVal = sqlite3_value_double(argv[0]);
      i64 iVal = (i64)rVal;
      if( !sqlite3IsNaN(rVal) && rVal==(double)iVal ){
        sqlite3_result_int64(context, iVal);
      }
      break;
    }
    case SQLITE_INTEGER: {
      sqlite3_result_int64(context, sqlite3_value_int64(argv[0]));
      break;
    }
    case SQLITE_BLOB:
    case SQLITE_TEXT: {
      const unsigned char *zStr = sqlite3_value_text(argv[0]);
      if( zStr ){
        int nStr = sqlite3_value_bytes(argv[0]);
        if( nStr ){
          i64 iVal;
          if( !sqlite3Atoi64(zStr, &iVal, nStr, SQLITE_UTF8) ){
            sqlite3_result_int64(context, iVal);
          }
        }
      }
      break;
    }
    default: {
................................................................................
  UNUSED_PARAMETER(argc);
  switch( sqlite3_value_type(argv[0]) ){
    case SQLITE_FLOAT: {
      sqlite3_result_double(context, sqlite3_value_double(argv[0]));
      break;
    }
    case SQLITE_INTEGER: {
      i64 iVal = sqlite3_value_int64(argv[0]);
      double rVal = (double)iVal;
      if( iVal==rVal ){
        sqlite3_result_double(context, rVal);
      }
      break;
    }
    case SQLITE_BLOB:
    case SQLITE_TEXT: {
      const unsigned char *zStr = sqlite3_value_text(argv[0]);
      if( zStr ){
        int nStr = sqlite3_value_bytes(argv[0]);
        if( nStr ){
          double rVal;
          if( sqlite3AtoF(zStr, &rVal, nStr, SQLITE_UTF8) ){
            sqlite3_result_double(context, rVal);
            return;
          }
        }
      }
      break;
    }







|













|

|







 







<
<
<
|
<







|

|







977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
....
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
){
  assert( argc==1 );
  UNUSED_PARAMETER(argc);
  switch( sqlite3_value_type(argv[0]) ){
    case SQLITE_FLOAT: {
      double rVal = sqlite3_value_double(argv[0]);
      i64 iVal = (i64)rVal;
      if( rVal==(double)iVal ){
        sqlite3_result_int64(context, iVal);
      }
      break;
    }
    case SQLITE_INTEGER: {
      sqlite3_result_int64(context, sqlite3_value_int64(argv[0]));
      break;
    }
    case SQLITE_BLOB:
    case SQLITE_TEXT: {
      const unsigned char *zStr = sqlite3_value_text(argv[0]);
      if( zStr ){
        int nStr = sqlite3_value_bytes(argv[0]);
        if( nStr && !sqlite3Isspace(zStr[0]) ){
          i64 iVal;
          if( !sqlite3Atoi64((const char*)zStr, &iVal, nStr, SQLITE_UTF8) ){
            sqlite3_result_int64(context, iVal);
          }
        }
      }
      break;
    }
    default: {
................................................................................
  UNUSED_PARAMETER(argc);
  switch( sqlite3_value_type(argv[0]) ){
    case SQLITE_FLOAT: {
      sqlite3_result_double(context, sqlite3_value_double(argv[0]));
      break;
    }
    case SQLITE_INTEGER: {



      sqlite3_result_double(context, (double)sqlite3_value_int64(argv[0]));

      break;
    }
    case SQLITE_BLOB:
    case SQLITE_TEXT: {
      const unsigned char *zStr = sqlite3_value_text(argv[0]);
      if( zStr ){
        int nStr = sqlite3_value_bytes(argv[0]);
        if( nStr && !sqlite3Isspace(zStr[0]) && !sqlite3Isspace(zStr[nStr-1]) ){
          double rVal;
          if( sqlite3AtoF((const char*)zStr, &rVal, nStr, SQLITE_UTF8) ){
            sqlite3_result_double(context, rVal);
            return;
          }
        }
      }
      break;
    }