Index: src/func.c ================================================================== --- src/func.c +++ src/func.c @@ -14,11 +14,11 @@ ** ** There is only one exported symbol in this file - the function ** sqliteRegisterBuildinFunctions() found at the bottom of the file. ** All other code has file scope. ** -** $Id: func.c,v 1.60 2004/05/27 09:28:42 danielk1977 Exp $ +** $Id: func.c,v 1.61 2004/05/27 10:30:53 danielk1977 Exp $ */ #include #include #include #include @@ -40,11 +40,13 @@ if( argc==0 ) return; mask = (int)sqlite3_user_data(context); assert( mask==-1 || mask==0 ); iBest = 0; + if( sqlite3_value_type(argv[0])==SQLITE3_NULL ) return; for(i=1; i=0 ){ iBest = i; } } sqlite3_result_value(context, argv[iBest]); @@ -105,19 +107,23 @@ */ static void absFunc(sqlite3_context *context, int argc, sqlite3_value **argv){ assert( argc==1 ); switch( sqlite3_value_type(argv[0]) ){ case SQLITE3_INTEGER: { - sqlite3_result_int64(context, -sqlite3_value_int64(argv[0])); + i64 iVal = sqlite3_value_int64(argv[0]); + if( iVal<0 ) iVal = iVal * -1; + sqlite3_result_int64(context, iVal); break; } case SQLITE3_NULL: { sqlite3_result_null(context); break; } default: { - sqlite3_result_double(context, -sqlite3_value_double(argv[0])); + double rVal = sqlite3_value_double(argv[0]); + if( rVal<0 ) rVal = rVal * -1.0; + sqlite3_result_double(context, rVal); break; } } } Index: src/select.c ================================================================== --- src/select.c +++ src/select.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.178 2004/05/26 16:54:44 drh Exp $ +** $Id: select.c,v 1.179 2004/05/27 10:30:53 danielk1977 Exp $ */ #include "sqliteInt.h" /* @@ -2117,10 +2117,11 @@ */ switch( eDest ){ case SRT_Union: case SRT_Except: case SRT_Discard: + case SRT_Set: pOrderBy = 0; break; default: break; } Index: src/test1.c ================================================================== --- src/test1.c +++ src/test1.c @@ -11,11 +11,11 @@ ************************************************************************* ** Code for testing the printf() interface to SQLite. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test1.c,v 1.62 2004/05/27 09:28:43 danielk1977 Exp $ +** $Id: test1.c,v 1.63 2004/05/27 10:31:10 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" #include "os.h" #include @@ -1583,20 +1583,24 @@ Tcl_Obj *CONST objv[] ){ sqlite3_stmt *pStmt; int col; const char *(*xFunc)(sqlite3_stmt*, int) = clientData; + const char *zRet; if( objc!=3 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", Tcl_GetString(objv[0]), " STMT column", 0); return TCL_ERROR; } if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; - Tcl_SetResult(interp, (char *)xFunc(pStmt, col), 0); + zRet = xFunc(pStmt, col); + if( zRet ){ + Tcl_SetResult(interp, (char *)zRet, 0); + } return TCL_OK; } /* ** Usage: sqlite3_column_text STMT column @@ -1625,12 +1629,14 @@ if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR; zName16 = xFunc(pStmt, col); - pRet = Tcl_NewByteArrayObj(zName16, sqlite3utf16ByteLen(zName16, -1)+2); - Tcl_SetObjResult(interp, pRet); + if( zName16 ){ + pRet = Tcl_NewByteArrayObj(zName16, sqlite3utf16ByteLen(zName16, -1)+2); + Tcl_SetObjResult(interp, pRet); + } return TCL_OK; } /* Index: src/vdbemem.c ================================================================== --- src/vdbemem.c +++ src/vdbemem.c @@ -64,11 +64,11 @@ }else{ /* Must be translating between UTF-16le and UTF-16be. */ int i; u8 *pFrom, *pTo; sqlite3VdbeMemMakeWriteable(pMem); - for(i=0, pFrom=pMem->z, pTo=&pMem->z[1]; in; i+=2, pFrom++, pTo++){ + for(i=0, pFrom=pMem->z, pTo=&pMem->z[1]; in; i+=2, pFrom+=2,pTo+=2){ u8 temp = *pFrom; *pFrom = *pTo; *pTo = temp; } } @@ -177,11 +177,11 @@ ** is UTF-16le or UTF-16be do a translation. ** ** FIX ME: It would be better if sqlite3_snprintf() could do UTF-16. */ u8 *z = pMem->zShort; - if( fg & MEM_Real ){ + if( fg & MEM_Real || (pMem->type==SQLITE3_FLOAT) ){ sqlite3_snprintf(NBFS, z, "%.15g", pMem->r); }else{ assert( fg & MEM_Int ); sqlite3_snprintf(NBFS, z, "%lld", pMem->i); } @@ -221,40 +221,35 @@ assert( pMem->z ); sqlite3atoi64(pMem->z, &pMem->i); }else{ pMem->i = 0; } - releaseMem(pMem); - pMem->flags = MEM_Int; - pMem->type = SQLITE3_INTEGER; + pMem->flags |= MEM_Int; return SQLITE_OK; } /* ** Add MEM_Real to the set of representations for pMem. Prior ** prior representations other than MEM_Null retained. NULL is ** converted into 0.0. */ int sqlite3VdbeMemRealify(Mem *pMem){ - if( pMem->flags & MEM_Int ){ + if( pMem->flags & MEM_Real ){ + /* Do nothing */ + }else if( (pMem->flags & MEM_Int) && pMem->type!=SQLITE3_TEXT ){ pMem->r = pMem->i; - pMem->flags |= MEM_Real; }else if( pMem->flags & (MEM_Str|MEM_Blob) ){ if( sqlite3VdbeChangeEncoding(pMem, TEXT_Utf8) || sqlite3VdbeMemNulTerminate(pMem) ){ return SQLITE_NOMEM; } assert( pMem->z ); pMem->r = sqlite3AtoF(pMem->z, 0); - releaseMem(pMem); - pMem->flags = MEM_Real; - pMem->type = SQLITE3_FLOAT; }else{ pMem->r = 0.0; - pMem->flags = MEM_Real; - pMem->type = SQLITE3_FLOAT; } + pMem->flags |= MEM_Real; return SQLITE_OK; } /* ** Delete any previous value and set the value stored in *pMem to NULL. Index: test/capi3.test ================================================================== --- test/capi3.test +++ test/capi3.test @@ -9,11 +9,11 @@ # #*********************************************************************** # 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.8 2004/05/27 09:28:44 danielk1977 Exp $ +# $Id: capi3.test,v 1.9 2004/05/27 10:31:12 danielk1977 Exp $ # set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -326,25 +326,25 @@ do_test capi3-5.2 { sqlite3_step $STMT } SQLITE_ROW check_header $STMT capi3-5.3 {a b c} {VARIANT BLOB VARCHAR(16)} -check_data $STMT capi3-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1 2 3} {1 2 3} +check_data $STMT capi3-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1.0 2.0 3.0} {1 2 3} do_test capi3-5.5 { sqlite3_step $STMT } SQLITE_ROW check_header $STMT capi3-5.6 {a b c} {VARIANT BLOB VARCHAR(16)} -check_data $STMT capi3-5.7 {TEXT TEXT NULL} {0 0 0} {0 0 0} {one two {}} +check_data $STMT capi3-5.7 {TEXT TEXT NULL} {0 0 0} {0.0 0.0 0.0} {one two {}} do_test capi3-5.8 { sqlite3_step $STMT } SQLITE_ROW check_header $STMT capi3-5.9 {a b c} {VARIANT BLOB VARCHAR(16)} -check_data $STMT capi3-5.10 {REAL REAL TEXT} {1 1 1} {1.2 1.3 1.4} {1.2 1.3 1.4} +check_data $STMT capi3-5.10 {FLOAT FLOAT TEXT} {1 1 1} {1.2 1.3 1.4} {1.2 1.3 1.4} do_test capi3-5.11 { sqlite3_step $STMT } SQLITE_DONE Index: test/func.test ================================================================== --- test/func.test +++ test/func.test @@ -9,11 +9,11 @@ # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing built-in functions. # -# $Id: func.test,v 1.17 2004/05/14 11:00:53 danielk1977 Exp $ +# $Id: func.test,v 1.18 2004/05/27 10:31:12 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Create a table to work with. @@ -171,11 +171,11 @@ do_test func-4.4.1 { execsql {SELECT abs(a) FROM t2} } {1 {} 345 {} 67890} do_test func-4.4.2 { execsql {SELECT abs(t1) FROM tbl1} -} {this program is free software} +} {0 0 0 0 0} do_test func-4.5 { catchsql {SELECT round(a,b,c) FROM t1} } {1 {wrong number of arguments to function round()}} do_test func-4.6 {