SQLite

Check-in [12c318ef1b]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Rename the experimental todouble() function to toreal(), update comments.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | toTypeFuncs
Files: files | file ages | folders
SHA1: 12c318ef1b674d1ef347458ce149398885f5ba10
User & Date: mistachkin 2013-03-13 06:48:05.170
Context
2013-03-13
20:52
Merge updates from trunk. (check-in: d63fa039a0 user: mistachkin tags: toTypeFuncs)
06:48
Rename the experimental todouble() function to toreal(), update comments. (check-in: 12c318ef1b user: mistachkin tags: toTypeFuncs)
2013-03-12
09:07
Increase strictness of the new experimental functions and add more tests. (check-in: 05c4463ec5 user: mistachkin tags: toTypeFuncs)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/func.c.
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
}

/*
** 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,







|



|







966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
}

/*
** 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 NULL.
** 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,
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
}

/*
** 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]) ){







|



|






|







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
}

/*
** 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 toreal() 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 NULL.
** 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 torealFunc(
  sqlite3_context *context,
  int argc,
  sqlite3_value **argv
){
  assert( argc==1 );
  UNUSED_PARAMETER(argc);
  switch( sqlite3_value_type(argv[0]) ){
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
#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







|







1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
#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(toreal,             1, 0, 0, torealFunc       ),
#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
Changes to test/func4.test.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 2013 March 10
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this file is testing the TOINTEGER() and TODOUBLE()
# functions.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl

set i 0
do_execsql_test func4-1.[incr i] {











|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 2013 March 10
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this file is testing the tointeger() and toreal()
# functions.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl

set i 0
do_execsql_test func4-1.[incr i] {
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(18446744073709551616 + 1);
} {{}}

ifcapable floatingpoint {
  set i 0
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(NULL);
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble('');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble('   ');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble('1234');
  } {1234.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble('   1234');
  } {1234.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble('bad');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble('0xBAD');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble('123BAD');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble('0x123BAD');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble('123NO');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble('0x123NO');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble('-0x1');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble('-0x0');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble('0x0');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble('0x1');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(-1);
  } {-1.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(-0);
  } {0.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(0);
  } {0.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(1);
  } {1.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(-1.79769313486232e308 - 1);
  } {-Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(-1.79769313486232e308);
  } {-Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(-1.79769313486232e308 + 1);
  } {-Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(-9223372036854775808 - 1);
  } {-9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(-9223372036854775808);
  } {-9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(-9223372036854775808 + 1);
  } {-9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(-2147483648 - 1);
  } {-2147483649.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(-2147483648);
  } {-2147483648.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(-2147483648 + 1);
  } {-2147483647.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(2147483647 - 1);
  } {2147483646.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(2147483647);
  } {2147483647.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(2147483647 + 1);
  } {2147483648.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(9223372036854775807 - 1);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(9223372036854775807);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(9223372036854775807 + 1);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(1.79769313486232e308 - 1);
  } {Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(1.79769313486232e308);
  } {Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(1.79769313486232e308 + 1);
  } {Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(4503599627370496 - 1);
  } {4503599627370500.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(4503599627370496);
  } {4503599627370500.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(4503599627370496 + 1);
  } {4503599627370500.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(9007199254740992 - 1);
  } {9007199254740990.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(9007199254740992);
  } {9007199254740990.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(9007199254740992 + 1);
  } {9007199254740990.0}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(9223372036854775808 - 1);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(9223372036854775808);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(9223372036854775808 + 1);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(18446744073709551616 - 1);
  } {1.84467440737096e+19}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(18446744073709551616);
  } {1.84467440737096e+19}
  do_execsql_test func4-2.[incr i] {
    SELECT todouble(18446744073709551616 + 1);
  } {1.84467440737096e+19}
}

ifcapable check {
  set i 0
  do_execsql_test func4-3.[incr i] {
    CREATE TABLE t1(







|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|


|







163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
do_execsql_test func4-1.[incr i] {
  SELECT tointeger(18446744073709551616 + 1);
} {{}}

ifcapable floatingpoint {
  set i 0
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(NULL);
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('   ');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('1234');
  } {1234.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('   1234');
  } {1234.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('bad');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('0xBAD');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('123BAD');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('0x123BAD');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('123NO');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('0x123NO');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('-0x1');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('-0x0');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('0x0');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal('0x1');
  } {{}}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-1);
  } {-1.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-0);
  } {0.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(0);
  } {0.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(1);
  } {1.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-1.79769313486232e308 - 1);
  } {-Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-1.79769313486232e308);
  } {-Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-1.79769313486232e308 + 1);
  } {-Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-9223372036854775808 - 1);
  } {-9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-9223372036854775808);
  } {-9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-9223372036854775808 + 1);
  } {-9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-2147483648 - 1);
  } {-2147483649.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-2147483648);
  } {-2147483648.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(-2147483648 + 1);
  } {-2147483647.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(2147483647 - 1);
  } {2147483646.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(2147483647);
  } {2147483647.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(2147483647 + 1);
  } {2147483648.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9223372036854775807 - 1);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9223372036854775807);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9223372036854775807 + 1);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(1.79769313486232e308 - 1);
  } {Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(1.79769313486232e308);
  } {Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(1.79769313486232e308 + 1);
  } {Inf}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(4503599627370496 - 1);
  } {4503599627370500.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(4503599627370496);
  } {4503599627370500.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(4503599627370496 + 1);
  } {4503599627370500.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9007199254740992 - 1);
  } {9007199254740990.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9007199254740992);
  } {9007199254740990.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9007199254740992 + 1);
  } {9007199254740990.0}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9223372036854775808 - 1);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9223372036854775808);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(9223372036854775808 + 1);
  } {9.22337203685478e+18}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(18446744073709551616 - 1);
  } {1.84467440737096e+19}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(18446744073709551616);
  } {1.84467440737096e+19}
  do_execsql_test func4-2.[incr i] {
    SELECT toreal(18446744073709551616 + 1);
  } {1.84467440737096e+19}
}

ifcapable check {
  set i 0
  do_execsql_test func4-3.[incr i] {
    CREATE TABLE t1(
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
    SELECT x FROM t1 ORDER BY x;
  } {1234 1234}

  ifcapable floatingpoint {
    set i 0
    do_execsql_test func4-4.[incr i] {
      CREATE TABLE t2(
        x REAL CHECK(todouble(x) IS NOT NULL)
      );
    } {}
    do_test func4-4.[incr i] {
      catchsql {
        INSERT INTO t2 (x) VALUES (NULL);
      }
    } {1 {constraint failed}}







|







396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
    SELECT x FROM t1 ORDER BY x;
  } {1234 1234}

  ifcapable floatingpoint {
    set i 0
    do_execsql_test func4-4.[incr i] {
      CREATE TABLE t2(
        x REAL CHECK(toreal(x) IS NOT NULL)
      );
    } {}
    do_test func4-4.[incr i] {
      catchsql {
        INSERT INTO t2 (x) VALUES (NULL);
      }
    } {1 {constraint failed}}