os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/limit.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
# 2001 November 6
sl@0
     2
#
sl@0
     3
# The author disclaims copyright to this source code.  In place of
sl@0
     4
# a legal notice, here is a blessing:
sl@0
     5
#
sl@0
     6
#    May you do good and not evil.
sl@0
     7
#    May you find forgiveness for yourself and forgive others.
sl@0
     8
#    May you share freely, never taking more than you give.
sl@0
     9
#
sl@0
    10
#***********************************************************************
sl@0
    11
# This file implements regression tests for SQLite library.  The
sl@0
    12
# focus of this file is testing the LIMIT ... OFFSET ... clause
sl@0
    13
#  of SELECT statements.
sl@0
    14
#
sl@0
    15
# $Id: limit.test,v 1.32 2008/08/02 03:50:39 drh Exp $
sl@0
    16
sl@0
    17
set testdir [file dirname $argv0]
sl@0
    18
source $testdir/tester.tcl
sl@0
    19
sl@0
    20
# Build some test data
sl@0
    21
#
sl@0
    22
execsql {
sl@0
    23
  CREATE TABLE t1(x int, y int);
sl@0
    24
  BEGIN;
sl@0
    25
}
sl@0
    26
for {set i 1} {$i<=32} {incr i} {
sl@0
    27
  for {set j 0} {(1<<$j)<$i} {incr j} {}
sl@0
    28
  execsql "INSERT INTO t1 VALUES([expr {32-$i}],[expr {10-$j}])"
sl@0
    29
}
sl@0
    30
execsql {
sl@0
    31
  COMMIT;
sl@0
    32
}
sl@0
    33
sl@0
    34
do_test limit-1.0 {
sl@0
    35
  execsql {SELECT count(*) FROM t1}
sl@0
    36
} {32}
sl@0
    37
do_test limit-1.1 {
sl@0
    38
  execsql {SELECT count(*) FROM t1 LIMIT  5}
sl@0
    39
} {32}
sl@0
    40
do_test limit-1.2.1 {
sl@0
    41
  execsql {SELECT x FROM t1 ORDER BY x LIMIT 5}
sl@0
    42
} {0 1 2 3 4}
sl@0
    43
do_test limit-1.2.2 {
sl@0
    44
  execsql {SELECT x FROM t1 ORDER BY x LIMIT 5 OFFSET 2}
sl@0
    45
} {2 3 4 5 6}
sl@0
    46
do_test limit-1.2.3 {
sl@0
    47
  execsql {SELECT x FROM t1 ORDER BY x+1 LIMIT 5 OFFSET -2}
sl@0
    48
} {0 1 2 3 4}
sl@0
    49
do_test limit-1.2.4 {
sl@0
    50
  execsql {SELECT x FROM t1 ORDER BY x+1 LIMIT 2, -5}
sl@0
    51
} {2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31}
sl@0
    52
do_test limit-1.2.5 {
sl@0
    53
  execsql {SELECT x FROM t1 ORDER BY x+1 LIMIT -2, 5}
sl@0
    54
} {0 1 2 3 4}
sl@0
    55
do_test limit-1.2.6 {
sl@0
    56
  execsql {SELECT x FROM t1 ORDER BY x+1 LIMIT -2, -5}
sl@0
    57
} {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31}
sl@0
    58
do_test limit-1.2.7 {
sl@0
    59
  execsql {SELECT x FROM t1 ORDER BY x LIMIT 2, 5}
sl@0
    60
} {2 3 4 5 6}
sl@0
    61
do_test limit-1.3 {
sl@0
    62
  execsql {SELECT x FROM t1 ORDER BY x LIMIT 5 OFFSET 5}
sl@0
    63
} {5 6 7 8 9}
sl@0
    64
do_test limit-1.4.1 {
sl@0
    65
  execsql {SELECT x FROM t1 ORDER BY x LIMIT 50 OFFSET 30}
sl@0
    66
} {30 31}
sl@0
    67
do_test limit-1.4.2 {
sl@0
    68
  execsql {SELECT x FROM t1 ORDER BY x LIMIT 30, 50}
sl@0
    69
} {30 31}
sl@0
    70
do_test limit-1.5 {
sl@0
    71
  execsql {SELECT x FROM t1 ORDER BY x LIMIT 50 OFFSET 50}
sl@0
    72
} {}
sl@0
    73
do_test limit-1.6 {
sl@0
    74
  execsql {SELECT * FROM t1 AS a, t1 AS b ORDER BY a.x, b.x LIMIT 5}
sl@0
    75
} {0 5 0 5 0 5 1 5 0 5 2 5 0 5 3 5 0 5 4 5}
sl@0
    76
do_test limit-1.7 {
sl@0
    77
  execsql {SELECT * FROM t1 AS a, t1 AS b ORDER BY a.x, b.x LIMIT 5 OFFSET 32}
sl@0
    78
} {1 5 0 5 1 5 1 5 1 5 2 5 1 5 3 5 1 5 4 5}
sl@0
    79
sl@0
    80
ifcapable {view && subquery} {
sl@0
    81
  do_test limit-2.1 {
sl@0
    82
    execsql {
sl@0
    83
      CREATE VIEW v1 AS SELECT * FROM t1 LIMIT 2;
sl@0
    84
      SELECT count(*) FROM (SELECT * FROM v1);
sl@0
    85
    }
sl@0
    86
  } 2
sl@0
    87
} ;# ifcapable view
sl@0
    88
do_test limit-2.2 {
sl@0
    89
  execsql {
sl@0
    90
    CREATE TABLE t2 AS SELECT * FROM t1 LIMIT 2;
sl@0
    91
    SELECT count(*) FROM t2;
sl@0
    92
  }
sl@0
    93
} 2
sl@0
    94
ifcapable subquery {
sl@0
    95
  do_test limit-2.3 {
sl@0
    96
    execsql {
sl@0
    97
      SELECT count(*) FROM t1 WHERE rowid IN (SELECT rowid FROM t1 LIMIT 2);
sl@0
    98
    }
sl@0
    99
  } 2
sl@0
   100
}
sl@0
   101
sl@0
   102
ifcapable subquery {
sl@0
   103
  do_test limit-3.1 {
sl@0
   104
    execsql {
sl@0
   105
      SELECT z FROM (SELECT y*10+x AS z FROM t1 ORDER BY x LIMIT 10)
sl@0
   106
      ORDER BY z LIMIT 5;
sl@0
   107
    }
sl@0
   108
  } {50 51 52 53 54}
sl@0
   109
}
sl@0
   110
sl@0
   111
do_test limit-4.1 {
sl@0
   112
  ifcapable subquery { 
sl@0
   113
    execsql {
sl@0
   114
      BEGIN;
sl@0
   115
      CREATE TABLE t3(x);
sl@0
   116
      INSERT INTO t3 SELECT x FROM t1 ORDER BY x LIMIT 10 OFFSET 1;
sl@0
   117
      INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
sl@0
   118
      INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
sl@0
   119
      INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
sl@0
   120
      INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
sl@0
   121
      INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
sl@0
   122
      INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
sl@0
   123
      INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
sl@0
   124
      INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
sl@0
   125
      INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
sl@0
   126
      INSERT INTO t3 SELECT x+(SELECT max(x) FROM t3) FROM t3;
sl@0
   127
      END;
sl@0
   128
      SELECT count(*) FROM t3;
sl@0
   129
    }
sl@0
   130
  } else {
sl@0
   131
    execsql {
sl@0
   132
      BEGIN;
sl@0
   133
      CREATE TABLE t3(x);
sl@0
   134
      INSERT INTO t3 SELECT x FROM t1 ORDER BY x LIMIT 10 OFFSET 1;
sl@0
   135
    }
sl@0
   136
    for {set i 0} {$i<10} {incr i} {
sl@0
   137
      set max_x_t3 [execsql {SELECT max(x) FROM t3}]
sl@0
   138
      execsql "INSERT INTO t3 SELECT x+$max_x_t3 FROM t3;"
sl@0
   139
    }
sl@0
   140
    execsql {
sl@0
   141
      END;
sl@0
   142
      SELECT count(*) FROM t3;
sl@0
   143
    }
sl@0
   144
  }
sl@0
   145
} {10240}
sl@0
   146
do_test limit-4.2 {
sl@0
   147
  execsql {
sl@0
   148
    SELECT x FROM t3 LIMIT 2 OFFSET 10000
sl@0
   149
  }
sl@0
   150
} {10001 10002}
sl@0
   151
do_test limit-4.3 {
sl@0
   152
  execsql {
sl@0
   153
    CREATE TABLE t4 AS SELECT x,
sl@0
   154
       'abcdefghijklmnopqrstuvwyxz ABCDEFGHIJKLMNOPQRSTUVWYXZ' || x ||
sl@0
   155
       'abcdefghijklmnopqrstuvwyxz ABCDEFGHIJKLMNOPQRSTUVWYXZ' || x ||
sl@0
   156
       'abcdefghijklmnopqrstuvwyxz ABCDEFGHIJKLMNOPQRSTUVWYXZ' || x ||
sl@0
   157
       'abcdefghijklmnopqrstuvwyxz ABCDEFGHIJKLMNOPQRSTUVWYXZ' || x ||
sl@0
   158
       'abcdefghijklmnopqrstuvwyxz ABCDEFGHIJKLMNOPQRSTUVWYXZ' || x AS y
sl@0
   159
    FROM t3 LIMIT 1000;
sl@0
   160
    SELECT x FROM t4 ORDER BY y DESC LIMIT 1 OFFSET 999;
sl@0
   161
  }
sl@0
   162
} {1000}
sl@0
   163
sl@0
   164
do_test limit-5.1 {
sl@0
   165
  execsql {
sl@0
   166
    CREATE TABLE t5(x,y);
sl@0
   167
    INSERT INTO t5 SELECT x-y, x+y FROM t1 WHERE x BETWEEN 10 AND 15
sl@0
   168
        ORDER BY x LIMIT 2;
sl@0
   169
    SELECT * FROM t5 ORDER BY x;
sl@0
   170
  }
sl@0
   171
} {5 15 6 16}
sl@0
   172
do_test limit-5.2 {
sl@0
   173
  execsql {
sl@0
   174
    DELETE FROM t5;
sl@0
   175
    INSERT INTO t5 SELECT x-y, x+y FROM t1 WHERE x BETWEEN 10 AND 15
sl@0
   176
        ORDER BY x DESC LIMIT 2;
sl@0
   177
    SELECT * FROM t5 ORDER BY x;
sl@0
   178
  }
sl@0
   179
} {9 19 10 20}
sl@0
   180
do_test limit-5.3 {
sl@0
   181
  execsql {
sl@0
   182
    DELETE FROM t5;
sl@0
   183
    INSERT INTO t5 SELECT x-y, x+y FROM t1 WHERE x ORDER BY x DESC LIMIT 31;
sl@0
   184
    SELECT * FROM t5 ORDER BY x LIMIT 2;
sl@0
   185
  }
sl@0
   186
} {-4 6 -3 7}
sl@0
   187
do_test limit-5.4 {
sl@0
   188
  execsql {
sl@0
   189
    SELECT * FROM t5 ORDER BY x DESC, y DESC LIMIT 2;
sl@0
   190
  }
sl@0
   191
} {21 41 21 39}
sl@0
   192
do_test limit-5.5 {
sl@0
   193
  execsql {
sl@0
   194
    DELETE FROM t5;
sl@0
   195
    INSERT INTO t5 SELECT a.x*100+b.x, a.y*100+b.y FROM t1 AS a, t1 AS b
sl@0
   196
                   ORDER BY 1, 2 LIMIT 1000;
sl@0
   197
    SELECT count(*), sum(x), sum(y), min(x), max(x), min(y), max(y) FROM t5;
sl@0
   198
  }
sl@0
   199
} {1000 1528204 593161 0 3107 505 1005}
sl@0
   200
sl@0
   201
# There is some contraversy about whether LIMIT 0 should be the same as
sl@0
   202
# no limit at all or if LIMIT 0 should result in zero output rows.
sl@0
   203
#
sl@0
   204
do_test limit-6.1 {
sl@0
   205
  execsql {
sl@0
   206
    BEGIN;
sl@0
   207
    CREATE TABLE t6(a);
sl@0
   208
    INSERT INTO t6 VALUES(1);
sl@0
   209
    INSERT INTO t6 VALUES(2);
sl@0
   210
    INSERT INTO t6 SELECT a+2 FROM t6;
sl@0
   211
    COMMIT;
sl@0
   212
    SELECT * FROM t6;
sl@0
   213
  }
sl@0
   214
} {1 2 3 4}
sl@0
   215
do_test limit-6.2 {
sl@0
   216
  execsql {
sl@0
   217
    SELECT * FROM t6 LIMIT -1 OFFSET -1;
sl@0
   218
  }
sl@0
   219
} {1 2 3 4}
sl@0
   220
do_test limit-6.3 {
sl@0
   221
  execsql {
sl@0
   222
    SELECT * FROM t6 LIMIT 2 OFFSET -123;
sl@0
   223
  }
sl@0
   224
} {1 2}
sl@0
   225
do_test limit-6.4 {
sl@0
   226
  execsql {
sl@0
   227
    SELECT * FROM t6 LIMIT -432 OFFSET 2;
sl@0
   228
  }
sl@0
   229
} {3 4}
sl@0
   230
do_test limit-6.5 {
sl@0
   231
  execsql {
sl@0
   232
    SELECT * FROM t6 LIMIT -1
sl@0
   233
  }
sl@0
   234
} {1 2 3 4}
sl@0
   235
do_test limit-6.6 {
sl@0
   236
  execsql {
sl@0
   237
    SELECT * FROM t6 LIMIT -1 OFFSET 1
sl@0
   238
  }
sl@0
   239
} {2 3 4}
sl@0
   240
do_test limit-6.7 {
sl@0
   241
  execsql {
sl@0
   242
    SELECT * FROM t6 LIMIT 0
sl@0
   243
  }
sl@0
   244
} {}
sl@0
   245
do_test limit-6.8 {
sl@0
   246
  execsql {
sl@0
   247
    SELECT * FROM t6 LIMIT 0 OFFSET 1
sl@0
   248
  }
sl@0
   249
} {}
sl@0
   250
sl@0
   251
# Make sure LIMIT works well with compound SELECT statements.
sl@0
   252
# Ticket #393
sl@0
   253
#
sl@0
   254
ifcapable compound {
sl@0
   255
do_test limit-7.1.1 {
sl@0
   256
  catchsql {
sl@0
   257
    SELECT x FROM t2 LIMIT 5 UNION ALL SELECT a FROM t6;
sl@0
   258
  }
sl@0
   259
} {1 {LIMIT clause should come after UNION ALL not before}}
sl@0
   260
do_test limit-7.1.2 {
sl@0
   261
  catchsql {
sl@0
   262
    SELECT x FROM t2 LIMIT 5 UNION SELECT a FROM t6;
sl@0
   263
  }
sl@0
   264
} {1 {LIMIT clause should come after UNION not before}}
sl@0
   265
do_test limit-7.1.3 {
sl@0
   266
  catchsql {
sl@0
   267
    SELECT x FROM t2 LIMIT 5 EXCEPT SELECT a FROM t6 LIMIT 3;
sl@0
   268
  }
sl@0
   269
} {1 {LIMIT clause should come after EXCEPT not before}}
sl@0
   270
do_test limit-7.1.4 {
sl@0
   271
  catchsql {
sl@0
   272
    SELECT x FROM t2 LIMIT 0,5 INTERSECT SELECT a FROM t6;
sl@0
   273
  }
sl@0
   274
} {1 {LIMIT clause should come after INTERSECT not before}}
sl@0
   275
do_test limit-7.2 {
sl@0
   276
  execsql {
sl@0
   277
    SELECT x FROM t2 UNION ALL SELECT a FROM t6 LIMIT 5;
sl@0
   278
  }
sl@0
   279
} {31 30 1 2 3}
sl@0
   280
do_test limit-7.3 {
sl@0
   281
  execsql {
sl@0
   282
    SELECT x FROM t2 UNION ALL SELECT a FROM t6 LIMIT 3 OFFSET 1;
sl@0
   283
  }
sl@0
   284
} {30 1 2}
sl@0
   285
do_test limit-7.4 {
sl@0
   286
  execsql {
sl@0
   287
    SELECT x FROM t2 UNION ALL SELECT a FROM t6 ORDER BY 1 LIMIT 3 OFFSET 1;
sl@0
   288
  }
sl@0
   289
} {2 3 4}
sl@0
   290
do_test limit-7.5 {
sl@0
   291
  execsql {
sl@0
   292
    SELECT x FROM t2 UNION SELECT x+2 FROM t2 LIMIT 2 OFFSET 1;
sl@0
   293
  }
sl@0
   294
} {31 32}
sl@0
   295
do_test limit-7.6 {
sl@0
   296
  execsql {
sl@0
   297
    SELECT x FROM t2 UNION SELECT x+2 FROM t2 ORDER BY 1 DESC LIMIT 2 OFFSET 1;
sl@0
   298
  }
sl@0
   299
} {32 31}
sl@0
   300
do_test limit-7.7 {
sl@0
   301
  execsql {
sl@0
   302
    SELECT a+9 FROM t6 EXCEPT SELECT y FROM t2 LIMIT 2;
sl@0
   303
  }
sl@0
   304
} {11 12}
sl@0
   305
do_test limit-7.8 {
sl@0
   306
  execsql {
sl@0
   307
    SELECT a+9 FROM t6 EXCEPT SELECT y FROM t2 ORDER BY 1 DESC LIMIT 2;
sl@0
   308
  }
sl@0
   309
} {13 12}
sl@0
   310
do_test limit-7.9 {
sl@0
   311
  execsql {
sl@0
   312
    SELECT a+26 FROM t6 INTERSECT SELECT x FROM t2 LIMIT 1;
sl@0
   313
  }
sl@0
   314
} {30}
sl@0
   315
do_test limit-7.10 {
sl@0
   316
  execsql {
sl@0
   317
    SELECT a+27 FROM t6 INTERSECT SELECT x FROM t2 LIMIT 1;
sl@0
   318
  }
sl@0
   319
} {30}
sl@0
   320
do_test limit-7.11 {
sl@0
   321
  execsql {
sl@0
   322
    SELECT a+27 FROM t6 INTERSECT SELECT x FROM t2 LIMIT 1 OFFSET 1;
sl@0
   323
  }
sl@0
   324
} {31}
sl@0
   325
do_test limit-7.12 {
sl@0
   326
  execsql {
sl@0
   327
    SELECT a+27 FROM t6 INTERSECT SELECT x FROM t2 
sl@0
   328
       ORDER BY 1 DESC LIMIT 1 OFFSET 1;
sl@0
   329
  }
sl@0
   330
} {30}
sl@0
   331
} ;# ifcapable compound
sl@0
   332
sl@0
   333
# Tests for limit in conjunction with distinct.  The distinct should
sl@0
   334
# occur before both the limit and the offset.  Ticket #749.
sl@0
   335
#
sl@0
   336
do_test limit-8.1 {
sl@0
   337
  execsql {
sl@0
   338
    SELECT DISTINCT cast(round(x/100) as integer) FROM t3 LIMIT 5;
sl@0
   339
  }
sl@0
   340
} {0 1 2 3 4}
sl@0
   341
do_test limit-8.2 {
sl@0
   342
  execsql {
sl@0
   343
    SELECT DISTINCT cast(round(x/100) as integer) FROM t3 LIMIT 5 OFFSET 5;
sl@0
   344
  }
sl@0
   345
} {5 6 7 8 9}
sl@0
   346
do_test limit-8.3 {
sl@0
   347
  execsql {
sl@0
   348
    SELECT DISTINCT cast(round(x/100) as integer) FROM t3 LIMIT 5 OFFSET 25;
sl@0
   349
  }
sl@0
   350
} {25 26 27 28 29}
sl@0
   351
sl@0
   352
# Make sure limits on multiple subqueries work correctly.
sl@0
   353
# Ticket #1035
sl@0
   354
#
sl@0
   355
ifcapable subquery {
sl@0
   356
  do_test limit-9.1 {
sl@0
   357
    execsql {
sl@0
   358
      SELECT * FROM (SELECT * FROM t6 LIMIT 3);
sl@0
   359
    }
sl@0
   360
  } {1 2 3}
sl@0
   361
}
sl@0
   362
do_test limit-9.2.1 {
sl@0
   363
  execsql {
sl@0
   364
    CREATE TABLE t7 AS SELECT * FROM t6;
sl@0
   365
  }
sl@0
   366
} {}
sl@0
   367
ifcapable subquery {
sl@0
   368
  do_test limit-9.2.2 {
sl@0
   369
    execsql {
sl@0
   370
      SELECT * FROM (SELECT * FROM t7 LIMIT 3);
sl@0
   371
    }
sl@0
   372
  } {1 2 3}
sl@0
   373
}
sl@0
   374
ifcapable compound {
sl@0
   375
  ifcapable subquery {
sl@0
   376
    do_test limit-9.3 {
sl@0
   377
      execsql {
sl@0
   378
        SELECT * FROM (SELECT * FROM t6 LIMIT 3)
sl@0
   379
        UNION
sl@0
   380
        SELECT * FROM (SELECT * FROM t7 LIMIT 3)
sl@0
   381
        ORDER BY 1
sl@0
   382
      }
sl@0
   383
    } {1 2 3}
sl@0
   384
    do_test limit-9.4 {
sl@0
   385
      execsql {
sl@0
   386
        SELECT * FROM (SELECT * FROM t6 LIMIT 3)
sl@0
   387
        UNION
sl@0
   388
        SELECT * FROM (SELECT * FROM t7 LIMIT 3)
sl@0
   389
        ORDER BY 1
sl@0
   390
        LIMIT 2
sl@0
   391
      }
sl@0
   392
    } {1 2}
sl@0
   393
  }
sl@0
   394
  do_test limit-9.5 {
sl@0
   395
    catchsql {
sl@0
   396
      SELECT * FROM t6 LIMIT 3
sl@0
   397
      UNION
sl@0
   398
      SELECT * FROM t7 LIMIT 3
sl@0
   399
    }
sl@0
   400
  } {1 {LIMIT clause should come after UNION not before}}
sl@0
   401
}
sl@0
   402
sl@0
   403
# Test LIMIT and OFFSET using SQL variables.
sl@0
   404
do_test limit-10.1 {
sl@0
   405
  set limit 10
sl@0
   406
  db eval {
sl@0
   407
    SELECT x FROM t1 LIMIT :limit;
sl@0
   408
  }
sl@0
   409
} {31 30 29 28 27 26 25 24 23 22}
sl@0
   410
do_test limit-10.2 {
sl@0
   411
  set limit 5
sl@0
   412
  set offset 5
sl@0
   413
  db eval {
sl@0
   414
    SELECT x FROM t1 LIMIT :limit OFFSET :offset;
sl@0
   415
  }
sl@0
   416
} {26 25 24 23 22}
sl@0
   417
do_test limit-10.3 {
sl@0
   418
  set limit -1
sl@0
   419
  db eval {
sl@0
   420
    SELECT x FROM t1 WHERE x<10 LIMIT :limit;
sl@0
   421
  }
sl@0
   422
} {9 8 7 6 5 4 3 2 1 0}
sl@0
   423
do_test limit-10.4 {
sl@0
   424
  set limit 1.5
sl@0
   425
  set rc [catch {
sl@0
   426
  db eval {
sl@0
   427
    SELECT x FROM t1 WHERE x<10 LIMIT :limit;
sl@0
   428
  } } msg]
sl@0
   429
  list $rc $msg
sl@0
   430
} {1 {datatype mismatch}}
sl@0
   431
do_test limit-10.5 {
sl@0
   432
  set limit "hello world"
sl@0
   433
  set rc [catch {
sl@0
   434
  db eval {
sl@0
   435
    SELECT x FROM t1 WHERE x<10 LIMIT :limit;
sl@0
   436
  } } msg]
sl@0
   437
  list $rc $msg
sl@0
   438
} {1 {datatype mismatch}}
sl@0
   439
sl@0
   440
ifcapable subquery {
sl@0
   441
do_test limit-11.1 {
sl@0
   442
  db eval {
sl@0
   443
     SELECT x FROM (SELECT x FROM t1 ORDER BY x LIMIT 0) ORDER BY x
sl@0
   444
  }
sl@0
   445
} {}
sl@0
   446
} ;# ifcapable subquery
sl@0
   447
sl@0
   448
# Test error processing.
sl@0
   449
#
sl@0
   450
do_test limit-12.1 {
sl@0
   451
  catchsql {
sl@0
   452
     SELECT * FROM t1 LIMIT replace(1)
sl@0
   453
  }
sl@0
   454
} {1 {wrong number of arguments to function replace()}}
sl@0
   455
do_test limit-12.2 {
sl@0
   456
  catchsql {
sl@0
   457
     SELECT * FROM t1 LIMIT 5 OFFSET replace(1)
sl@0
   458
  }
sl@0
   459
} {1 {wrong number of arguments to function replace()}}
sl@0
   460
do_test limit-12.3 {
sl@0
   461
  catchsql {
sl@0
   462
     SELECT * FROM t1 LIMIT x
sl@0
   463
  }
sl@0
   464
} {1 {no such column: x}}
sl@0
   465
do_test limit-12.4 {
sl@0
   466
  catchsql {
sl@0
   467
     SELECT * FROM t1 LIMIT 1 OFFSET x
sl@0
   468
  }
sl@0
   469
} {1 {no such column: x}}
sl@0
   470
sl@0
   471
sl@0
   472
finish_test