Index: src/func.c ================================================================== --- src/func.c +++ src/func.c @@ -964,12 +964,12 @@ } } } /* -** tointeger(X): If X is any value (integer, double, or string) that can -** be losslessly converted into an integer, then make the conversion and +** tointeger(X): If X is any value (integer, double, blob, or string) that +** can be losslessly converted into an integer, then make the conversion and ** return the result. Otherwise, return NULL. */ static void tointegerFunc( sqlite3_context *context, int argc, @@ -994,11 +994,20 @@ const unsigned char *zBlob = sqlite3_value_blob(argv[0]); if( zBlob ){ int nBlob = sqlite3_value_bytes(argv[0]); if( nBlob==sizeof(i64) ){ i64 iVal; - memcpy(&iVal, zBlob, sizeof(i64)); + if( SQLITE_BIGENDIAN ){ + int i; + unsigned char *zBlobRev = contextMalloc(context, nBlob); + if( !zBlobRev ) break; + for(i=0; i