mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-11 01:42:22 +03:00
A few more bugfixes. Test cases pass now. (CVS 1472)
FossilOrigin-Name: c9e3015faffb650d8dbf1f7f95a7057a36361bac
This commit is contained in:
12
src/func.c
12
src/func.c
@@ -16,7 +16,7 @@
|
||||
** 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 <ctype.h>
|
||||
#include <math.h>
|
||||
@@ -42,7 +42,9 @@ static void minmaxFunc(
|
||||
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<argc; i++){
|
||||
if( sqlite3_value_type(argv[i])==SQLITE3_NULL ) return;
|
||||
if( (sqlite3MemCompare(argv[iBest], argv[i], 0)^mask)>=0 ){
|
||||
iBest = i;
|
||||
}
|
||||
@@ -107,7 +109,9 @@ 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: {
|
||||
@@ -115,7 +119,9 @@ static void absFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
** 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"
|
||||
|
||||
@@ -2119,6 +2119,7 @@ int sqlite3Select(
|
||||
case SRT_Union:
|
||||
case SRT_Except:
|
||||
case SRT_Discard:
|
||||
case SRT_Set:
|
||||
pOrderBy = 0;
|
||||
break;
|
||||
default:
|
||||
|
||||
14
src/test1.c
14
src/test1.c
@@ -13,7 +13,7 @@
|
||||
** 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"
|
||||
@@ -1585,6 +1585,7 @@ static int test_stmt_utf8(
|
||||
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 \"",
|
||||
@@ -1594,7 +1595,10 @@ static int test_stmt_utf8(
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1627,8 +1631,10 @@ static int test_stmt_utf16(
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){
|
||||
int i;
|
||||
u8 *pFrom, *pTo;
|
||||
sqlite3VdbeMemMakeWriteable(pMem);
|
||||
for(i=0, pFrom=pMem->z, pTo=&pMem->z[1]; i<pMem->n; i+=2, pFrom++, pTo++){
|
||||
for(i=0, pFrom=pMem->z, pTo=&pMem->z[1]; i<pMem->n; i+=2, pFrom+=2,pTo+=2){
|
||||
u8 temp = *pFrom;
|
||||
*pFrom = *pTo;
|
||||
*pTo = temp;
|
||||
@@ -179,7 +179,7 @@ int sqlite3VdbeMemStringify(Mem *pMem, int enc){
|
||||
** 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 );
|
||||
@@ -223,9 +223,7 @@ int sqlite3VdbeMemIntegerify(Mem *pMem){
|
||||
}else{
|
||||
pMem->i = 0;
|
||||
}
|
||||
releaseMem(pMem);
|
||||
pMem->flags = MEM_Int;
|
||||
pMem->type = SQLITE3_INTEGER;
|
||||
pMem->flags |= MEM_Int;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
@@ -235,9 +233,10 @@ int sqlite3VdbeMemIntegerify(Mem *pMem){
|
||||
** 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) ){
|
||||
@@ -245,14 +244,10 @@ int sqlite3VdbeMemRealify(Mem *pMem){
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user