/ Check-in [c9e3015f]
Login

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

Overview
Comment:A few more bugfixes. Test cases pass now. (CVS 1472)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c9e3015faffb650d8dbf1f7f95a7057a36361bac
User & Date: danielk1977 2004-05-27 10:30:53
Context
2004-05-27
12:11
Alter the Tcl eval sub-command so that it supports blobs. (CVS 1473) check-in: b5d5f0ad user: danielk1977 tags: trunk
10:30
A few more bugfixes. Test cases pass now. (CVS 1472) check-in: c9e3015f user: danielk1977 tags: trunk
09:28
Various bugfixes. 68 Test cases still fail. (CVS 1471) check-in: 67a140cf user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/func.c.

    12     12   ** This file contains the C functions that implement various SQL
    13     13   ** functions of SQLite.  
    14     14   **
    15     15   ** There is only one exported symbol in this file - the function
    16     16   ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
    17     17   ** All other code has file scope.
    18     18   **
    19         -** $Id: func.c,v 1.60 2004/05/27 09:28:42 danielk1977 Exp $
           19  +** $Id: func.c,v 1.61 2004/05/27 10:30:53 danielk1977 Exp $
    20     20   */
    21     21   #include <ctype.h>
    22     22   #include <math.h>
    23     23   #include <stdlib.h>
    24     24   #include <assert.h>
    25     25   #include "sqliteInt.h"
    26     26   #include "vdbeInt.h"
................................................................................
    38     38     int mask;    /* 0 for min() or 0xffffffff for max() */
    39     39     int iBest;
    40     40   
    41     41     if( argc==0 ) return;
    42     42     mask = (int)sqlite3_user_data(context);
    43     43     assert( mask==-1 || mask==0 );
    44     44     iBest = 0;
           45  +  if( sqlite3_value_type(argv[0])==SQLITE3_NULL ) return;
    45     46     for(i=1; i<argc; i++){
           47  +    if( sqlite3_value_type(argv[i])==SQLITE3_NULL ) return;
    46     48       if( (sqlite3MemCompare(argv[iBest], argv[i], 0)^mask)>=0 ){
    47     49         iBest = i;
    48     50       }
    49     51     }
    50     52     sqlite3_result_value(context, argv[iBest]);
    51     53   }
    52     54   
................................................................................
   103    105   /*
   104    106   ** Implementation of the abs() function
   105    107   */
   106    108   static void absFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
   107    109     assert( argc==1 );
   108    110     switch( sqlite3_value_type(argv[0]) ){
   109    111       case SQLITE3_INTEGER: {
   110         -      sqlite3_result_int64(context, -sqlite3_value_int64(argv[0]));
          112  +      i64 iVal = sqlite3_value_int64(argv[0]);
          113  +      if( iVal<0 ) iVal = iVal * -1;
          114  +      sqlite3_result_int64(context, iVal);
   111    115         break;
   112    116       }
   113    117       case SQLITE3_NULL: {
   114    118         sqlite3_result_null(context);
   115    119         break;
   116    120       }
   117    121       default: {
   118         -      sqlite3_result_double(context, -sqlite3_value_double(argv[0]));
          122  +      double rVal = sqlite3_value_double(argv[0]);
          123  +      if( rVal<0 ) rVal = rVal * -1.0;
          124  +      sqlite3_result_double(context, rVal);
   119    125         break;
   120    126       }
   121    127     }
   122    128   }
   123    129   
   124    130   /*
   125    131   ** Implementation of the substr() function

Changes to src/select.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle SELECT statements in SQLite.
    14     14   **
    15         -** $Id: select.c,v 1.178 2004/05/26 16:54:44 drh Exp $
           15  +** $Id: select.c,v 1.179 2004/05/27 10:30:53 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   
    20     20   /*
    21     21   ** Allocate a new Select structure and return a pointer to that
    22     22   ** structure.
................................................................................
  2115   2115   
  2116   2116     /* ORDER BY is ignored for some destinations.
  2117   2117     */
  2118   2118     switch( eDest ){
  2119   2119       case SRT_Union:
  2120   2120       case SRT_Except:
  2121   2121       case SRT_Discard:
         2122  +    case SRT_Set:
  2122   2123         pOrderBy = 0;
  2123   2124         break;
  2124   2125       default:
  2125   2126         break;
  2126   2127     }
  2127   2128   
  2128   2129     /* At this point, we should have allocated all the cursors that we

Changes to src/test1.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Code for testing the printf() interface to SQLite.  This code
    13     13   ** is not included in the SQLite library.  It is used for automated
    14     14   ** testing of the SQLite library.
    15     15   **
    16         -** $Id: test1.c,v 1.62 2004/05/27 09:28:43 danielk1977 Exp $
           16  +** $Id: test1.c,v 1.63 2004/05/27 10:31:10 danielk1977 Exp $
    17     17   */
    18     18   #include "sqliteInt.h"
    19     19   #include "tcl.h"
    20     20   #include "os.h"
    21     21   #include <stdlib.h>
    22     22   #include <string.h>
    23     23   
................................................................................
  1581   1581     Tcl_Interp *interp,
  1582   1582     int objc,
  1583   1583     Tcl_Obj *CONST objv[]
  1584   1584   ){
  1585   1585     sqlite3_stmt *pStmt;
  1586   1586     int col;
  1587   1587     const char *(*xFunc)(sqlite3_stmt*, int) = clientData;
         1588  +  const char *zRet;
  1588   1589   
  1589   1590     if( objc!=3 ){
  1590   1591       Tcl_AppendResult(interp, "wrong # args: should be \"", 
  1591   1592          Tcl_GetString(objv[0]), " STMT column", 0);
  1592   1593       return TCL_ERROR;
  1593   1594     }
  1594   1595   
  1595   1596     if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
  1596   1597     if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR;
  1597         -  Tcl_SetResult(interp, (char *)xFunc(pStmt, col), 0);
         1598  +  zRet = xFunc(pStmt, col);
         1599  +  if( zRet ){
         1600  +    Tcl_SetResult(interp, (char *)zRet, 0);
         1601  +  }
  1598   1602     return TCL_OK;
  1599   1603   }
  1600   1604   
  1601   1605   /*
  1602   1606   ** Usage: sqlite3_column_text STMT column
  1603   1607   **
  1604   1608   ** Usage: sqlite3_column_decltype STMT column
................................................................................
  1623   1627       return TCL_ERROR;
  1624   1628     }
  1625   1629   
  1626   1630     if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
  1627   1631     if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR;
  1628   1632   
  1629   1633     zName16 = xFunc(pStmt, col);
  1630         -  pRet = Tcl_NewByteArrayObj(zName16, sqlite3utf16ByteLen(zName16, -1)+2);
  1631         -  Tcl_SetObjResult(interp, pRet);
         1634  +  if( zName16 ){
         1635  +    pRet = Tcl_NewByteArrayObj(zName16, sqlite3utf16ByteLen(zName16, -1)+2);
         1636  +    Tcl_SetObjResult(interp, pRet);
         1637  +  }
  1632   1638   
  1633   1639     return TCL_OK;
  1634   1640   }
  1635   1641   
  1636   1642   /*
  1637   1643   ** Usage: sqlite3_column_int STMT column
  1638   1644   **

Changes to src/vdbemem.c.

    62     62       pMem->flags &= ~(MEM_Ephem | MEM_Short | MEM_Static);
    63     63       pMem->flags |= MEM_Str | MEM_Dyn | MEM_Term;
    64     64     }else{
    65     65       /* Must be translating between UTF-16le and UTF-16be. */
    66     66       int i;
    67     67       u8 *pFrom, *pTo;
    68     68       sqlite3VdbeMemMakeWriteable(pMem);
    69         -    for(i=0, pFrom=pMem->z, pTo=&pMem->z[1]; i<pMem->n; i+=2, pFrom++, pTo++){
           69  +    for(i=0, pFrom=pMem->z, pTo=&pMem->z[1]; i<pMem->n; i+=2, pFrom+=2,pTo+=2){
    70     70         u8 temp = *pFrom;
    71     71         *pFrom = *pTo;
    72     72         *pTo = temp;
    73     73       }
    74     74     }
    75     75     pMem->enc = desiredEnc;
    76     76     return SQLITE_OK;
................................................................................
   175    175       /* For a Real or Integer, use sqlite3_snprintf() to produce the UTF-8
   176    176       ** string representation of the value. Then, if the required encoding
   177    177       ** is UTF-16le or UTF-16be do a translation.
   178    178       ** 
   179    179       ** FIX ME: It would be better if sqlite3_snprintf() could do UTF-16.
   180    180       */
   181    181       u8 *z = pMem->zShort;
   182         -    if( fg & MEM_Real ){
          182  +    if( fg & MEM_Real || (pMem->type==SQLITE3_FLOAT) ){
   183    183         sqlite3_snprintf(NBFS, z, "%.15g", pMem->r);
   184    184       }else{
   185    185         assert( fg & MEM_Int );
   186    186         sqlite3_snprintf(NBFS, z, "%lld", pMem->i);
   187    187       }
   188    188       pMem->n = strlen(z);
   189    189       pMem->z = z;
................................................................................
   219    219         return SQLITE_NOMEM;
   220    220       }
   221    221       assert( pMem->z );
   222    222       sqlite3atoi64(pMem->z, &pMem->i);
   223    223     }else{
   224    224       pMem->i = 0;
   225    225     }
   226         -  releaseMem(pMem);
   227         -  pMem->flags = MEM_Int;
   228         -  pMem->type = SQLITE3_INTEGER;
          226  +  pMem->flags |= MEM_Int;
   229    227     return SQLITE_OK;
   230    228   }
   231    229   
   232    230   /*
   233    231   ** Add MEM_Real to the set of representations for pMem.  Prior
   234    232   ** prior representations other than MEM_Null retained.  NULL is
   235    233   ** converted into 0.0.
   236    234   */
   237    235   int sqlite3VdbeMemRealify(Mem *pMem){
   238         -  if( pMem->flags & MEM_Int ){
          236  +  if( pMem->flags & MEM_Real ){
          237  +    /* Do nothing */
          238  +  }else if( (pMem->flags & MEM_Int) && pMem->type!=SQLITE3_TEXT ){
   239    239       pMem->r = pMem->i;
   240         -    pMem->flags |= MEM_Real;
   241    240     }else if( pMem->flags & (MEM_Str|MEM_Blob) ){
   242    241       if( sqlite3VdbeChangeEncoding(pMem, TEXT_Utf8)
   243    242          || sqlite3VdbeMemNulTerminate(pMem) ){
   244    243         return SQLITE_NOMEM;
   245    244       }
   246    245       assert( pMem->z );
   247    246       pMem->r = sqlite3AtoF(pMem->z, 0);
   248         -    releaseMem(pMem);
   249         -    pMem->flags = MEM_Real;
   250         -    pMem->type = SQLITE3_FLOAT;
   251    247     }else{
   252    248       pMem->r = 0.0;
   253         -    pMem->flags = MEM_Real;
   254         -    pMem->type = SQLITE3_FLOAT;
   255    249     }
          250  +  pMem->flags |= MEM_Real;
   256    251     return SQLITE_OK;
   257    252   }
   258    253   
   259    254   /*
   260    255   ** Delete any previous value and set the value stored in *pMem to NULL.
   261    256   */
   262    257   void sqlite3VdbeMemSetNull(Mem *pMem){

Changes to test/capi3.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script testing the callback-free C/C++ API.
    13     13   #
    14         -# $Id: capi3.test,v 1.8 2004/05/27 09:28:44 danielk1977 Exp $
           14  +# $Id: capi3.test,v 1.9 2004/05/27 10:31:12 danielk1977 Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Return the UTF-16 representation of the supplied UTF-8 string $str.
    21     21   # If $nt is true, append two 0x00 bytes as a nul terminator.
................................................................................
   324    324   check_header $STMT capi3-5.1 {a b c} {VARIANT BLOB VARCHAR(16)}
   325    325   
   326    326   do_test capi3-5.2 {
   327    327     sqlite3_step $STMT
   328    328   } SQLITE_ROW
   329    329   
   330    330   check_header $STMT capi3-5.3 {a b c} {VARIANT BLOB VARCHAR(16)}
   331         -check_data $STMT capi3-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1 2 3} {1 2 3}
          331  +check_data $STMT capi3-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1.0 2.0 3.0} {1 2 3}
   332    332   
   333    333   do_test capi3-5.5 {
   334    334     sqlite3_step $STMT
   335    335   } SQLITE_ROW
   336    336   
   337    337   check_header $STMT capi3-5.6 {a b c} {VARIANT BLOB VARCHAR(16)}
   338         -check_data $STMT capi3-5.7 {TEXT TEXT NULL} {0 0 0} {0 0 0} {one two {}}
          338  +check_data $STMT capi3-5.7 {TEXT TEXT NULL} {0 0 0} {0.0 0.0 0.0} {one two {}}
   339    339   
   340    340   do_test capi3-5.8 {
   341    341     sqlite3_step $STMT
   342    342   } SQLITE_ROW
   343    343   
   344    344   check_header $STMT capi3-5.9 {a b c} {VARIANT BLOB VARCHAR(16)}
   345         -check_data $STMT capi3-5.10 {REAL REAL TEXT} {1 1 1} {1.2 1.3 1.4} {1.2 1.3 1.4}
          345  +check_data $STMT capi3-5.10 {FLOAT FLOAT TEXT} {1 1 1} {1.2 1.3 1.4} {1.2 1.3 1.4}
   346    346   
   347    347   do_test capi3-5.11 {
   348    348     sqlite3_step $STMT
   349    349   } SQLITE_DONE
   350    350   
   351    351   do_test capi3-5.12 {
   352    352     sqlite3_finalize $STMT

Changes to test/func.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing built-in functions.
    13     13   #
    14         -# $Id: func.test,v 1.17 2004/05/14 11:00:53 danielk1977 Exp $
           14  +# $Id: func.test,v 1.18 2004/05/27 10:31:12 danielk1977 Exp $
    15     15   
    16     16   set testdir [file dirname $argv0]
    17     17   source $testdir/tester.tcl
    18     18   
    19     19   # Create a table to work with.
    20     20   #
    21     21   do_test func-0.0 {
................................................................................
   169    169     catchsql {SELECT abs(c) FROM t1 ORDER BY a}
   170    170   } {0 {3 12345.6789 5}}
   171    171   do_test func-4.4.1 {
   172    172     execsql {SELECT abs(a) FROM t2}
   173    173   } {1 {} 345 {} 67890}
   174    174   do_test func-4.4.2 {
   175    175     execsql {SELECT abs(t1) FROM tbl1}
   176         -} {this program is free software}
          176  +} {0 0 0 0 0}
   177    177   
   178    178   do_test func-4.5 {
   179    179     catchsql {SELECT round(a,b,c) FROM t1}
   180    180   } {1 {wrong number of arguments to function round()}}
   181    181   do_test func-4.6 {
   182    182     catchsql {SELECT round(b,2) FROM t1 ORDER BY b}
   183    183   } {0 {-2.00 1.23 2.00}}