os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/sqllimits1.test
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
# 2007 May 8
sl@0
     2
#
sl@0
     3
# Portions Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiaries. All rights reserved.
sl@0
     4
#
sl@0
     5
# The author disclaims copyright to this source code.  In place of
sl@0
     6
# a legal notice, here is a blessing:
sl@0
     7
#
sl@0
     8
#    May you do good and not evil.
sl@0
     9
#    May you find forgiveness for yourself and forgive others.
sl@0
    10
#    May you share freely, never taking more than you give.
sl@0
    11
#
sl@0
    12
#***********************************************************************
sl@0
    13
#
sl@0
    14
# This file contains tests to verify that the limits defined in
sl@0
    15
# sqlite source file limits.h are enforced.
sl@0
    16
#
sl@0
    17
# $Id: sqllimits1.test,v 1.31 2008/07/15 00:27:35 drh Exp $
sl@0
    18
sl@0
    19
set testdir [file dirname $argv0]
sl@0
    20
source $testdir/tester.tcl
sl@0
    21
sl@0
    22
# Verify that the default per-connection limits are the same as
sl@0
    23
# the compile-time hard limits.
sl@0
    24
#
sl@0
    25
sqlite3 db2 :memory:
sl@0
    26
do_test sqllimits1-1.1 {
sl@0
    27
  sqlite3_limit db SQLITE_LIMIT_LENGTH -1
sl@0
    28
} $SQLITE_MAX_LENGTH
sl@0
    29
do_test sqllimits1-1.2 {
sl@0
    30
  sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH -1
sl@0
    31
} $SQLITE_MAX_SQL_LENGTH
sl@0
    32
do_test sqllimits1-1.3 {
sl@0
    33
  sqlite3_limit db SQLITE_LIMIT_COLUMN -1
sl@0
    34
} $SQLITE_MAX_COLUMN
sl@0
    35
do_test sqllimits1-1.4 {
sl@0
    36
  sqlite3_limit db SQLITE_LIMIT_EXPR_DEPTH -1
sl@0
    37
} $SQLITE_MAX_EXPR_DEPTH
sl@0
    38
do_test sqllimits1-1.5 {
sl@0
    39
  sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT -1
sl@0
    40
} $SQLITE_MAX_COMPOUND_SELECT
sl@0
    41
do_test sqllimits1-1.6 {
sl@0
    42
  sqlite3_limit db SQLITE_LIMIT_VDBE_OP -1
sl@0
    43
} $SQLITE_MAX_VDBE_OP
sl@0
    44
do_test sqllimits1-1.7 {
sl@0
    45
  sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG -1
sl@0
    46
} $SQLITE_MAX_FUNCTION_ARG
sl@0
    47
do_test sqllimits1-1.8 {
sl@0
    48
  sqlite3_limit db SQLITE_LIMIT_ATTACHED -1
sl@0
    49
} $SQLITE_MAX_ATTACHED
sl@0
    50
do_test sqllimits1-1.9 {
sl@0
    51
  sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH -1
sl@0
    52
} $SQLITE_MAX_LIKE_PATTERN_LENGTH
sl@0
    53
do_test sqllimits1-1.10 {
sl@0
    54
  sqlite3_limit db SQLITE_LIMIT_VARIABLE_NUMBER -1
sl@0
    55
} $SQLITE_MAX_VARIABLE_NUMBER
sl@0
    56
sl@0
    57
# Limit parameters out of range.
sl@0
    58
#
sl@0
    59
do_test sqllimits1-1.20 {
sl@0
    60
  sqlite3_limit db SQLITE_LIMIT_TOOSMALL 123
sl@0
    61
} {-1}
sl@0
    62
do_test sqllimits1-1.21 {
sl@0
    63
  sqlite3_limit db SQLITE_LIMIT_TOOSMALL 123
sl@0
    64
} {-1}
sl@0
    65
do_test sqllimits1-1.22 {
sl@0
    66
  sqlite3_limit db SQLITE_LIMIT_TOOBIG 123
sl@0
    67
} {-1}
sl@0
    68
do_test sqllimits1-1.23 {
sl@0
    69
  sqlite3_limit db SQLITE_LIMIT_TOOBIG 123
sl@0
    70
} {-1}
sl@0
    71
sl@0
    72
sl@0
    73
# Decrease all limits by half.  Verify that the new limits take.
sl@0
    74
#
sl@0
    75
if {$SQLITE_MAX_LENGTH>=2} {
sl@0
    76
  do_test sqllimits1-2.1.1 {
sl@0
    77
    sqlite3_limit db SQLITE_LIMIT_LENGTH \
sl@0
    78
                    [expr {$::SQLITE_MAX_LENGTH/2}]
sl@0
    79
  } $SQLITE_MAX_LENGTH
sl@0
    80
  do_test sqllimits1-2.1.2 {
sl@0
    81
    sqlite3_limit db SQLITE_LIMIT_LENGTH -1
sl@0
    82
  } [expr {$SQLITE_MAX_LENGTH/2}]
sl@0
    83
}
sl@0
    84
if {$SQLITE_MAX_SQL_LENGTH>=2} {
sl@0
    85
  do_test sqllimits1-2.2.1 {
sl@0
    86
    sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH \
sl@0
    87
                    [expr {$::SQLITE_MAX_SQL_LENGTH/2}]
sl@0
    88
  } $SQLITE_MAX_SQL_LENGTH
sl@0
    89
  do_test sqllimits1-2.2.2 {
sl@0
    90
    sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH -1
sl@0
    91
  } [expr {$SQLITE_MAX_SQL_LENGTH/2}]
sl@0
    92
}
sl@0
    93
if {$SQLITE_MAX_COLUMN>=2} {
sl@0
    94
  do_test sqllimits1-2.3.1 {
sl@0
    95
    sqlite3_limit db SQLITE_LIMIT_COLUMN \
sl@0
    96
                    [expr {$::SQLITE_MAX_COLUMN/2}]
sl@0
    97
  } $SQLITE_MAX_COLUMN
sl@0
    98
  do_test sqllimits1-2.3.2 {
sl@0
    99
    sqlite3_limit db SQLITE_LIMIT_COLUMN -1
sl@0
   100
  } [expr {$SQLITE_MAX_COLUMN/2}]
sl@0
   101
}
sl@0
   102
if {$SQLITE_MAX_EXPR_DEPTH>=2} {
sl@0
   103
  do_test sqllimits1-2.4.1 {
sl@0
   104
    sqlite3_limit db SQLITE_LIMIT_EXPR_DEPTH \
sl@0
   105
                    [expr {$::SQLITE_MAX_EXPR_DEPTH/2}]
sl@0
   106
  } $SQLITE_MAX_EXPR_DEPTH
sl@0
   107
  do_test sqllimits1-2.4.2 {
sl@0
   108
    sqlite3_limit db SQLITE_LIMIT_EXPR_DEPTH -1
sl@0
   109
  } [expr {$SQLITE_MAX_EXPR_DEPTH/2}]
sl@0
   110
}
sl@0
   111
if {$SQLITE_MAX_COMPOUND_SELECT>=2} {
sl@0
   112
  do_test sqllimits1-2.5.1 {
sl@0
   113
    sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT \
sl@0
   114
                    [expr {$::SQLITE_MAX_COMPOUND_SELECT/2}]
sl@0
   115
  } $SQLITE_MAX_COMPOUND_SELECT
sl@0
   116
  do_test sqllimits1-2.5.2 {
sl@0
   117
    sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT -1
sl@0
   118
  } [expr {$SQLITE_MAX_COMPOUND_SELECT/2}]
sl@0
   119
}
sl@0
   120
if {$SQLITE_MAX_VDBE_OP>=2} {
sl@0
   121
  do_test sqllimits1-2.6.1 {
sl@0
   122
    sqlite3_limit db SQLITE_LIMIT_VDBE_OP \
sl@0
   123
                    [expr {$::SQLITE_MAX_VDBE_OP/2}]
sl@0
   124
  } $SQLITE_MAX_VDBE_OP
sl@0
   125
  do_test sqllimits1-2.6.2 {
sl@0
   126
    sqlite3_limit db SQLITE_LIMIT_VDBE_OP -1
sl@0
   127
  } [expr {$SQLITE_MAX_VDBE_OP/2}]
sl@0
   128
}
sl@0
   129
if {$SQLITE_MAX_FUNCTION_ARG>=2} {
sl@0
   130
  do_test sqllimits1-2.7.1 {
sl@0
   131
    sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG \
sl@0
   132
                    [expr {$::SQLITE_MAX_FUNCTION_ARG/2}]
sl@0
   133
  } $SQLITE_MAX_FUNCTION_ARG
sl@0
   134
  do_test sqllimits1-2.7.2 {
sl@0
   135
    sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG -1
sl@0
   136
  } [expr {$SQLITE_MAX_FUNCTION_ARG/2}]
sl@0
   137
}
sl@0
   138
if {$SQLITE_MAX_ATTACHED>=2} {
sl@0
   139
  do_test sqllimits1-2.8.1 {
sl@0
   140
    sqlite3_limit db SQLITE_LIMIT_ATTACHED \
sl@0
   141
                    [expr {$::SQLITE_MAX_ATTACHED/2}]
sl@0
   142
  } $SQLITE_MAX_ATTACHED
sl@0
   143
  do_test sqllimits1-2.8.2 {
sl@0
   144
    sqlite3_limit db SQLITE_LIMIT_ATTACHED -1
sl@0
   145
  } [expr {$SQLITE_MAX_ATTACHED/2}]
sl@0
   146
}
sl@0
   147
if {$SQLITE_MAX_LIKE_PATTERN_LENGTH>=2} {
sl@0
   148
  do_test sqllimits1-2.9.1 {
sl@0
   149
    sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH \
sl@0
   150
                    [expr {$::SQLITE_MAX_LIKE_PATTERN_LENGTH/2}]
sl@0
   151
  } $SQLITE_MAX_LIKE_PATTERN_LENGTH
sl@0
   152
  do_test sqllimits1-2.9.2 {
sl@0
   153
    sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH -1
sl@0
   154
  } [expr {$SQLITE_MAX_LIKE_PATTERN_LENGTH/2}]
sl@0
   155
}
sl@0
   156
if {$SQLITE_MAX_VARIABLE_NUMBER>=2} {
sl@0
   157
  do_test sqllimits1-2.10.1 {
sl@0
   158
    sqlite3_limit db SQLITE_LIMIT_VARIABLE_NUMBER \
sl@0
   159
                    [expr {$::SQLITE_MAX_VARIABLE_NUMBER/2}]
sl@0
   160
  } $SQLITE_MAX_VARIABLE_NUMBER
sl@0
   161
  do_test sqllimits1-2.10.2 {
sl@0
   162
    sqlite3_limit db SQLITE_LIMIT_VARIABLE_NUMBER -1
sl@0
   163
  } [expr {$SQLITE_MAX_VARIABLE_NUMBER/2}]
sl@0
   164
}
sl@0
   165
sl@0
   166
# In a separate database connection, verify that the limits are unchanged.
sl@0
   167
#
sl@0
   168
do_test sqllimits1-3.1 {
sl@0
   169
  sqlite3_limit db2 SQLITE_LIMIT_LENGTH -1
sl@0
   170
} $SQLITE_MAX_LENGTH
sl@0
   171
do_test sqllimits1-3.2 {
sl@0
   172
  sqlite3_limit db2 SQLITE_LIMIT_SQL_LENGTH -1
sl@0
   173
} $SQLITE_MAX_SQL_LENGTH
sl@0
   174
do_test sqllimits1-3.3 {
sl@0
   175
  sqlite3_limit db2 SQLITE_LIMIT_COLUMN -1
sl@0
   176
} $SQLITE_MAX_COLUMN
sl@0
   177
do_test sqllimits1-3.4 {
sl@0
   178
  sqlite3_limit db2 SQLITE_LIMIT_EXPR_DEPTH -1
sl@0
   179
} $SQLITE_MAX_EXPR_DEPTH
sl@0
   180
do_test sqllimits1-3.5 {
sl@0
   181
  sqlite3_limit db2 SQLITE_LIMIT_COMPOUND_SELECT -1
sl@0
   182
} $SQLITE_MAX_COMPOUND_SELECT
sl@0
   183
do_test sqllimits1-3.6 {
sl@0
   184
  sqlite3_limit db2 SQLITE_LIMIT_VDBE_OP -1
sl@0
   185
} $SQLITE_MAX_VDBE_OP
sl@0
   186
do_test sqllimits1-3.7 {
sl@0
   187
  sqlite3_limit db2 SQLITE_LIMIT_FUNCTION_ARG -1
sl@0
   188
} $SQLITE_MAX_FUNCTION_ARG
sl@0
   189
do_test sqllimits1-3.8 {
sl@0
   190
  sqlite3_limit db2 SQLITE_LIMIT_ATTACHED -1
sl@0
   191
} $SQLITE_MAX_ATTACHED
sl@0
   192
do_test sqllimits1-3.9 {
sl@0
   193
  sqlite3_limit db2 SQLITE_LIMIT_LIKE_PATTERN_LENGTH -1
sl@0
   194
} $SQLITE_MAX_LIKE_PATTERN_LENGTH
sl@0
   195
do_test sqllimits1-3.10 {
sl@0
   196
  sqlite3_limit db2 SQLITE_LIMIT_VARIABLE_NUMBER -1
sl@0
   197
} $SQLITE_MAX_VARIABLE_NUMBER
sl@0
   198
db2 close
sl@0
   199
sl@0
   200
# Attempt to set all limits to the maximum 32-bit integer.  Verify
sl@0
   201
# that the limit does not exceed the compile-time upper bound.
sl@0
   202
#
sl@0
   203
do_test sqllimits1-4.1.1 {
sl@0
   204
  sqlite3_limit db SQLITE_LIMIT_LENGTH 0x7fffffff
sl@0
   205
  sqlite3_limit db SQLITE_LIMIT_LENGTH -1
sl@0
   206
} $SQLITE_MAX_LENGTH
sl@0
   207
do_test sqllimits1-4.2.1 {
sl@0
   208
  sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH 0x7fffffff
sl@0
   209
  sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH -1
sl@0
   210
} $SQLITE_MAX_SQL_LENGTH
sl@0
   211
do_test sqllimits1-4.3.1 {
sl@0
   212
  sqlite3_limit db SQLITE_LIMIT_COLUMN 0x7fffffff
sl@0
   213
  sqlite3_limit db SQLITE_LIMIT_COLUMN -1
sl@0
   214
} $SQLITE_MAX_COLUMN
sl@0
   215
do_test sqllimits1-4.4.1 {
sl@0
   216
  sqlite3_limit db SQLITE_LIMIT_EXPR_DEPTH 0x7fffffff
sl@0
   217
  sqlite3_limit db SQLITE_LIMIT_EXPR_DEPTH -1
sl@0
   218
} $SQLITE_MAX_EXPR_DEPTH
sl@0
   219
do_test sqllimits1-4.5.1 {
sl@0
   220
  sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT 0x7fffffff
sl@0
   221
  sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT -1
sl@0
   222
} $SQLITE_MAX_COMPOUND_SELECT
sl@0
   223
do_test sqllimits1-4.6.1 {
sl@0
   224
  sqlite3_limit db SQLITE_LIMIT_VDBE_OP 0x7fffffff
sl@0
   225
  sqlite3_limit db SQLITE_LIMIT_VDBE_OP -1
sl@0
   226
} $SQLITE_MAX_VDBE_OP
sl@0
   227
do_test sqllimits1-4.7.1 {
sl@0
   228
  sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG 0x7fffffff
sl@0
   229
  sqlite3_limit db SQLITE_LIMIT_FUNCTION_ARG -1
sl@0
   230
} $SQLITE_MAX_FUNCTION_ARG
sl@0
   231
do_test sqllimits1-4.8.1 {
sl@0
   232
  sqlite3_limit db SQLITE_LIMIT_ATTACHED 0x7fffffff
sl@0
   233
  sqlite3_limit db SQLITE_LIMIT_ATTACHED -1
sl@0
   234
} $SQLITE_MAX_ATTACHED
sl@0
   235
do_test sqllimits1-4.9.1 {
sl@0
   236
  sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH 0x7fffffff
sl@0
   237
  sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH -1
sl@0
   238
} $SQLITE_MAX_LIKE_PATTERN_LENGTH
sl@0
   239
do_test sqllimits1-4.10.1 {
sl@0
   240
  sqlite3_limit db SQLITE_LIMIT_VARIABLE_NUMBER 0x7fffffff
sl@0
   241
  sqlite3_limit db SQLITE_LIMIT_VARIABLE_NUMBER -1
sl@0
   242
} $SQLITE_MAX_VARIABLE_NUMBER
sl@0
   243
sl@0
   244
#--------------------------------------------------------------------
sl@0
   245
# Test cases sqllimits1-5.* test that the SQLITE_MAX_LENGTH limit
sl@0
   246
# is enforced.
sl@0
   247
#
sl@0
   248
db close
sl@0
   249
sqlite3 db test.db
sl@0
   250
set LARGESIZE 99999
sl@0
   251
set SQLITE_LIMIT_LENGTH 100000
sl@0
   252
sqlite3_limit db SQLITE_LIMIT_LENGTH $SQLITE_LIMIT_LENGTH
sl@0
   253
sl@0
   254
do_test sqllimits1-5.1.1 {
sl@0
   255
  catchsql { SELECT randomblob(2147483647) }
sl@0
   256
} {1 {string or blob too big}}
sl@0
   257
do_test sqllimits1-5.1.2 {
sl@0
   258
  catchsql { SELECT zeroblob(2147483647) }
sl@0
   259
} {1 {string or blob too big}}
sl@0
   260
sl@0
   261
do_test sqllimits1-5.2 {
sl@0
   262
  catchsql { SELECT LENGTH(randomblob($::LARGESIZE)) }
sl@0
   263
} [list 0 $LARGESIZE]
sl@0
   264
sl@0
   265
do_test sqllimits1-5.3 {
sl@0
   266
  catchsql { SELECT quote(randomblob($::LARGESIZE)) }
sl@0
   267
} {1 {string or blob too big}}
sl@0
   268
sl@0
   269
do_test sqllimits1-5.4 {
sl@0
   270
  catchsql { SELECT LENGTH(zeroblob($::LARGESIZE)) }
sl@0
   271
} [list 0 $LARGESIZE]
sl@0
   272
sl@0
   273
do_test sqllimits1-5.5 {
sl@0
   274
  catchsql { SELECT quote(zeroblob($::LARGESIZE)) }
sl@0
   275
} {1 {string or blob too big}}
sl@0
   276
sl@0
   277
do_test sqllimits1-5.6 {
sl@0
   278
  catchsql { SELECT zeroblob(-1) }
sl@0
   279
} {0 {{}}}
sl@0
   280
sl@0
   281
do_test sqllimits1-5.9 {
sl@0
   282
  set ::str [string repeat A 65537]
sl@0
   283
  set ::rep [string repeat B 65537]
sl@0
   284
  catchsql { SELECT replace($::str, 'A', $::rep) }
sl@0
   285
} {1 {string or blob too big}}
sl@0
   286
sl@0
   287
do_test sqllimits1-5.10 {
sl@0
   288
  set ::str [string repeat %J 2100]
sl@0
   289
  catchsql { SELECT strftime($::str, '2003-10-31') }
sl@0
   290
} {1 {string or blob too big}}
sl@0
   291
sl@0
   292
do_test sqllimits1-5.11 {
sl@0
   293
  set ::str1 [string repeat A [expr {$SQLITE_LIMIT_LENGTH - 10}]]
sl@0
   294
  set ::str2 [string repeat B [expr {$SQLITE_LIMIT_LENGTH - 10}]]
sl@0
   295
  catchsql { SELECT $::str1 || $::str2 }
sl@0
   296
} {1 {string or blob too big}}
sl@0
   297
sl@0
   298
do_test sqllimits1-5.12 {
sl@0
   299
  set ::str1 [string repeat ' [expr {$SQLITE_LIMIT_LENGTH - 10}]]
sl@0
   300
  catchsql { SELECT quote($::str1) }
sl@0
   301
} {1 {string or blob too big}}
sl@0
   302
sl@0
   303
do_test sqllimits1-5.13 {
sl@0
   304
  set ::str1 [string repeat ' [expr {$SQLITE_LIMIT_LENGTH - 10}]]
sl@0
   305
  catchsql { SELECT hex($::str1) }
sl@0
   306
} {1 {string or blob too big}}
sl@0
   307
sl@0
   308
do_test sqllimits1-5.14.1 {
sl@0
   309
  set ::STMT [sqlite3_prepare db "SELECT ?" -1 TAIL]
sl@0
   310
  sqlite3_bind_zeroblob $::STMT 1 [expr {$SQLITE_LIMIT_LENGTH + 1}]
sl@0
   311
} {}
sl@0
   312
do_test sqllimits1-5.14.2 {
sl@0
   313
  sqlite3_step $::STMT 
sl@0
   314
} {SQLITE_ERROR}
sl@0
   315
do_test sqllimits1-5.14.3 {
sl@0
   316
  sqlite3_reset $::STMT 
sl@0
   317
} {SQLITE_TOOBIG}
sl@0
   318
do_test sqllimits1-5.14.4 {
sl@0
   319
  set np1 [expr {$SQLITE_LIMIT_LENGTH + 1}]
sl@0
   320
  set ::str1 [string repeat A $np1]
sl@0
   321
  catch {sqlite3_bind_text $::STMT 1 $::str1 -1} res
sl@0
   322
  set res
sl@0
   323
} {SQLITE_TOOBIG}
sl@0
   324
do_test sqllimits1-5.14.5 {
sl@0
   325
  catch {sqlite3_bind_text16 $::STMT 1 $::str1 -1} res
sl@0
   326
  set res
sl@0
   327
} {SQLITE_TOOBIG}
sl@0
   328
do_test sqllimits1-5.14.6 {
sl@0
   329
  catch {sqlite3_bind_text $::STMT 1 $::str1 $np1} res
sl@0
   330
  set res
sl@0
   331
} {SQLITE_TOOBIG}
sl@0
   332
do_test sqllimits1-5.14.7 {
sl@0
   333
  catch {sqlite3_bind_text16 $::STMT 1 $::str1 $np1} res
sl@0
   334
  set res
sl@0
   335
} {SQLITE_TOOBIG}
sl@0
   336
do_test sqllimits1-5.14.8 {
sl@0
   337
  set n [expr {$np1-1}]
sl@0
   338
  catch {sqlite3_bind_text $::STMT 1 $::str1 $n} res
sl@0
   339
  set res
sl@0
   340
} {}
sl@0
   341
do_test sqllimits1-5.14.9 {
sl@0
   342
  catch {sqlite3_bind_text16 $::STMT 1 $::str1 $n} res
sl@0
   343
  set res
sl@0
   344
} {}
sl@0
   345
sqlite3_finalize $::STMT 
sl@0
   346
sl@0
   347
do_test sqllimits1-5.15 {
sl@0
   348
  execsql {
sl@0
   349
    CREATE TABLE t4(x);
sl@0
   350
    INSERT INTO t4 VALUES(1);
sl@0
   351
    INSERT INTO t4 VALUES(2);
sl@0
   352
    INSERT INTO t4 SELECT 2+x FROM t4;
sl@0
   353
  }
sl@0
   354
  catchsql {
sl@0
   355
    SELECT group_concat(hex(randomblob(20000))) FROM t4;
sl@0
   356
  }
sl@0
   357
} {1 {string or blob too big}}
sl@0
   358
db eval {DROP TABLE t4}
sl@0
   359
sl@0
   360
sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH 0x7fffffff
sl@0
   361
set strvalue [string repeat A $::SQLITE_LIMIT_LENGTH]
sl@0
   362
do_test sqllimits1-5.16 {
sl@0
   363
  catchsql "SELECT '$strvalue'"
sl@0
   364
} [list 0 $strvalue]
sl@0
   365
do_test sqllimits1-5.17.1 {
sl@0
   366
  catchsql "SELECT 'A$strvalue'"
sl@0
   367
} [list 1 {string or blob too big}]
sl@0
   368
do_test sqllimits1-5.17.2 {
sl@0
   369
  sqlite3_limit db SQLITE_LIMIT_LENGTH 0x7fffffff
sl@0
   370
  catchsql {SELECT 'A' || $::strvalue}
sl@0
   371
} [list 0 A$strvalue]
sl@0
   372
do_test sqllimits1-5.17.3 {
sl@0
   373
  sqlite3_limit db SQLITE_LIMIT_LENGTH $SQLITE_LIMIT_LENGTH
sl@0
   374
  catchsql {SELECT 'A' || $::strvalue}
sl@0
   375
} [list 1 {string or blob too big}]
sl@0
   376
set blobvalue [string repeat 41 $::SQLITE_LIMIT_LENGTH]
sl@0
   377
do_test sqllimits1-5.18 {
sl@0
   378
  catchsql "SELECT x'$blobvalue'"
sl@0
   379
} [list 0 $strvalue]
sl@0
   380
do_test sqllimits1-5.19 {
sl@0
   381
  catchsql "SELECT '41$blobvalue'"
sl@0
   382
} [list 1 {string or blob too big}]
sl@0
   383
unset blobvalue
sl@0
   384
sl@0
   385
ifcapable datetime {
sl@0
   386
  set strvalue [string repeat D [expr {$SQLITE_LIMIT_LENGTH-12}]]
sl@0
   387
  do_test sqllimits1-5.20 {
sl@0
   388
    catchsql {SELECT strftime('%Y ' || $::strvalue, '2008-01-02')}
sl@0
   389
  } [list 0 [list "2008 $strvalue"]]
sl@0
   390
  do_test sqllimits1-5.21 {
sl@0
   391
    catchsql {SELECT strftime('%Y-%m-%d ' || $::strvalue, '2008-01-02')}
sl@0
   392
  } {1 {string or blob too big}}
sl@0
   393
}
sl@0
   394
unset strvalue
sl@0
   395
sl@0
   396
#--------------------------------------------------------------------
sl@0
   397
# Test cases sqllimits1-6.* test that the SQLITE_MAX_SQL_LENGTH limit
sl@0
   398
# is enforced.
sl@0
   399
#
sl@0
   400
# Symbian OS: the next test fails because the max expression depth is limited to 250. 
sl@0
   401
if {$::tcl_platform(platform)!="symbian"} {
sl@0
   402
  do_test sqllimits1-6.1 {
sl@0
   403
    sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH 50000
sl@0
   404
    set sql "SELECT 1 WHERE 1==1"
sl@0
   405
    set tail " /* A comment to take up space in order to make the string\
sl@0
   406
                  longer without increasing the expression depth */\
sl@0
   407
                  AND   1  ==  1"
sl@0
   408
    set N [expr {(50000 / [string length $tail])+1}]
sl@0
   409
    append sql [string repeat $tail $N]
sl@0
   410
    catchsql $sql
sl@0
   411
  } {1 {String or BLOB exceeded size limit}}
sl@0
   412
}
sl@0
   413
do_test sqllimits1-6.3 {
sl@0
   414
  sqlite3_limit db SQLITE_LIMIT_SQL_LENGTH 50000
sl@0
   415
  set sql "SELECT 1 WHERE 1==1"
sl@0
   416
  set tail " /* A comment to take up space in order to make the string\
sl@0
   417
                longer without increasing the expression depth */\
sl@0
   418
                AND   1  ==  1"
sl@0
   419
  set N [expr {(50000 / [string length $tail])+1}]
sl@0
   420
  append sql [string repeat $tail $N]
sl@0
   421
  set nbytes [string length $sql]
sl@0
   422
  append sql { AND 0}
sl@0
   423
  set rc [catch {sqlite3_prepare db $sql $nbytes TAIL} STMT]
sl@0
   424
  lappend rc $STMT
sl@0
   425
} {1 {(18) statement too long}}
sl@0
   426
do_test sqllimits1-6.4 {
sl@0
   427
  sqlite3_errmsg db
sl@0
   428
} {statement too long}
sl@0
   429
sl@0
   430
#--------------------------------------------------------------------
sl@0
   431
# Test cases sqllimits1-7.* test that the limit set using the
sl@0
   432
# max_page_count pragma.
sl@0
   433
#
sl@0
   434
do_test sqllimits1-7.1 {
sl@0
   435
  execsql {
sl@0
   436
    PRAGMA max_page_count = 1000;
sl@0
   437
  }
sl@0
   438
} {1000}
sl@0
   439
do_test sqllimits1-7.2 {
sl@0
   440
  execsql { CREATE TABLE trig (a INTEGER, b INTEGER); }
sl@0
   441
sl@0
   442
  # Set up a tree of triggers to fire when a row is inserted
sl@0
   443
  # into table "trig".
sl@0
   444
  #
sl@0
   445
  # INSERT -> insert_b -> update_b -> insert_a -> update_a      (chain 1)
sl@0
   446
  #                    -> update_a -> insert_a -> update_b      (chain 2)
sl@0
   447
  #        -> insert_a -> update_b -> insert_b -> update_a      (chain 3)
sl@0
   448
  #                    -> update_a -> insert_b -> update_b      (chain 4)
sl@0
   449
  #
sl@0
   450
  # Table starts with N rows.
sl@0
   451
  #
sl@0
   452
  #   Chain 1: insert_b (update N rows)
sl@0
   453
  #              -> update_b (insert 1 rows)
sl@0
   454
  #                -> insert_a (update N rows)
sl@0
   455
  #                  -> update_a (insert 1 rows)
sl@0
   456
  #
sl@0
   457
  # chains 2, 3 and 4 are similar. Each inserts more than N^2 rows, where
sl@0
   458
  # N is the number of rows at the conclusion of the previous chain.
sl@0
   459
  #
sl@0
   460
  # Therefore, a single insert adds (N^16 plus some) rows to the database.
sl@0
   461
  # A really long loop...
sl@0
   462
  #     
sl@0
   463
  execsql {
sl@0
   464
    CREATE TRIGGER update_b BEFORE UPDATE ON trig
sl@0
   465
      FOR EACH ROW BEGIN
sl@0
   466
        INSERT INTO trig VALUES (65, 'update_b');
sl@0
   467
      END;
sl@0
   468
sl@0
   469
    CREATE TRIGGER update_a AFTER UPDATE ON trig
sl@0
   470
      FOR EACH ROW BEGIN
sl@0
   471
        INSERT INTO trig VALUES (65, 'update_a');
sl@0
   472
      END;
sl@0
   473
sl@0
   474
    CREATE TRIGGER insert_b BEFORE INSERT ON trig
sl@0
   475
      FOR EACH ROW BEGIN
sl@0
   476
        UPDATE trig SET a = 1;
sl@0
   477
      END;
sl@0
   478
sl@0
   479
    CREATE TRIGGER insert_a AFTER INSERT ON trig
sl@0
   480
      FOR EACH ROW BEGIN
sl@0
   481
        UPDATE trig SET a = 1;
sl@0
   482
      END;
sl@0
   483
  }
sl@0
   484
} {}
sl@0
   485
sl@0
   486
do_test sqllimits1-7.3 {
sl@0
   487
  execsql {
sl@0
   488
    INSERT INTO trig VALUES (1,1); 
sl@0
   489
  }
sl@0
   490
} {}
sl@0
   491
sl@0
   492
do_test sqllimits1-7.4 {
sl@0
   493
  execsql {
sl@0
   494
    SELECT COUNT(*) FROM trig;
sl@0
   495
  }
sl@0
   496
} {7}
sl@0
   497
sl@0
   498
# This tries to insert so many rows it fills up the database (limited
sl@0
   499
# to 1MB, so not that noteworthy an achievement).
sl@0
   500
#
sl@0
   501
do_test sqllimits1-7.5 {
sl@0
   502
  catchsql {
sl@0
   503
    INSERT INTO trig VALUES (1,10);
sl@0
   504
  }
sl@0
   505
} {1 {database or disk is full}}
sl@0
   506
sl@0
   507
do_test sqllimits1-7.6 {
sl@0
   508
  catchsql {
sl@0
   509
    SELECT COUNT(*) FROM trig;
sl@0
   510
  }
sl@0
   511
} {0 7}
sl@0
   512
sl@0
   513
# Now check the response of the library to opening a file larger than
sl@0
   514
# the current max_page_count value. The response is to change the
sl@0
   515
# internal max_page_count value to match the actual size of the file.
sl@0
   516
if {[db eval {PRAGMA auto_vacuum}]} {
sl@0
   517
   set fsize 1700
sl@0
   518
} else {
sl@0
   519
   set fsize 1691
sl@0
   520
}
sl@0
   521
do_test sqllimits1-7.7.1 {
sl@0
   522
  execsql {
sl@0
   523
    PRAGMA max_page_count = 1000000;
sl@0
   524
    CREATE TABLE abc(a, b, c);
sl@0
   525
    INSERT INTO abc VALUES(1, 2, 3);
sl@0
   526
    INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
sl@0
   527
    INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
sl@0
   528
    INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
sl@0
   529
    INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
sl@0
   530
    INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
sl@0
   531
    INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
sl@0
   532
    INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
sl@0
   533
    INSERT INTO abc SELECT a||b||c, b||c||a, c||a||b FROM abc;
sl@0
   534
    INSERT INTO abc SELECT a, b, c FROM abc;
sl@0
   535
    INSERT INTO abc SELECT b, a, c FROM abc;
sl@0
   536
    INSERT INTO abc SELECT c, b, a FROM abc;
sl@0
   537
  }
sl@0
   538
  expr [file size test.db] / 1024
sl@0
   539
} $fsize
sl@0
   540
do_test sqllimits1-7.7.2 {
sl@0
   541
  db close
sl@0
   542
  sqlite3 db test.db
sl@0
   543
  execsql {
sl@0
   544
    PRAGMA max_page_count = 1000;
sl@0
   545
  }
sl@0
   546
  execsql {
sl@0
   547
    SELECT count(*) FROM sqlite_master;
sl@0
   548
  }
sl@0
   549
} {6}
sl@0
   550
do_test sqllimits1-7.7.3 {
sl@0
   551
  execsql {
sl@0
   552
    PRAGMA max_page_count;
sl@0
   553
  }
sl@0
   554
} $fsize
sl@0
   555
do_test sqllimits1-7.7.4 {
sl@0
   556
  execsql {
sl@0
   557
    DROP TABLE abc;
sl@0
   558
  }
sl@0
   559
} {}
sl@0
   560
sl@0
   561
#--------------------------------------------------------------------
sl@0
   562
# Test cases sqllimits1-8.* test the SQLITE_MAX_COLUMN limit.
sl@0
   563
#
sl@0
   564
set SQLITE_LIMIT_COLUMN 200
sl@0
   565
sqlite3_limit db SQLITE_LIMIT_COLUMN $SQLITE_LIMIT_COLUMN
sl@0
   566
do_test sqllimits1-8.1 {
sl@0
   567
  # Columns in a table.
sl@0
   568
  set cols [list]
sl@0
   569
  for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
sl@0
   570
    lappend cols "c$i"
sl@0
   571
  }
sl@0
   572
  catchsql "CREATE TABLE t([join $cols ,])" 
sl@0
   573
} {1 {too many columns on t}}
sl@0
   574
sl@0
   575
do_test sqllimits1-8.2 {
sl@0
   576
  # Columns in the result-set of a SELECT.
sl@0
   577
  set cols [list]
sl@0
   578
  for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
sl@0
   579
    lappend cols "sql AS sql$i"
sl@0
   580
  }
sl@0
   581
  catchsql "SELECT [join $cols ,] FROM sqlite_master"
sl@0
   582
} {1 {too many columns in result set}}
sl@0
   583
sl@0
   584
do_test sqllimits1-8.3 {
sl@0
   585
  # Columns in the result-set of a sub-SELECT.
sl@0
   586
  set cols [list]
sl@0
   587
  for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
sl@0
   588
    lappend cols "sql AS sql$i"
sl@0
   589
  }
sl@0
   590
  catchsql "SELECT sql4 FROM (SELECT [join $cols ,] FROM sqlite_master)"
sl@0
   591
} {1 {too many columns in result set}}
sl@0
   592
sl@0
   593
do_test sqllimits1-8.4 {
sl@0
   594
  # Columns in an index.
sl@0
   595
  set cols [list]
sl@0
   596
  for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
sl@0
   597
    lappend cols c
sl@0
   598
  }
sl@0
   599
  set sql1 "CREATE TABLE t1(c);"
sl@0
   600
  set sql2 "CREATE INDEX i1 ON t1([join $cols ,]);"
sl@0
   601
  catchsql "$sql1 ; $sql2"
sl@0
   602
} {1 {too many columns in index}}
sl@0
   603
sl@0
   604
do_test sqllimits1-8.5 {
sl@0
   605
  # Columns in a GROUP BY clause.
sl@0
   606
  catchsql "SELECT * FROM t1 GROUP BY [join $cols ,]"
sl@0
   607
} {1 {too many terms in GROUP BY clause}}
sl@0
   608
sl@0
   609
do_test sqllimits1-8.6 {
sl@0
   610
  # Columns in an ORDER BY clause.
sl@0
   611
  catchsql "SELECT * FROM t1 ORDER BY [join $cols ,]"
sl@0
   612
} {1 {too many terms in ORDER BY clause}}
sl@0
   613
sl@0
   614
do_test sqllimits1-8.7 {
sl@0
   615
  # Assignments in an UPDATE statement.
sl@0
   616
  set cols [list]
sl@0
   617
  for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
sl@0
   618
    lappend cols "c = 1"
sl@0
   619
  }
sl@0
   620
  catchsql "UPDATE t1 SET [join $cols ,];"
sl@0
   621
} {1 {too many columns in set list}}
sl@0
   622
sl@0
   623
do_test sqllimits1-8.8 {
sl@0
   624
  # Columns in a view definition:
sl@0
   625
  set cols [list]
sl@0
   626
  for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
sl@0
   627
    lappend cols "c$i"
sl@0
   628
  }
sl@0
   629
  catchsql "CREATE VIEW v1 AS SELECT [join $cols ,] FROM t1;"
sl@0
   630
} {1 {too many columns in result set}}
sl@0
   631
sl@0
   632
do_test sqllimits1-8.9 {
sl@0
   633
  # Columns in a view definition (testing * expansion):
sl@0
   634
  set cols [list]
sl@0
   635
  for {set i 0} {$i < $SQLITE_LIMIT_COLUMN} {incr i} {
sl@0
   636
    lappend cols "c$i"
sl@0
   637
  }
sl@0
   638
  catchsql "CREATE TABLE t2([join $cols ,])"
sl@0
   639
  catchsql "CREATE VIEW v1 AS SELECT *, c1 AS o FROM t2;"
sl@0
   640
} {1 {too many columns in result set}}
sl@0
   641
do_test sqllimits1-8.10 {
sl@0
   642
  # ORDER BY columns
sl@0
   643
  set cols [list]
sl@0
   644
  for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
sl@0
   645
    lappend cols c
sl@0
   646
  }
sl@0
   647
  set sql "SELECT c FROM t1 ORDER BY [join $cols ,]"
sl@0
   648
  catchsql $sql
sl@0
   649
} {1 {too many terms in ORDER BY clause}}
sl@0
   650
do_test sqllimits1-8.11 {
sl@0
   651
  # ORDER BY columns
sl@0
   652
  set cols [list]
sl@0
   653
  for {set i 0} {$i <= $SQLITE_LIMIT_COLUMN} {incr i} {
sl@0
   654
    lappend cols [expr {$i%3 + 1}]
sl@0
   655
  }
sl@0
   656
  set sql "SELECT c, c+1, c+2 FROM t1 UNION SELECT c-1, c-2, c-3 FROM t1"
sl@0
   657
  append sql " ORDER BY [join $cols ,]"
sl@0
   658
  catchsql $sql
sl@0
   659
} {1 {too many terms in ORDER BY clause}}
sl@0
   660
sl@0
   661
sl@0
   662
#--------------------------------------------------------------------
sl@0
   663
# These tests - sqllimits1-9.* - test that the SQLITE_LIMIT_EXPR_DEPTH
sl@0
   664
# limit is enforced. The limit refers to the number of terms in 
sl@0
   665
# the expression.
sl@0
   666
#
sl@0
   667
if {$SQLITE_MAX_EXPR_DEPTH==0} {
sl@0
   668
  puts -nonewline stderr "WARNING: Compile with -DSQLITE_MAX_EXPR_DEPTH to run "
sl@0
   669
  puts stderr "tests sqllimits1-9.X"
sl@0
   670
} else {
sl@0
   671
  do_test sqllimits1-9.1 {
sl@0
   672
    set max $::SQLITE_MAX_EXPR_DEPTH
sl@0
   673
    set expr "(1 [string repeat {AND 1 } $max])"
sl@0
   674
    catchsql [subst {
sl@0
   675
      SELECT $expr
sl@0
   676
    }]
sl@0
   677
  } "1 {Expression tree is too large (maximum depth $::SQLITE_MAX_EXPR_DEPTH)}"
sl@0
   678
  
sl@0
   679
  # Attempting to beat the expression depth limit using nested SELECT
sl@0
   680
  # queries causes a parser stack overflow. 
sl@0
   681
  do_test sqllimits1-9.2 {
sl@0
   682
    set max $::SQLITE_MAX_EXPR_DEPTH
sl@0
   683
    set expr "SELECT 1"
sl@0
   684
    for {set i 0} {$i <= $max} {incr i} {
sl@0
   685
      set expr "SELECT ($expr)"
sl@0
   686
    }
sl@0
   687
    catchsql [subst { $expr }]
sl@0
   688
  } "1 {parser stack overflow}"
sl@0
   689
  
sl@0
   690
if 0 {  
sl@0
   691
  do_test sqllimits1-9.3 {
sl@0
   692
    execsql {
sl@0
   693
      PRAGMA max_page_count = 1000000;  -- 1 GB
sl@0
   694
      CREATE TABLE v0(a);
sl@0
   695
      INSERT INTO v0 VALUES(1);
sl@0
   696
    }
sl@0
   697
    db transaction {
sl@0
   698
      for {set i 1} {$i < 200} {incr i} {
sl@0
   699
        set expr "(a [string repeat {AND 1 } 50]) AS a"
sl@0
   700
        execsql [subst {
sl@0
   701
          CREATE VIEW v${i} AS SELECT $expr FROM v[expr {$i-1}]
sl@0
   702
        }]
sl@0
   703
      }
sl@0
   704
    }
sl@0
   705
  } {}
sl@0
   706
  
sl@0
   707
  do_test sqllimits1-9.4 {
sl@0
   708
    catchsql {
sl@0
   709
      SELECT a FROM v199
sl@0
   710
    }
sl@0
   711
  } "1 {Expression tree is too large (maximum depth $::SQLITE_MAX_EXPR_DEPTH)}"
sl@0
   712
}
sl@0
   713
}
sl@0
   714
sl@0
   715
#--------------------------------------------------------------------
sl@0
   716
# Test cases sqllimits1-10.* test that the SQLITE_MAX_VDBE_OP
sl@0
   717
# limit works as expected. The limit refers to the number of opcodes
sl@0
   718
# in a single VDBE program.
sl@0
   719
#
sl@0
   720
# TODO
sl@0
   721
sl@0
   722
#--------------------------------------------------------------------
sl@0
   723
# Test the SQLITE_LIMIT_FUNCTION_ARG limit works. Test case names
sl@0
   724
# match the pattern "sqllimits1-11.*".
sl@0
   725
#
sl@0
   726
do_test sqllimits1-11.1 {
sl@0
   727
  set max $::SQLITE_MAX_FUNCTION_ARG
sl@0
   728
  set vals [list]
sl@0
   729
  for {set i 0} {$i < $SQLITE_MAX_FUNCTION_ARG} {incr i} {
sl@0
   730
    lappend vals $i
sl@0
   731
  }
sl@0
   732
  catchsql "SELECT max([join $vals ,])"
sl@0
   733
} "0 [expr {$::SQLITE_MAX_FUNCTION_ARG - 1}]"
sl@0
   734
do_test sqllimits1-11.2 {
sl@0
   735
  set max $::SQLITE_MAX_FUNCTION_ARG
sl@0
   736
  set vals [list]
sl@0
   737
  for {set i 0} {$i <= $SQLITE_MAX_FUNCTION_ARG} {incr i} {
sl@0
   738
    lappend vals $i
sl@0
   739
  }
sl@0
   740
  catchsql "SELECT max([join $vals ,])"
sl@0
   741
} {1 {too many arguments on function max}}
sl@0
   742
sl@0
   743
# Test that it is SQLite, and not the implementation of the
sl@0
   744
# user function that is throwing the error.
sl@0
   745
proc myfunc {args} {error "I don't like to be called!"}
sl@0
   746
do_test sqllimits1-11.2 {
sl@0
   747
  db function myfunc myfunc
sl@0
   748
  set max $::SQLITE_MAX_FUNCTION_ARG
sl@0
   749
  set vals [list]
sl@0
   750
  for {set i 0} {$i <= $SQLITE_MAX_FUNCTION_ARG} {incr i} {
sl@0
   751
    lappend vals $i
sl@0
   752
  }
sl@0
   753
  catchsql "SELECT myfunc([join $vals ,])"
sl@0
   754
} {1 {too many arguments on function myfunc}}
sl@0
   755
sl@0
   756
sl@0
   757
#--------------------------------------------------------------------
sl@0
   758
# Test cases sqllimits1-12.*: Test the SQLITE_MAX_ATTACHED limit.
sl@0
   759
#
sl@0
   760
ifcapable attach {
sl@0
   761
  do_test sqllimits1-12.1 {
sl@0
   762
    set max $::SQLITE_MAX_ATTACHED
sl@0
   763
    for {set i 0} {$i < ($max)} {incr i} {
sl@0
   764
      file delete -force test${i}.db test${i}.db-journal
sl@0
   765
    }
sl@0
   766
    for {set i 0} {$i < ($max)} {incr i} {
sl@0
   767
      execsql "ATTACH 'test${i}.db' AS aux${i}"
sl@0
   768
    }
sl@0
   769
    catchsql "ATTACH 'test${i}.db' AS aux${i}"
sl@0
   770
  } "1 {too many attached databases - max $::SQLITE_MAX_ATTACHED}"
sl@0
   771
  do_test sqllimits1-12.2 {
sl@0
   772
    set max $::SQLITE_MAX_ATTACHED
sl@0
   773
    for {set i 0} {$i < ($max)} {incr i} {
sl@0
   774
      execsql "DETACH aux${i}"
sl@0
   775
    }
sl@0
   776
  } {}
sl@0
   777
}
sl@0
   778
sl@0
   779
#--------------------------------------------------------------------
sl@0
   780
# Test cases sqllimits1-13.*: Check that the SQLITE_MAX_VARIABLE_NUMBER 
sl@0
   781
# limit works.
sl@0
   782
#
sl@0
   783
do_test sqllimits1-13.1 {
sl@0
   784
  set max $::SQLITE_MAX_VARIABLE_NUMBER
sl@0
   785
  catchsql "SELECT ?[expr {$max+1}] FROM t1"
sl@0
   786
} "1 {variable number must be between ?1 and ?$::SQLITE_MAX_VARIABLE_NUMBER}"
sl@0
   787
do_test sqllimits1-13.2 {
sl@0
   788
  set max $::SQLITE_MAX_VARIABLE_NUMBER
sl@0
   789
  set vals [list]
sl@0
   790
  for {set i 0} {$i < ($max+3)} {incr i} {
sl@0
   791
    lappend vals ?
sl@0
   792
  }
sl@0
   793
  catchsql "SELECT [join $vals ,] FROM t1"
sl@0
   794
} "1 {too many SQL variables}"
sl@0
   795
sl@0
   796
sl@0
   797
#--------------------------------------------------------------------
sl@0
   798
# Test cases sqllimits1-15.* verify that the 
sl@0
   799
# SQLITE_MAX_LIKE_PATTERN_LENGTH limit is enforced. This limit only
sl@0
   800
# applies to the built-in LIKE operator, supplying an external 
sl@0
   801
# implementation by overriding the like() scalar function bypasses
sl@0
   802
# this limitation.
sl@0
   803
#
sl@0
   804
# These tests check that the limit is not incorrectly applied to
sl@0
   805
# the left-hand-side of the LIKE operator (the string being tested
sl@0
   806
# against the pattern).
sl@0
   807
#
sl@0
   808
set SQLITE_LIMIT_LIKE_PATTERN 1000
sl@0
   809
sqlite3_limit db SQLITE_LIMIT_LIKE_PATTERN_LENGTH $SQLITE_LIMIT_LIKE_PATTERN
sl@0
   810
do_test sqllimits1-15.1 {
sl@0
   811
  set max $::SQLITE_LIMIT_LIKE_PATTERN
sl@0
   812
  set ::pattern [string repeat "A%" [expr $max/2]]
sl@0
   813
  set ::string  [string repeat "A" [expr {$max*2}]]
sl@0
   814
  execsql {
sl@0
   815
    SELECT $::string LIKE $::pattern;
sl@0
   816
  }
sl@0
   817
} {1}
sl@0
   818
do_test sqllimits1-15.2 {
sl@0
   819
  set max $::SQLITE_LIMIT_LIKE_PATTERN
sl@0
   820
  set ::pattern [string repeat "A%" [expr {($max/2) + 1}]]
sl@0
   821
  set ::string  [string repeat "A" [expr {$max*2}]]
sl@0
   822
  catchsql {
sl@0
   823
    SELECT $::string LIKE $::pattern;
sl@0
   824
  }
sl@0
   825
} {1 {LIKE or GLOB pattern too complex}}
sl@0
   826
sl@0
   827
#--------------------------------------------------------------------
sl@0
   828
# This test case doesn't really belong with the other limits tests.
sl@0
   829
# It is in this file because it is taxing to run, like the limits tests.
sl@0
   830
#
sl@0
   831
do_test sqllimits1-16.1 {
sl@0
   832
  set ::N [expr int(([expr pow(2,32)]/50) + 1)]
sl@0
   833
  expr (($::N*50) & 0xffffffff)<55
sl@0
   834
} {1}
sl@0
   835
#
sl@0
   836
# Symbian: This test case is crashing tclsqlite3.exe if uncommented.
sl@0
   837
#
sl@0
   838
if {$tcl_platform(platform)!="symbian"} {
sl@0
   839
  do_test sqllimits1-16.2 {
sl@0
   840
    set ::format "[string repeat A 60][string repeat "%J" $::N]"
sl@0
   841
    catchsql {
sl@0
   842
      SELECT strftime($::format, 1);
sl@0
   843
    }
sl@0
   844
  } {1 {string or blob too big}}
sl@0
   845
}
sl@0
   846
sl@0
   847
foreach {key value} [array get saved] {
sl@0
   848
  catch {set $key $value}
sl@0
   849
}
sl@0
   850
finish_test