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.211 2009/01/24 11:30:43 drh Exp $ +** $Id: func.c,v 1.212 2009/02/01 18:08:41 drh Exp $ */ #include "sqliteInt.h" #include #include #include "vdbeInt.h" @@ -818,11 +818,19 @@ zStr = sqlite3_value_text(argv[0]); if( zStr==0 ) return; nStr = sqlite3_value_bytes(argv[0]); assert( zStr==sqlite3_value_text(argv[0]) ); /* No encoding change */ zPattern = sqlite3_value_text(argv[1]); - if( zPattern==0 || zPattern[0]==0 ) return; + if( zPattern==0 ){ + assert( sqlite3_value_type(argv[1])==SQLITE_NULL ); + return; + } + if( zPattern[0]==0 ){ + assert( sqlite3_value_type(argv[1])!=SQLITE_NULL ); + sqlite3_result_value(context, argv[0]); + return; + } nPattern = sqlite3_value_bytes(argv[1]); assert( zPattern==sqlite3_value_text(argv[1]) ); /* No encoding change */ zRep = sqlite3_value_text(argv[2]); if( zRep==0 ) return; nRep = sqlite3_value_bytes(argv[2]); 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.88 2009/01/31 22:28:49 drh Exp $ +# $Id: func.test,v 1.89 2009/02/01 18:08:41 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Create a table to work with. @@ -360,21 +360,21 @@ do_test func-9.11-utf16le { execsql {SELECT hex(replace('abcdefg','ef','12'))} } {6100620063006400310032006700} do_test func-9.12-utf16le { execsql {SELECT hex(replace('abcdefg','','12'))} - } {{}} + } {6100620063006400650066006700} do_test func-9.13-utf16le { execsql {SELECT hex(replace('aabcdefg','a','aaa'))} } {610061006100610061006100620063006400650066006700} } elseif {$encoding=="UTF-8"} { do_test func-9.11-utf8 { execsql {SELECT hex(replace('abcdefg','ef','12'))} } {61626364313267} do_test func-9.12-utf8 { execsql {SELECT hex(replace('abcdefg','','12'))} - } {{}} + } {61626364656667} do_test func-9.13-utf8 { execsql {SELECT hex(replace('aabcdefg','a','aaa'))} } {616161616161626364656667} }