Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add experimental tointeger() and todouble() SQL functions. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | toTypeFuncs |
Files: | files | file ages | folders |
SHA1: |
465fd853d3e3544cb06b15ffa32ce257 |
User & Date: | mistachkin 2013-03-11 01:23:37.658 |
Context
2013-03-11
| ||
06:24 | Add more tests. (check-in: f9468e334d user: mistachkin tags: toTypeFuncs) | |
01:23 | Add experimental tointeger() and todouble() SQL functions. (check-in: 465fd853d3 user: mistachkin tags: toTypeFuncs) | |
2013-03-09
| ||
14:49 | Add a test case for the problem fixed by the previous commit. (check-in: e899b058a7 user: dan tags: trunk) | |
Changes
Changes to src/func.c.
︙ | |||
958 959 960 961 962 963 964 965 966 967 968 969 970 971 | 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | assert( sqlite3_value_type(argv[0])==SQLITE_NULL ); sqlite3_result_text(context, "NULL", 4, SQLITE_STATIC); break; } } } /* ** EXPERIMENTAL - This is not an official function. The interface may ** change. This function may disappear. Do not write code that depends ** on this function. ** ** Implementation of the TOINTEGER() function. This function takes a ** single argument. If the argument is an integer or is a double that ** can be losslessly converted to an integer, the return value is the ** same as the argument. If the argument is a double that cannot be ** losslessly represented as an integer, the return value is undefined. ** If the argument is NULL, the return value is NULL. Otherwise, an ** attempt is made to convert the argument to an integer. If the ** conversion is successful, the integer value is returned; otherwise, ** NULL is returned. */ static void tointegerFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ assert( argc==1 ); UNUSED_PARAMETER(argc); switch( sqlite3_value_type(argv[0]) ){ case SQLITE_FLOAT: case SQLITE_INTEGER: { sqlite3_result_int64(context, sqlite3_value_int64(argv[0])); break; } case SQLITE_BLOB: case SQLITE_TEXT: { const unsigned char *zStr = sqlite3_value_text(argv[0]); if( zStr ){ int nStr = sqlite3_value_bytes(argv[0]); if( nStr ){ i64 iVal; if( !sqlite3Atoi64(zStr, &iVal, nStr, SQLITE_UTF8) ){ sqlite3_result_int64(context, iVal); return; } } } sqlite3_result_null(context); break; } default: { assert( sqlite3_value_type(argv[0])==SQLITE_NULL ); sqlite3_result_null(context); break; } } } /* ** EXPERIMENTAL - This is not an official function. The interface may ** change. This function may disappear. Do not write code that depends ** on this function. ** ** Implementation of the TODOUBLE() function. This function takes a ** single argument. If the argument is a double or is an integer that ** can be losslessly converted to a double, the return value is the ** same as the argument. If the argument is an integer that cannot be ** losslessly represented as a double, the return value is undefined. ** If the argument is NULL, the return value is NULL. Otherwise, an ** attempt is made to convert the argument to a double. If the ** conversion is successful, the double value is returned; otherwise, ** NULL is returned. */ #ifndef SQLITE_OMIT_FLOATING_POINT static void todoubleFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ assert( argc==1 ); UNUSED_PARAMETER(argc); switch( sqlite3_value_type(argv[0]) ){ case SQLITE_FLOAT: case SQLITE_INTEGER: { sqlite3_result_double(context, sqlite3_value_double(argv[0])); break; } case SQLITE_BLOB: case SQLITE_TEXT: { const unsigned char *zStr = sqlite3_value_text(argv[0]); if( zStr ){ int nStr = sqlite3_value_bytes(argv[0]); if( nStr ){ double rVal; if( sqlite3AtoF(zStr, &rVal, nStr, SQLITE_UTF8) ){ sqlite3_result_double(context, rVal); return; } } } sqlite3_result_null(context); break; } default: { assert( sqlite3_value_type(argv[0])==SQLITE_NULL ); sqlite3_result_null(context); break; } } } #endif /* ** The unicode() function. Return the integer unicode code-point value ** for the first character of the input string. */ static void unicodeFunc( sqlite3_context *context, int argc, |
︙ | |||
1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 | 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 | + + + + | FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ), #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ), FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ), #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ FUNCTION(quote, 1, 0, 0, quoteFunc ), FUNCTION(tointeger, 1, 0, 0, tointegerFunc ), #ifndef SQLITE_OMIT_FLOATING_POINT FUNCTION(todouble, 1, 0, 0, todoubleFunc ), #endif FUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid), FUNCTION(changes, 0, 0, 0, changes ), FUNCTION(total_changes, 0, 0, 0, total_changes ), FUNCTION(replace, 3, 0, 0, replaceFunc ), FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ), #ifdef SQLITE_SOUNDEX FUNCTION(soundex, 1, 0, 0, soundexFunc ), |
︙ |
Added test/func4.test.