sleep 3000
sql connect

$dbPrefix = lm_db
$tbPrefix = lm_tb
$stbPrefix = lm_stb
$tbNum = 10
$rowNum = 10
$totalNum = $tbNum * $rowNum
$ts0 = 1537146000000
$delta = 600000
print ========== limit_tb.sim
$i = 0
$db = $dbPrefix . $i
$stb = $stbPrefix . $i

print ====== use db
sql use $db

##### select from table
print ====== select from table with limit offset
$tb = $tbPrefix . 0
sql select * from $tb order by ts desc limit 5
if $rows != 5 then
  return -1
endi
if $data01 != 9 then
  return -1
endi
if $data41 != 5 then
  return -1
endi

sql select * from $tb order by ts desc limit 5 offset 5
if $rows != 5 then
  return -1
endi
if $data01 != 4 then
  return -1
endi
if $data41 != 0 then
  return -1
endi

$offset = $rowNum - 1
sql select * from $tb order by ts desc limit 5 offset $offset
if $rows != 1 then
  return -1
endi

sql select ts, c1, c2, c3, c4, c5, c6, c7, c8, c9 from $tb order by ts desc limit 5 offset 5
if $rows != 5 then
  return -1
endi
if $data01 != 4 then
  return -1
endi
if $data02 != 4 then
  return -1
endi
if $data03 != 4.00000 then
  return -1
endi
if $data04 != 4.000000000 then
  return -1
endi
if $data05 != 4 then
  return -1
endi
if $data06 != 4 then
   return -1
endi
if $data07 != 1 then
  return -1
endi
if $data08 != binary4 then
  return -1
endi
if $data09 != nchar4 then
  return -1
endi

sql select ts, c1, c2, c3, c4, c5, c6, c7, c8, c9 from $tb order by ts desc limit 5 offset $offset
if $rows != 1 then
  return -1
endi
if $data01 != 0 then
  return -1
endi
if $data02 != 0 then
  return -1
endi
if $data03 != 0.00000 then
  return -1
endi
if $data04 != 0.000000000 then
  return -1
endi
if $data05 != 0 then
  return -1
endi
if $data06 != 0 then
  return -1
endi
if $data07 != 1 then
  return -1
endi
if $data08 != binary0 then
  return -1
endi
if $data09 != nchar0 then
  return -1
endi


## TBASE-329
sql select * from $tb where c1 < 9 order by ts desc limit 1 offset 1
if $rows != 1 then
  return -1
endi
if $data01 != 7 then
  return -1
endi

sql select * from $tb where c1 < 9 order by ts desc limit 2 offset 1
if $rows != 2 then
  return -1
endi
if $data01 != 7 then
  return -1
endi
if $data11 != 6 then
  return -1
endi

sql select * from $tb where c1 < 9 order by ts desc limit 3 offset 1
if $rows != 3 then
  return -1
endi
if $data01 != 7 then
  return -1
endi
if $data11 != 6 then
  return -1
endi
if $data21 != 5 then
  return -1
endi

sql select * from $tb where c1 < 0 order by ts desc limit 3 offset 1
if $rows != 0 then
  return -1
endi

sql select * from $tb where c1 > 0 order by ts desc limit 1 offset 1
if $rows != 1 then
  return -1
endi
if $data01 != 8 then
  return -1
endi

sql select * from $tb where c1 > 0 order by ts desc limit 2 offset 1
if $rows != 2 then
  return -1
endi
if $data01 != 8 then
  return -1
endi
if $data11 != 7 then
  return -1
endi


sql_error select * from $tb limit
sql_error select * from $tb offset
sql_error select * from $tb offset 1
sql_error select * from $tb offset 1 limit 5
sql_error select * from $tb offset 1 limit -1

#### aggregation function + limit offset
$tsu = $rowNum * $delta
$tsu = $tsu - $delta
$tsu = $tsu + $ts0

### aggregation function + limit offset (non-interval case)
sql select max(c1), max(c2), max(c3), max(c4), max(c5), max(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 5
if $rows != 1 then
  return -1
endi
sql select max(c1), max(c2), max(c3), max(c4), max(c5), max(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 0
if $rows != 0 then
  return -1
endi
sql select max(c1), max(c2), max(c3), max(c4), max(c5), max(c6) from $tb where ts >= $ts0 and ts <= $tsu and c1 < 9 and c2 < 8 and c3 >0 and c4 <= 7 and c5 <7 limit 5 offset 0
if $rows != 1 then
  return -1
endi

sql select max(c1), max(c2), max(c3), max(c4), max(c5), max(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
if $rows != 0 then
  return -1
endi

sql select min(c1), min(c2), min(c3), min(c4), min(c5), min(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 5
if $rows != 1 then
  return -1
endi
sql select min(c1), min(c2), min(c3), min(c4), min(c5), min(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 0 offset 0
if $rows != 0 then
  return -1
endi
sql select min(c1), min(c2), min(c3), min(c4), min(c5), min(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
if $rows != 0 then
  return -1
endi

sql select sum(c1), avg(c2), stddev(c3), max(c4), min(c5), count(c6), first(c7), last(c8), last(c9) from $tb where ts >= $ts0 and ts <= $tsu limit 5
if $rows != 1 then
  return -1
endi
$val = 45 * $rowNum 
$val = $val / 10
print $data05
print $rowNum
#print $val
if $data00 != $val then
  return -1
endi
if $data01 != 4.500000000 then
  return -1
endi
if $data02 != 2.872281323 then
  return -1
endi
if $data03 != 9.000000000 then
  return -1
endi
if $data04 != 0 then
  return -1
endi
if $data05 != $rowNum then
  return -1
endi
if $data06 != 1 then
  return -1
endi
if $data07 != binary9 then
  return -1
endi
if $data08 != nchar9 then
  return -1
endi

sql select sum(c1), avg(c2), stddev(c3), max(c4), min(c5), count(c6), first(c7), last(c8), last(c9) from $tb where ts >= $ts0 and ts <= $tsu limit 0
if $rows != 0 then
  return -1
endi
sql select sum(c1), avg(c2), stddev(c3), max(c4), min(c5), count(c6), first(c7), last(c8), last(c9) from $tb where ts >= $ts0 and ts <= $tsu and c1>1 and c2<9 and c3>2 and c4<8 and c5>4 and c6<6 limit 1 offset 0
if $rows != 1 then
  return -1
endi
if $data00 != 5 then
  return -1
endi
if $data01 != 5.000000000 then
  return -1
endi
if $data02 != 0.000000000 then
  return -1
endi
if $data03 != 5.000000000 then
  return -1
endi
if $data04 != 5 then
  return -1
endi
if $data05 != 1 then
  return -1
endi
if $data06 != 1 then
  return -1
endi
if $data07 != binary5 then
  return -1
endi
if $data08 != nchar5 then
  return -1
endi

sql select sum(c1), avg(c2), stddev(c3), max(c4), min(c5), count(c6), first(c7), last(c8), last(c9) from $tb where ts >= $ts0 and ts <= $tsu limit 3 offset 1
if $rows != 0 then
  return -1
endi

sql select spread(ts), spread(c1), spread(c2), spread(c3), spread(c4), spread(c5), spread(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 0
if $rows != 1 then
  return -1
endi
if $data00 != 5400000.000000000 then
  return -1
endi
if $data01 != 9.000000000 then
  return -1
endi
if $data02 != 9.000000000 then
  return -1
endi
if $data03 != 9.000000000 then
  return -1
endi
if $data04 != 9.000000000 then
  return -1
endi
if $data05 != 9.000000000 then
  return -1
endi
if $data06 != 9.000000000 then
  return -1
endi
sql select spread(ts), spread(c1), spread(c2), spread(c3), spread(c4), spread(c5), spread(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
if $rows != 0 then
  return -1
endi

sql select twa(c1), twa(c2), twa(c3), twa(c4), twa(c5), twa(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 0
if $rows != 1 then
  return -1
endi
if $data00 != 4.000000000 then
  return -1
endi
if $data01 != 4.000000000 then
  return -1
endi
if $data02 != 4.000000000 then
  return -1
endi
if $data03 != 4.000000000 then
  return -1
endi
if $data04 != 4.000000000 then
  return -1
endi
if $data05 != 4.000000000 then
  return -1
endi

sql select twa(c1), twa(c2), twa(c3), twa(c4), twa(c5), twa(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
if $rows != 0 then
  return -1
endi

sql select top(c1, 1) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
if $rows != 0 then
  return -1
endi
sql select top(c1, 5) from $tb where ts >= $ts0 and ts <= $tsu order by ts desc limit 3 offset 1
print select top(c1, 5) from $tb where ts >= $ts0 and ts <= $tsu order by ts desc limit 3 offset 1
print $data00 $data01
print $data10 $data11
print $data20 $data21

if $rows != 3 then
  return -1
endi
if $data00 != @18-09-17 10:20:00.000@ then
  return -1
endi
if $data01 != 8 then
  return -1
endi
if $data10 != @18-09-17 10:10:00.000@ then
  return -1
endi
if $data11 != 7 then
  return -1
endi
if $data20 != @18-09-17 10:00:00.000@ then
  return -1
endi
if $data21 != 6 then
  return -1
endi

sql select top(c1, 5) from $tb where ts >= $ts0 and ts <= $tsu order by ts asc limit 3 offset 1
if $rows != 3 then
  return -1
endi
if $data00 != @18-09-17 10:00:00.000@ then
  return -1
endi
if $data01 != 6 then
  return -1
endi
if $data10 != @18-09-17 10:10:00.000@ then
  return -1
endi
if $data11 != 7 then
  return -1
endi
if $data20 != @18-09-17 10:20:00.000@ then
  return -1
endi
if $data21 != 8 then
  return -1
endi
sql select top(c1, 5) from $tb where ts >= $ts0 and ts <= $tsu order by ts asc limit 3 offset 5
if $rows != 0 then
  return -1
endi
sql_error select top(c1, 101) from $tb where ts >= $ts0 and ts <= $tsu order by ts asc limit 3 offset 98

sql select bottom(c1, 1) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
if $rows != 0 then
  return -1
endi
sql select bottom(c1, 5) from $tb where ts >= $ts0 and ts <= $tsu limit 3 offset 1
if $rows != 3 then
  return -1
endi
if $data00 != @18-09-17 09:10:00.000@ then
  return -1
endi
if $data01 != 1 then
  return -1
endi
if $data10 != @18-09-17 09:20:00.000@ then
  return -1
endi
if $data11 != 2 then
  return -1
endi
if $data20 != @18-09-17 09:30:00.000@ then
  return -1
endi
if $data21 != 3 then
  return -1
endi
sql select bottom(c1, 5) from $tb where ts >= $ts0 and ts <= $tsu limit 3 offset 5
if $rows != 0 then
  return -1
endi

sql select diff(c1) from $tb where c1 > 5 limit 2 offset 1
if $rows != 2 then
  return -1
endi
if $data00 != @18-09-17 10:20:00.000@ then
  return -1
endi
if $data01 != 1 then
  return -1
endi
if $data10 != @18-09-17 10:30:00.000@ then
  return -1
endi
if $data11 != 1 then
  return -1
endi

### aggregation + limit offset (with interval)
sql select max(c1), max(c2), max(c3), max(c4), max(c5), max(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) limit 5
if $rows != 5 then 
  return -1
endi
if $data01 != 0 then
  return -1
endi
if $data11 != 1 then
  return -1
endi
if $data21 != 2 then
  return -1
endi
if $data31 != 3 then
  return -1
endi
if $data41 != 4 then
  return -1
endi
sql select max(c1), max(c2), max(c3), max(c4), max(c5), max(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) limit 5 offset 1
if $rows != 5 then
  return -1
endi
if $data01 != 1 then
  return -1
endi
if $data02 != 1 then
  return -1
endi
if $data03 != 1.00000 then
  return -1
endi
if $data04 != 1.000000000 then
  return -1
endi
if $data05 != 1 then
  return -1
endi
if $data06 != 1 then
  return -1
endi
if $data11 != 2 then
  return -1
endi
if $data21 != 3 then
  return -1
endi
if $data31 != 4 then
  return -1
endi
if $data41 != 5 then
  return -1
endi

## TBASE-334
sql select max(c1), max(c2), max(c3), max(c4), max(c5), max(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 2 offset 1
if $rows != 2 then
  return -1
endi
if $data01 != 5 then
  return -1
endi
if $data04 != 5.000000000 then
  return -1
endi
if $data11 != 8 then
  return -1
endi
if $data14 != 8.000000000 then
  return -1
endi
if $data21 != null then
  print expect null, actual: $data21
  return -1
endi

sql select min(c1), min(c2), min(c3), min(c4), min(c5), min(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 1
if $rows != 3 then
  return -1
endi
if $data01 != 3 then
  return -1
endi
if $data11 != 6 then
  return -1
endi
if $data21 != 9 then
  return -1
endi
if $data31 != null then
  return -1
endi

sql select sum(c1), sum(c2), sum(c3), sum(c4), sum(c5), sum(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 5
if $rows != 4 then
  return -1
endi
if $data01 != 3 then
  return -1
endi
if $data11 != 12 then
  return -1
endi
if $data21 != 21 then
  return -1
endi
if $data31 != 9 then
  return -1
endi
if $data41 != null then
  return -1
endi
sql select sum(c1), sum(c2), sum(c3), sum(c4), sum(c5), sum(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 5 offset 1
if $rows != 3 then
  return -1
endi
if $data01 != 12 then
  return -1
endi
if $data11 != 21 then
  return -1
endi
if $data21 != 9 then
  return -1
endi
if $data31 != null then
  return -1
endi

sql select avg(c1), avg(c2), avg(c3), avg(c4), avg(c5), avg(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 0
if $rows != 3 then
  return -1
endi
if $data01 != 1.000000000 then
  return -1
endi
if $data11 != 4.000000000 then
  return -1
endi
if $data21 != 7.000000000 then
  return -1
endi
if $data31 != null then
  return -1
endi
sql select avg(c1), avg(c2), avg(c3), avg(c4), avg(c5), avg(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 1
if $rows != 3 then
  return -1
endi
if $data01 != 4.000000000 then
  return -1
endi
if $data11 != 7.000000000 then
  return -1
endi
if $data21 != 9.000000000 then
  return -1
endi
if $data31 != null then
  return -1
endi


sql select stddev(c1), stddev(c2), stddev(c3), stddev(c4), stddev(c5), stddev(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
if $rows != 0 then
  return -1
endi
sql select stddev(c1), stddev(c2), stddev(c3), stddev(c4), stddev(c5), stddev(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) limit 0
if $rows != 0 then
  return -1
endi
sql select stddev(c1), stddev(c2), stddev(c3), stddev(c4), stddev(c5), stddev(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 5 offset 1
if $rows != 3 then
  return -1
endi
if $data00 != @18-09-17 09:30:00.000@ then
  return -1
endi
if $data01 != 0.816496581 then
  return -1
endi
if $data10 != @18-09-17 10:00:00.000@ then
  return -1
endi
if $data20 != @18-09-17 10:30:00.000@ then
  return -1
endi
if $data21 != 0.000000000 then
  return -1
endi

sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(27m)
if $rows != 4 then
  return -1
endi
if $data01 != 2 then
  return -1
endi
if $data11 != 2 then
  return -1
endi
if $data21 != 3 then
  return -1
endi
if $data31 != 3 then
  return -1
endi
sql select count(c1), count(c2), count(c3), count(c4), count(c5), count(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(27m) limit 5 offset 1
if $rows != 3 then
  return -1
endi
if $data01 != 2 then
  return -1
endi
if $data11 != 3 then
  return -1
endi
if $data21 != 3 then
  return -1
endi 

sql select twa(c1), twa(c2), twa(c3), twa(c4), twa(c5), twa(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 3 offset 1
if $rows != 0 then
  return -1
endi

sql select twa(c1), twa(c2), twa(c3), twa(c4), twa(c5), twa(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 3 offset 0
if $rows != 1 then
  return -1
endi
if $data00 != 4.000000000 then
  return -1
endi
if $data02 != 4.000000000 then
  return -1
endi
if $data05 != 4.000000000 then
  return -1
endi

sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
if $rows != 0 then
  return -1
endi
sql select first(c1), first(c2), first(c3), first(c4), first(c5), first(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 1
if $rows != 3 then
  return -1
endi
if $data01 != 3 then
  return -1
endi
if $data12 != 6 then
  return -1
endi
if $data23 != 9.00000 then
  return -1
endi


sql select last(c1), last(c2), last(c3), last(c4), last(c5), last(c6) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
if $rows != 0 then
  return -1
endi
sql select last(c1), last(c2), last(c3), last(c4), last(c5), last(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(30m) limit 3 offset 1
if $rows != 3 then
  return -1
endi
if $data01 != 5 then
  return -1
endi
if $data12 != 8 then
  return -1
endi
if $data23 != 9.00000 then
  return -1
endi

sql select first(ts), first(c1), last(c2), first(c3), last(c4), first(c5), last(c6), first(c8), last(c9) from $tb where ts >= $ts0 and ts <= $tsu and c1 > 0 interval(30m) limit 3 offset 0
if $rows != 3 then
  return -1
endi
if $data01 != @18-09-17 09:10:00.000@ then
  return -1
endi
if $data02 != 1 then
  return -1
endi
if $data03 != 2 then
  return -1
endi
if $data12 != 3 then
  return -1
endi
if $data13 != 5 then
  return -1
endi
if $data14 != 3.00000 then
  return -1
endi
if $data22 != 6 then
  return -1
endi
if $data23 != 8 then
  return -1
endi
if $data28 != binary6 then
  return -1
endi
if $data29 != nchar8 then
  return -1
endi

sql select first(ts), first(c1), last(c2), first(c3), last(c4), first(c5), last(c6), first(c8), last(c9) from $tb where ts >= $ts0 and ts <= $tsu and c1 > 0 interval(30m) limit 3 offset 1
if $rows != 3 then
  return -1
endi
if $data01 != @18-09-17 09:30:00.000@ then
  return -1
endi
if $data02 != 3 then
  return -1
endi
if $data03 != 5 then
  return -1
endi 
if $data04 != 3.00000 then
  return -1
endi
if $data05 != 5.000000000 then
  return -1
endi
if $data08 != binary3 then
  return -1
endi
if $data09 != nchar5 then
  return -1
endi
if $data12 != 6 then
  return -1
endi
if $data13 != 8 then
  return -1
endi
if $data14 != 6.00000 then
  return -1
endi
if $data15 != 8.000000000 then
  return -1
endi
if $data22 != 9 then
  return -1
endi
if $data23 != 9 then
  return -1
endi
if $data24 != 9.00000 then
  return -1
endi
if $data25 != 9.000000000 then
  return -1
endi
if $data26 != 9 then
  return -1
endi
if $data27 != 9 then
  return -1
endi
if $data28 != binary9 then
  return -1
endi
if $data29 != nchar9 then
  return -1
endi

### order by ts + limit offset

sql select * from $tb order by ts asc limit 5
if $rows != 5 then
  return -1
endi
if $data00 != @18-09-17 09:00:00.000@ then
  return -1
endi
if $data01 != 0 then
  return -1
endi
if $data10 != @18-09-17 09:10:00.000@ then
  return -1
endi
if $data12 != 1 then
  return -1
endi
if $data20 != @18-09-17 09:20:00.000@ then
  return -1
endi
if $data23 != 2.00000 then
  return -1
endi
if $data34 != 3.000000000 then
  return -1
endi
if $data45 != 4 then
  return -1
endi
if $data06 != 0 then
  return -1
endi
if $data17 != 1 then
  return -1
endi
if $data28 != binary2 then
  return -1
endi
if $data39 != nchar3 then
  return -1
endi
if $data40 != @18-09-17 09:40:00.000@ then
  return -1
endi

sql select * from $tb order by ts asc limit 5 offset 1
if $rows != 5 then
  return -1
endi
if $data00 != @18-09-17 09:10:00.000@ then
  return -1
endi
if $data01 != 1 then
  return -1
endi
if $data10 != @18-09-17 09:20:00.000@ then
  return -1
endi
if $data12 != 2 then
  return -1
endi
if $data20 != @18-09-17 09:30:00.000@ then
  return -1
endi
if $data23 != 3.00000 then
  return -1
endi
if $data34 != 4.000000000 then
  return -1
endi
if $data45 != 5 then
  return -1
endi
if $data06 != 1 then
  return -1
endi
if $data17 != 1 then
  return -1
endi
if $data28 != binary3 then
  return -1
endi
if $data39 != nchar4 then
  return -1
endi
if $data40 != @18-09-17 09:50:00.000@ then
  return -1
endi

sql select * from $tb order by ts asc limit 5 offset 8
if $rows != 2 then
  return -1
endi
if $data00 != @18-09-17 10:20:00.000@ then
  return -1
endi
if $data01 != 8 then
  return -1
endi
if $data10 != @18-09-17 10:30:00.000@ then
  return -1
endi
if $data12 != 9 then
  return -1
endi

sql select * from $tb where c1 > 1 order by ts asc limit 3 offset 2
if $rows != 3 then
  return -1
endi
if $data00 != @18-09-17 09:40:00.000@ then
  return -1
endi
if $data01 != 4 then
  return -1
endi
if $data10 != @18-09-17 09:50:00.000@ then
  return -1
endi
if $data20 != @18-09-17 10:00:00.000@ then
  return -1
endi
if $data12 != 5 then
  return -1
endi
if $data23 != 6.00000 then
  return -1
endi

sql select * from $tb where c1 < 3 and c1 > 1 order by ts asc limit 3 offset 2
if $rows != 0 then
  return -1
endi

sql select * from $tb where c1 < 5 and c1 > 1 order by ts asc limit 3 offset 2
if $rows != 1 then
  return -1
endi
if $data00 != @18-09-17 09:40:00.000@ then
  return -1
endi
if $data01 != 4 then
  return -1
endi
if $data04 != 4.000000000 then
  return -1
endi

sql select * from $tb order by ts desc limit 5
if $rows != 5 then
  return -1
endi
if $data00 != @18-09-17 10:30:00.000@ then
  return -1
endi
if $data01 != 9 then
  return -1
endi
if $data10 != @18-09-17 10:20:00.000@ then
  return -1
endi
if $data12 != 8 then
  return -1
endi
if $data20 != @18-09-17 10:10:00.000@ then
  return -1
endi
if $data23 != 7.00000 then
  return -1
endi
if $data34 != 6.000000000 then
  return -1
endi
if $data45 != 5 then
  return -1
endi
if $data06 != 9 then
  return -1
endi
if $data17 != 1 then
  return -1
endi
if $data28 != binary7 then
  return -1
endi
if $data39 != nchar6 then
  return -1
endi
if $data40 != @18-09-17 09:50:00.000@ then
  return -1
endi

sql select * from $tb order by ts desc limit 5 offset 1
if $rows != 5 then
  return -1
endi
if $data00 != @18-09-17 10:20:00.000@ then
  return -1
endi
if $data01 != 8 then
  return -1
endi
if $data10 != @18-09-17 10:10:00.000@ then
  return -1
endi
if $data12 != 7 then
  return -1
endi
if $data20 != @18-09-17 10:00:00.000@ then
  return -1
endi
if $data23 != 6.00000 then
  return -1
endi
if $data34 != 5.000000000 then
  return -1
endi
if $data45 != 4 then
  return -1
endi
if $data06 != 8 then
  return -1
endi
if $data17 != 1 then
  return -1
endi
if $data28 != binary6 then
  return -1
endi
if $data39 != nchar5 then
  return -1
endi
if $data40 != @18-09-17 09:40:00.000@ then
  return -1
endi

sql select * from $tb order by ts desc limit 5 offset 8
if $rows != 2 then
  return -1
endi
if $data00 != @18-09-17 09:10:00.000@ then
  return -1
endi
if $data01 != 1 then
  return -1
endi
if $data10 != @18-09-17 09:00:00.000@ then
  return -1
endi
if $data12 != 0 then
  return -1
endi

sql select * from $tb where c1 < 8 order by ts desc limit 3 offset 2
if $rows != 3 then
  return -1
endi
if $data00 != @18-09-17 09:50:00.000@ then
  return -1
endi
if $data01 != 5 then
  return -1
endi
if $data10 != @18-09-17 09:40:00.000@ then
  return -1
endi
if $data20 != @18-09-17 09:30:00.000@ then
  return -1
endi
if $data12 != 4 then
  return -1
endi
if $data23 != 3.00000 then
  return -1
endi

sql select * from $tb where c1 < 8 and c1 > 6 order by ts desc limit 3 offset 2
if $rows != 0 then
  return -1
endi

sql select * from $tb where c1 < 8 and c1 > 4 order by ts desc limit 3 offset 2
if $rows != 1 then
  return -1
endi
if $data00 != @18-09-17 09:50:00.000@ then
  return -1
endi
if $data01 != 5 then
  return -1
endi
if $data04 != 5.000000000 then
  return -1
endi

