SQLite4
Check-in [22365cae272858a7eff64fe07c2b6cb88cfcfdba]
Not logged in

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

Overview
SHA1 Hash:22365cae272858a7eff64fe07c2b6cb88cfcfdba
Date: 2013-06-26 20:29:40
User: dan
Comment:Further fixes for legacy test cases.
Tags And Properties
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/lsm_shared.c

954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
#ifdef LSM_LOG_WORK
      lsmLogMessage(pDb, 0, "finish checkpoint %d", 
          (int)lsmCheckpointId(pDb->aSnapshot, 0)
      );
#endif
    }

    if( rc==LSM_OK && bTruncate ){
      rc = lsmFsTruncateDb(pDb->pFS, (i64)nBlock*lsmFsBlockSize(pDb->pFS));
    }
  }

  lsmShmLock(pDb, LSM_LOCK_CHECKPOINTER, LSM_LOCK_UNLOCK, 0);
  if( pnWrite && rc==LSM_OK ) *pnWrite = nWrite;
  return rc;







|







954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
#ifdef LSM_LOG_WORK
      lsmLogMessage(pDb, 0, "finish checkpoint %d", 
          (int)lsmCheckpointId(pDb->aSnapshot, 0)
      );
#endif
    }

    if( rc==LSM_OK && bTruncate && nBlock>0 ){
      rc = lsmFsTruncateDb(pDb->pFS, (i64)nBlock*lsmFsBlockSize(pDb->pFS));
    }
  }

  lsmShmLock(pDb, LSM_LOCK_CHECKPOINTER, LSM_LOCK_UNLOCK, 0);
  if( pnWrite && rc==LSM_OK ) *pnWrite = nWrite;
  return rc;

Changes to src/utf.c

577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
    ** character. Two bytes are required in the output buffer for the
    ** nul-terminator.  */
    if( n<0 ){
      u8 *z = (u8*)p;
      while( z[0] || z[1] ) z += 2;
      n = z - (u8*)p;
    }
    nReq = n * 2 + 1;
  }else{
    /* When converting from UTF-16, the maximum growth results from
    ** translating a 2-byte character to a 4-byte UTF-8 character.
    ** A single byte is required for the output string
    ** nul-terminator.  */
    if( n<0 ) n = sqlite4Strlen30(p);
    nReq = n * 2 + 1;







|







577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
    ** character. Two bytes are required in the output buffer for the
    ** nul-terminator.  */
    if( n<0 ){
      u8 *z = (u8*)p;
      while( z[0] || z[1] ) z += 2;
      n = z - (u8*)p;
    }
    nReq = n * 2 + 2;
  }else{
    /* When converting from UTF-16, the maximum growth results from
    ** translating a 2-byte character to a 4-byte UTF-8 character.
    ** A single byte is required for the output string
    ** nul-terminator.  */
    if( n<0 ) n = sqlite4Strlen30(p);
    nReq = n * 2 + 1;

Changes to test/capi2.test

430
431
432
433
434
435
436



437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
...
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
#
# do_test capi2-6.2 {
#   list [sqlite4_step $VM1] \
#        [sqlite4_column_count $VM1] \
#        [get_row_values $VM1] \
#        [get_column_names $VM1]
# } {SQLITE4_BUSY 0 {} {}}



do_test capi2-6.3 {
  execsql {COMMIT} db2
} {}
do_test capi2-6.4 {
  list [sqlite4_step $VM1] \
       [sqlite4_column_count $VM1] \
       [get_row_values $VM1] \
       [get_column_names $VM1]
} {SQLITE4_ROW 1 1 {x counter}}
do_test capi2-6.5 {
  catchsql {INSERT INTO t3 VALUES(10);} db2
} {0 {}}
do_test capi2-6.6 {
  list [sqlite4_step $VM1] \
       [sqlite4_column_count $VM1] \
       [get_row_values $VM1] \
       [get_column_names $VM1]
} {SQLITE4_ROW 1 2 {x counter}}
do_test capi2-6.7 {
................................................................................
    PRAGMA count_changes=on
  }
} {0}
do_test capi2-7.3 {
  stepsql $DB {
    UPDATE t1 SET a=a+10;
  }
} {0 1}
do_test capi2-7.4 {
  stepsql $DB {
    INSERT INTO t1 SELECT a+1,b+1,c+1 FROM t1;
  }
} {0 1}
do_test capi2-7.4b {sqlite4_changes $DB} {1}
do_test capi2-7.5 {
  stepsql $DB {
    UPDATE t1 SET a=a+10;
  }
} {0 2}
do_test capi2-7.5b {sqlite4_changes $DB} {2}
do_test capi2-7.6 {
  stepsql $DB {
    SELECT * FROM t1;
  }
} {0 21 2 3 22 3 4}
do_test capi2-7.7 {
  stepsql $DB {
    INSERT INTO t1 SELECT a+2,b+2,c+2 FROM t1;
  }
} {0 2}
do_test capi2-7.8 {
  sqlite4_changes $DB
} {2}
do_test capi2-7.9 {
  stepsql $DB {
    SELECT * FROM t1;
  }
} {0 21 2 3 22 3 4 23 4 5 24 5 6}
do_test capi2-7.10 {
  stepsql $DB {
    UPDATE t1 SET a=a-20;
    SELECT * FROM t1;
  }
} {0 4 1 2 3 2 3 4 3 4 5 4 5 6}

# Update for version 3: A SELECT statement no longer resets the change
# counter (Test result changes from 0 to 4).
do_test capi2-7.11 {
  sqlite4_changes $DB
} {4}
do_test capi2-7.11a {







>
>
>









<
<
<







 







|




|





|










|













|







430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448



449
450
451
452
453
454
455
...
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
#
# do_test capi2-6.2 {
#   list [sqlite4_step $VM1] \
#        [sqlite4_column_count $VM1] \
#        [get_row_values $VM1] \
#        [get_column_names $VM1]
# } {SQLITE4_BUSY 0 {} {}}
do_test capi2-6.5 {
  catchsql {INSERT INTO t3 VALUES(10);} db2
} {0 {}}
do_test capi2-6.3 {
  execsql {COMMIT} db2
} {}
do_test capi2-6.4 {
  list [sqlite4_step $VM1] \
       [sqlite4_column_count $VM1] \
       [get_row_values $VM1] \
       [get_column_names $VM1]
} {SQLITE4_ROW 1 1 {x counter}}



do_test capi2-6.6 {
  list [sqlite4_step $VM1] \
       [sqlite4_column_count $VM1] \
       [get_row_values $VM1] \
       [get_column_names $VM1]
} {SQLITE4_ROW 1 2 {x counter}}
do_test capi2-6.7 {
................................................................................
    PRAGMA count_changes=on
  }
} {0}
do_test capi2-7.3 {
  stepsql $DB {
    UPDATE t1 SET a=a+10;
  }
} {0}
do_test capi2-7.4 {
  stepsql $DB {
    INSERT INTO t1 SELECT a+1,b+1,c+1 FROM t1;
  }
} {0}
do_test capi2-7.4b {sqlite4_changes $DB} {1}
do_test capi2-7.5 {
  stepsql $DB {
    UPDATE t1 SET a=a+10;
  }
} {0}
do_test capi2-7.5b {sqlite4_changes $DB} {2}
do_test capi2-7.6 {
  stepsql $DB {
    SELECT * FROM t1;
  }
} {0 21 2 3 22 3 4}
do_test capi2-7.7 {
  stepsql $DB {
    INSERT INTO t1 SELECT a+2,b+2,c+2 FROM t1;
  }
} {0}
do_test capi2-7.8 {
  sqlite4_changes $DB
} {2}
do_test capi2-7.9 {
  stepsql $DB {
    SELECT * FROM t1;
  }
} {0 21 2 3 22 3 4 23 4 5 24 5 6}
do_test capi2-7.10 {
  stepsql $DB {
    UPDATE t1 SET a=a-20;
    SELECT * FROM t1;
  }
} {0 1 2 3 2 3 4 3 4 5 4 5 6}

# Update for version 3: A SELECT statement no longer resets the change
# counter (Test result changes from 0 to 4).
do_test capi2-7.11 {
  sqlite4_changes $DB
} {4}
do_test capi2-7.11a {

Changes to test/capi3.test

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
...
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
...
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
...
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
322
323
324
325
326
327
328
329
...
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
...
509
510
511
512
513
514
515

516
517
518
519
520
521
522
...
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
...
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
...
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
...
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
....
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
# capi3-5.*: Test the various sqlite4_result_* APIs
# capi3-6.*: Test that sqlite4_close fails if there are outstanding VMs.
#

set DB [sqlite4_connection_pointer db]

do_test capi3-1.0 {
  sqlite4_get_autocommit $DB
} 1
do_test capi3-1.1 {
  set STMT [sqlite4_prepare $DB {SELECT name FROM sqlite_master} -1 TAIL]
  sqlite4_finalize $STMT
  set TAIL
} {}
do_test capi3-1.2.1 {
  sqlite4_errcode $DB
} {SQLITE4_OK}
do_test capi3-1.2.2 {
  sqlite4_extended_errcode $DB
} {SQLITE4_OK}
do_test capi3-1.3 {
  sqlite4_errmsg $DB
} {not an error}
do_test capi3-1.4 {
  set sql {SELECT name FROM sqlite_master;SELECT 10}
  set STMT [sqlite4_prepare $DB $sql -1 TAIL]
................................................................................
    set STMT [sqlite4_prepare $DB $sql -1 TAIL]
  }
} {1}
do_test capi3-1.8.1 {
  sqlite4_errcode $DB
} {SQLITE4_ERROR}
do_test capi3-1.8.2 {
  sqlite4_extended_errcode $DB
} {SQLITE4_ERROR}
do_test capi3-1.9 {
  sqlite4_errmsg $DB
} {no such column: namex}

ifcapable {utf16} {
  do_test capi3-2.1 {
    set sql16 [utf16 {SELECT name FROM sqlite_master}]
    set STMT [sqlite4_prepare16 $DB $sql16 -1 ::TAIL]
    sqlite4_finalize $STMT
    utf8 $::TAIL
  } {}
  do_test capi3-2.2 {
    set sql [utf16 {SELECT name FROM sqlite_master;SELECT 10}]
    set STMT [sqlite4_prepare16 $DB $sql -1 TAIL]
    sqlite4_finalize $STMT
    utf8 $TAIL
  } {SELECT 10}
  do_test capi3-2.3 {
    set sql [utf16 {SELECT namex FROM sqlite_master}]
    catch {
      set STMT [sqlite4_prepare16 $DB $sql -1]
    }
  } {1}
  do_test capi3-2.4.1 {
    sqlite4_errcode $DB
  } {SQLITE4_ERROR}
  do_test capi3-2.4.2 {
    sqlite4_extended_errcode $DB
  } {SQLITE4_ERROR}
  do_test capi3-2.5 {
    sqlite4_errmsg $DB
  } {no such column: namex}

  ifcapable schema_pragmas {
    do_test capi3-2.6 {
      execsql {CREATE TABLE tablename(x)}
      set sql16 [utf16 {PRAGMA table_info("TableName"); --excess text}]
      set STMT [sqlite4_prepare16 $DB $sql16 -1]
      sqlite4_step $STMT
    } SQLITE4_ROW
    do_test capi3-2.7 {
      sqlite4_step $STMT
    } SQLITE4_DONE
    do_test capi3-2.8 {
      sqlite4_finalize $STMT
    } SQLITE4_OK
  }

} ;# endif utf16

# rename sqlite4_open sqlite4_open_old
# proc sqlite4_open {fname options} {sqlite4_open_new $fname $options}

do_test capi3-3.1 {
  set db2 [sqlite4_open test.db {}]
  sqlite4_errcode $db2
} {SQLITE4_OK}
................................................................................
do_test capi3-3.2 {
  sqlite4_close $db2
} {SQLITE4_OK}
do_test capi3-3.3 {
  catch {
    set db2 [sqlite4_open /bogus/path/test.db {}]
  }
  sqlite4_extended_errcode $db2
} {SQLITE4_CANTOPEN}
do_test capi3-3.4 {
  sqlite4_errmsg $db2
} {unable to open database file}
do_test capi3-3.5 {
  sqlite4_close $db2
} {SQLITE4_OK}
do_test capi3-3.6.1-misuse {
  sqlite4_close $db2
} {SQLITE4_MISUSE}
do_test capi3-3.6.2-misuse {
  sqlite4_errmsg $db2
} {library routine called out of sequence}
ifcapable {utf16} {
  do_test capi3-3.6.3-misuse {
    utf8 [sqlite4_errmsg16 $db2]
  } {library routine called out of sequence}
}

do_test capi3-3.7 {
  set db2 [sqlite4_open]
  sqlite4_errcode $db2
} {SQLITE4_OK}
do_test capi3-3.8 {
  sqlite4_close $db2
} {SQLITE4_OK}

# rename sqlite4_open ""
# rename sqlite4_open_old sqlite4_open

ifcapable {utf16} {
do_test capi3-4.1 {
  set db2 [sqlite4_open16 [utf16 test.db] {}]
  sqlite4_errcode $db2
} {SQLITE4_OK}
# FIX ME: Should test the db handle works.
do_test capi3-4.2 {
  sqlite4_close $db2
} {SQLITE4_OK}
do_test capi3-4.3 {
  catch {
    set db2 [sqlite4_open16 [utf16 /bogus/path/test.db] {}]
  }
  sqlite4_errcode $db2
} {SQLITE4_CANTOPEN}
do_test capi3-4.4 {
  utf8 [sqlite4_errmsg16 $db2]
} {unable to open database file}
do_test capi3-4.5 {
  sqlite4_close $db2
} {SQLITE4_OK}
} ;# utf16

# This proc is used to test the following API calls:
#
# sqlite4_column_count
# sqlite4_column_name
# sqlite4_column_name16
# sqlite4_column_decltype
# sqlite4_column_decltype16
................................................................................
  # Column names in UTF-8
  do_test $test.1 {
    set cnamelist [list]
    foreach i $idxlist {lappend cnamelist [sqlite4_column_name $STMT $i]} 
    set cnamelist
  } $names

  # Column names in UTF-16
  ifcapable {utf16} {
    do_test $test.2 {
      set cnamelist [list]
      foreach i $idxlist {
        lappend cnamelist [utf8 [sqlite4_column_name16 $STMT $i]]
      }
      set cnamelist
    } $names
  }

  # Column names in UTF-8
  do_test $test.3 {
    set cnamelist [list]
    foreach i $idxlist {lappend cnamelist [sqlite4_column_name $STMT $i]} 
    set cnamelist
  } $names

  # Column names in UTF-16
  ifcapable {utf16} {
    do_test $test.4 {
      set cnamelist [list]
      foreach i $idxlist {
        lappend cnamelist [utf8 [sqlite4_column_name16 $STMT $i]]
      }
      set cnamelist
    } $names
  }

  # Column names in UTF-8
  do_test $test.5 {
    set cnamelist [list]
    foreach i $idxlist {lappend cnamelist [sqlite4_column_decltype $STMT $i]} 
    set cnamelist
  } $decltypes

  # Column declaration types in UTF-16
  ifcapable {utf16} {
    do_test $test.6 {
      set cnamelist [list]
      foreach i $idxlist {
        lappend cnamelist [utf8 [sqlite4_column_decltype16 $STMT $i]]
      }
      set cnamelist
    } $decltypes
  }


  # Test some out of range conditions:
  ifcapable {utf16} {
    do_test $test.7 {
      list \
        [sqlite4_column_name $STMT -1] \
        [sqlite4_column_name16 $STMT -1] \
        [sqlite4_column_decltype $STMT -1] \
        [sqlite4_column_decltype16 $STMT -1] \
        [sqlite4_column_name $STMT $numcols] \
        [sqlite4_column_name16 $STMT $numcols] \
        [sqlite4_column_decltype $STMT $numcols] \
        [sqlite4_column_decltype16 $STMT $numcols]
    } {{} {} {} {} {} {} {} {}}
  }
} 

# This proc is used to test the following API calls:
#
# sqlite4_column_origin_name
# sqlite4_column_origin_name16
................................................................................
# Integers
do_test $test.2 {
  set ints [list]
  foreach i $idxlist {lappend ints [sqlite4_column_int64 $STMT $i]}
  set ints
} $ints

# bytes
set lens [list]
foreach i $::idxlist {
  lappend lens [string length [lindex $strings $i]]
}
do_test $test.3 {
  set bytes [list]
  set lens [list]
  foreach i $idxlist {
    lappend bytes [sqlite4_column_bytes $STMT $i]
  }
  set bytes
} $lens

# bytes16
ifcapable {utf16} {
  set lens [list]
  foreach i $::idxlist {
    lappend lens [expr 2 * [string length [lindex $strings $i]]]
  }
  do_test $test.4 {
    set bytes [list]
    set lens [list]
    foreach i $idxlist {
      lappend bytes [sqlite4_column_bytes16 $STMT $i]
    }
    set bytes
  } $lens
}

# Blob
do_test $test.5 {
  set utf8 [list]
  foreach i $idxlist {lappend utf8 [sqlite4_column_blob $STMT $i]}
  set utf8
} $strings

................................................................................
  set utf8 [list]
  foreach i $idxlist {lappend utf8 [sqlite4_column_double $STMT $i]}
  set utf8
} $doubles

# UTF-16
ifcapable {utf16} {

  do_test $test.8 {
    set utf8 [list]
    foreach i $idxlist {lappend utf8 [utf8 [sqlite4_column_text16 $STMT $i]]}
    set utf8
  } $strings
}

................................................................................
    BEGIN;
    CREATE TABLE t1(a, b);
    INSERT INTO t1 VALUES(1, 'int');
    INSERT INTO t1 VALUES(2, 'notatype');
  }
} {}
do_test capi3-11.1.1 {
  sqlite4_get_autocommit $DB
} 0
do_test capi3-11.2 {
  set STMT [sqlite4_prepare $DB "SELECT func(b, a) FROM t1" -1 TAIL]
  sqlite4_step $STMT
} {SQLITE4_ROW}

# As of 3.6.5 a COMMIT is OK during while a query is still running -
# as long as it is a read-only query and not an incremental BLOB write.
................................................................................
#
do_test capi3-11.3.1 {
  catchsql {
    COMMIT;
  }
} {0 {}}
do_test capi3-11.3.2 {
  sqlite4_extended_errcode $DB
} {SQLITE4_OK}
do_test capi3-11.3.3 {
  sqlite4_get_autocommit $DB
} 1
do_test capi3-11.3.4 {
  db eval {PRAGMA lock_status}
} {main shared temp closed}

do_test capi3-11.4 {
  sqlite4_step $STMT
} {SQLITE4_ERROR}
................................................................................
} {SQLITE4_ERROR}
do_test capi3-11.6 {
  catchsql {
    SELECT * FROM t1;
  }
} {0 {1 int 2 notatype}}
do_test capi3-11.7 {
  sqlite4_get_autocommit $DB
} 1
do_test capi3-11.8 {
  execsql {
    CREATE TABLE t2(a);
    INSERT INTO t2 VALUES(1);
    INSERT INTO t2 VALUES(2);
    BEGIN;
    INSERT INTO t2 VALUES(3);
  }
} {}
do_test capi3-11.8.1 {
  sqlite4_get_autocommit $DB
} 0
do_test capi3-11.9 {
  set STMT [sqlite4_prepare $DB "SELECT a FROM t2" -1 TAIL]
  sqlite4_step $STMT
} {SQLITE4_ROW}
do_test capi3-11.9.1 {
  sqlite4_get_autocommit $DB
} 0
do_test capi3-11.9.2 {
  catchsql {
    ROLLBACK;
  }
} {1 {cannot rollback transaction - SQL statements in progress}}
do_test capi3-11.9.3 {
  sqlite4_get_autocommit $DB
} 0
do_test capi3-11.10 {
  sqlite4_step $STMT
} {SQLITE4_ROW}
do_test capi3-11.11 {
  sqlite4_step $STMT
} {SQLITE4_ROW}
do_test capi3-11.12 {
................................................................................
} {SQLITE4_OK}
do_test capi3-11.14 {
  execsql {
    SELECT a FROM t2;
  }
} {1 2 3}
do_test capi3-11.14.1 {
  sqlite4_get_autocommit $DB
} 0
do_test capi3-11.15 {
  catchsql {
    ROLLBACK;
  }
} {0 {}}
do_test capi3-11.15.1 {
  sqlite4_get_autocommit $DB
} 1
do_test capi3-11.16 {
  execsql {
    SELECT a FROM t2;
  }
} {1 2}

# Sanity check on the definition of 'outstanding VM'. This means any VM
................................................................................
# Make sure this works correctly and does not reference memory out of
# range.
#
do_test capi3-19.1 {
  sqlite4_prepare_tkt3134 db
} {}

# Tests of the interface when no VFS is registered.
#
if {![info exists tester_do_binarylog]} {
  db close
  vfs_unregister_all
  do_test capi3-20.1 {
    sqlite4_sleep 100
  } {0}
  vfs_reregister_all
}

finish_test







|
|









|







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
<
<
<
|
|
|

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|













<
<
<
<
<












<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<
<
<
<
<
<
<
<
<
<







<
<
<
<
<
<
<
<
<
<
<






<
<
<
<
<
<
<
<
<
<
<
<






<

<

<

<
|







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>







 







|
|







 







|


|
|







 







|
|










|
|





|
|






|
|







 







|
|






|
|







 







<
<
<
<
<
<
<
<
<
<
<

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
...
100
101
102
103
104
105
106


























107
108



109
110
111
112

















113
114
115
116
117
118
119
...
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141





142
143
144
145
146
147
148
149
150
151
152
153























154
155
156
157
158
159
160
...
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
...
344
345
346
347
348
349
350






























351
352
353
354
355
356
357
...
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
...
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
...
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
...
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
...
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
....
1056
1057
1058
1059
1060
1061
1062











1063
# capi3-5.*: Test the various sqlite4_result_* APIs
# capi3-6.*: Test that sqlite4_close fails if there are outstanding VMs.
#

set DB [sqlite4_connection_pointer db]

do_test capi3-1.0 {
  sqlite4_db_transaction_status $DB
} 0
do_test capi3-1.1 {
  set STMT [sqlite4_prepare $DB {SELECT name FROM sqlite_master} -1 TAIL]
  sqlite4_finalize $STMT
  set TAIL
} {}
do_test capi3-1.2.1 {
  sqlite4_errcode $DB
} {SQLITE4_OK}
do_test capi3-1.2.2 {
  sqlite4_errcode $DB
} {SQLITE4_OK}
do_test capi3-1.3 {
  sqlite4_errmsg $DB
} {not an error}
do_test capi3-1.4 {
  set sql {SELECT name FROM sqlite_master;SELECT 10}
  set STMT [sqlite4_prepare $DB $sql -1 TAIL]
................................................................................
    set STMT [sqlite4_prepare $DB $sql -1 TAIL]
  }
} {1}
do_test capi3-1.8.1 {
  sqlite4_errcode $DB
} {SQLITE4_ERROR}
do_test capi3-1.8.2 {


























  sqlite4_errcode $DB
} {SQLITE4_ERROR}



do_test capi3-1.9 {
  sqlite4_errmsg $DB
} {no such column: namex}


















# rename sqlite4_open sqlite4_open_old
# proc sqlite4_open {fname options} {sqlite4_open_new $fname $options}

do_test capi3-3.1 {
  set db2 [sqlite4_open test.db {}]
  sqlite4_errcode $db2
} {SQLITE4_OK}
................................................................................
do_test capi3-3.2 {
  sqlite4_close $db2
} {SQLITE4_OK}
do_test capi3-3.3 {
  catch {
    set db2 [sqlite4_open /bogus/path/test.db {}]
  }
  sqlite4_errcode $db2
} {SQLITE4_CANTOPEN}
do_test capi3-3.4 {
  sqlite4_errmsg $db2
} {unable to open database file}
do_test capi3-3.5 {
  sqlite4_close $db2
} {SQLITE4_OK}
do_test capi3-3.6.1-misuse {
  sqlite4_close $db2
} {SQLITE4_MISUSE}
do_test capi3-3.6.2-misuse {
  sqlite4_errmsg $db2
} {library routine called out of sequence}






do_test capi3-3.7 {
  set db2 [sqlite4_open]
  sqlite4_errcode $db2
} {SQLITE4_OK}
do_test capi3-3.8 {
  sqlite4_close $db2
} {SQLITE4_OK}

# rename sqlite4_open ""
# rename sqlite4_open_old sqlite4_open
























# This proc is used to test the following API calls:
#
# sqlite4_column_count
# sqlite4_column_name
# sqlite4_column_name16
# sqlite4_column_decltype
# sqlite4_column_decltype16
................................................................................
  # Column names in UTF-8
  do_test $test.1 {
    set cnamelist [list]
    foreach i $idxlist {lappend cnamelist [sqlite4_column_name $STMT $i]} 
    set cnamelist
  } $names












  # Column names in UTF-8
  do_test $test.3 {
    set cnamelist [list]
    foreach i $idxlist {lappend cnamelist [sqlite4_column_name $STMT $i]} 
    set cnamelist
  } $names












  # Column names in UTF-8
  do_test $test.5 {
    set cnamelist [list]
    foreach i $idxlist {lappend cnamelist [sqlite4_column_decltype $STMT $i]} 
    set cnamelist
  } $decltypes













  # Test some out of range conditions:
  ifcapable {utf16} {
    do_test $test.7 {
      list \
        [sqlite4_column_name $STMT -1] \

        [sqlite4_column_decltype $STMT -1] \

        [sqlite4_column_name $STMT $numcols] \

        [sqlite4_column_decltype $STMT $numcols] \

    } {{} {} {} {}}
  }
} 

# This proc is used to test the following API calls:
#
# sqlite4_column_origin_name
# sqlite4_column_origin_name16
................................................................................
# Integers
do_test $test.2 {
  set ints [list]
  foreach i $idxlist {lappend ints [sqlite4_column_int64 $STMT $i]}
  set ints
} $ints































# Blob
do_test $test.5 {
  set utf8 [list]
  foreach i $idxlist {lappend utf8 [sqlite4_column_blob $STMT $i]}
  set utf8
} $strings

................................................................................
  set utf8 [list]
  foreach i $idxlist {lappend utf8 [sqlite4_column_double $STMT $i]}
  set utf8
} $doubles

# UTF-16
ifcapable {utf16} {
breakpoint
  do_test $test.8 {
    set utf8 [list]
    foreach i $idxlist {lappend utf8 [utf8 [sqlite4_column_text16 $STMT $i]]}
    set utf8
  } $strings
}

................................................................................
    BEGIN;
    CREATE TABLE t1(a, b);
    INSERT INTO t1 VALUES(1, 'int');
    INSERT INTO t1 VALUES(2, 'notatype');
  }
} {}
do_test capi3-11.1.1 {
  sqlite4_db_transaction_status $DB
} 1
do_test capi3-11.2 {
  set STMT [sqlite4_prepare $DB "SELECT func(b, a) FROM t1" -1 TAIL]
  sqlite4_step $STMT
} {SQLITE4_ROW}

# As of 3.6.5 a COMMIT is OK during while a query is still running -
# as long as it is a read-only query and not an incremental BLOB write.
................................................................................
#
do_test capi3-11.3.1 {
  catchsql {
    COMMIT;
  }
} {0 {}}
do_test capi3-11.3.2 {
  sqlite4_errcode $DB
} {SQLITE4_OK}
do_test capi3-11.3.3 {
  sqlite4_db_transaction_status $DB
} 0
do_test capi3-11.3.4 {
  db eval {PRAGMA lock_status}
} {main shared temp closed}

do_test capi3-11.4 {
  sqlite4_step $STMT
} {SQLITE4_ERROR}
................................................................................
} {SQLITE4_ERROR}
do_test capi3-11.6 {
  catchsql {
    SELECT * FROM t1;
  }
} {0 {1 int 2 notatype}}
do_test capi3-11.7 {
  sqlite4_db_transaction_status $DB
} 0
do_test capi3-11.8 {
  execsql {
    CREATE TABLE t2(a);
    INSERT INTO t2 VALUES(1);
    INSERT INTO t2 VALUES(2);
    BEGIN;
    INSERT INTO t2 VALUES(3);
  }
} {}
do_test capi3-11.8.1 {
  sqlite4_db_transaction_status $DB
} 1
do_test capi3-11.9 {
  set STMT [sqlite4_prepare $DB "SELECT a FROM t2" -1 TAIL]
  sqlite4_step $STMT
} {SQLITE4_ROW}
do_test capi3-11.9.1 {
  sqlite4_db_transaction_status $DB
} 1
do_test capi3-11.9.2 {
  catchsql {
    ROLLBACK;
  }
} {1 {cannot rollback transaction - SQL statements in progress}}
do_test capi3-11.9.3 {
  sqlite4_db_transaction_status $DB
} 1
do_test capi3-11.10 {
  sqlite4_step $STMT
} {SQLITE4_ROW}
do_test capi3-11.11 {
  sqlite4_step $STMT
} {SQLITE4_ROW}
do_test capi3-11.12 {
................................................................................
} {SQLITE4_OK}
do_test capi3-11.14 {
  execsql {
    SELECT a FROM t2;
  }
} {1 2 3}
do_test capi3-11.14.1 {
  sqlite4_db_transaction_status $DB
} 1
do_test capi3-11.15 {
  catchsql {
    ROLLBACK;
  }
} {0 {}}
do_test capi3-11.15.1 {
  sqlite4_db_transaction_status $DB
} 0
do_test capi3-11.16 {
  execsql {
    SELECT a FROM t2;
  }
} {1 2}

# Sanity check on the definition of 'outstanding VM'. This means any VM
................................................................................
# Make sure this works correctly and does not reference memory out of
# range.
#
do_test capi3-19.1 {
  sqlite4_prepare_tkt3134 db
} {}












finish_test

Changes to test/lsm5.test

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
} {db}
do_test 1.2 {
  db write 1 one
  db write 2 two
  db close
} {}
do_test 1.3 {
  expr [file size test.db] < (64*1024)
} 1

#-------------------------------------------------------------------------
# Test that if an attempt is made to open a read-write connection to a 
# non-live database that the client does not have permission to write to is
# attempted an error is reported. In order to open a read-write connection 
# to a database, the client requires:







|







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
} {db}
do_test 1.2 {
  db write 1 one
  db write 2 two
  db close
} {}
do_test 1.3 {
  expr [file size test.db] <= (256*1024)
} 1

#-------------------------------------------------------------------------
# Test that if an attempt is made to open a read-write connection to a 
# non-live database that the client does not have permission to write to is
# attempted an error is reported. In order to open a read-write connection 
# to a database, the client requires:

Changes to test/permutations.test

149
150
151
152
153
154
155
156
157

158
159
160
161
162
163
164
  attach.test attach3.test attach4.test
  autoindex1.test
  badutf.test badutf2.test
  between.test
  bigrow.test
  bind.test
  blob.test

  boundary1.test boundary2.test boundary3.test boundary4.test

  cast.test
  coalesce.test 
  collate1.test collate2.test collate3.test collate4.test collate5.test
  collate6.test collate7.test collate8.test collate9.test collateA.test
  conflict.test 
  count.test
  cse.test







<

>







149
150
151
152
153
154
155

156
157
158
159
160
161
162
163
164
  attach.test attach3.test attach4.test
  autoindex1.test
  badutf.test badutf2.test
  between.test
  bigrow.test
  bind.test
  blob.test

  boundary1.test boundary2.test boundary3.test boundary4.test
  capi2.test
  cast.test
  coalesce.test 
  collate1.test collate2.test collate3.test collate4.test collate5.test
  collate6.test collate7.test collate8.test collate9.test collateA.test
  conflict.test 
  count.test
  cse.test

Changes to test/test_main.c

2921
2922
2923
2924
2925
2926
2927
2928

2929
2930
2931
2932
2933
2934
2935
....
4097
4098
4099
4100
4101
4102
4103












































4104
4105
4106
4107
4108
4109
4110
....
4221
4222
4223
4224
4225
4226
4227




4228
4229
4230
4231
4232
4233
4234
  rc = sqlite4_prepare(db, zSql, bytes, &pStmt, objc>=5 ? &nUsed : 0);
  Tcl_ResetResult(interp);
  if( sqlite4TestErrCode(interp, db, rc) ) return TCL_ERROR;
  if( objc>=5 ){
    const char *zTail = &zSql[nUsed];
    int nTail = -1;
    if( bytes>=0 ){
      nTail = bytes - nUsed;

    }
    Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, nTail), 0);
  }
  if( rc!=SQLITE4_OK ){
    assert( pStmt==0 );
    sprintf(zBuf, "(%d) ", rc);
    Tcl_AppendResult(interp, zBuf, sqlite4_errmsg(db), 0);
................................................................................
      Tcl_AppendResult(interp, " ", aOpt[i].zOptName);
    }
    return TCL_ERROR;
  }
  sqlite4_test_control(SQLITE4_TESTCTRL_OPTIMIZATIONS, db, mask);
  return TCL_OK;
}













































void sqlite4TestInit(Tcl_Interp *interp){
  Sqlitetest_auth_init(interp);
  Sqlitetest_num_init(interp);
  Sqlitetest_func_Init(interp);
}

................................................................................
     { "sqlite4_column_decltype",test_stmt_utf8,(void*)sqlite4_column_decltype},
#endif
#ifdef SQLITE4_ENABLE_COLUMN_METADATA
{ "sqlite4_column_database_name",test_stmt_utf8,(void*)sqlite4_column_database_name},
{ "sqlite4_column_table_name",test_stmt_utf8,(void*)sqlite4_column_table_name},
{ "sqlite4_column_origin_name",test_stmt_utf8,(void*)sqlite4_column_origin_name},
#endif





     { "sqlite4_create_collation",   test_create_collation, 0 },
     { "sqlite4_collation_needed",   test_collation_needed, 0 },
     { "sqlite4_profile",            test_profile, 0 },
     { "sqlite4_trace",              test_trace, 0 },
     { "working_64bit_int",          working_64bit_int,   0   },
     { "sqlite4_create_function_v2", test_create_function_v2, 0 },







|
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







>
>
>
>







2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
....
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
....
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
  rc = sqlite4_prepare(db, zSql, bytes, &pStmt, objc>=5 ? &nUsed : 0);
  Tcl_ResetResult(interp);
  if( sqlite4TestErrCode(interp, db, rc) ) return TCL_ERROR;
  if( objc>=5 ){
    const char *zTail = &zSql[nUsed];
    int nTail = -1;
    if( bytes>=0 ){
      nTail = (bytes - nUsed);
      if( nTail>strlen(zTail) ) nTail = strlen(zTail);
    }
    Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, nTail), 0);
  }
  if( rc!=SQLITE4_OK ){
    assert( pStmt==0 );
    sprintf(zBuf, "(%d) ", rc);
    Tcl_AppendResult(interp, zBuf, sqlite4_errmsg(db), 0);
................................................................................
      Tcl_AppendResult(interp, " ", aOpt[i].zOptName);
    }
    return TCL_ERROR;
  }
  sqlite4_test_control(SQLITE4_TESTCTRL_OPTIMIZATIONS, db, mask);
  return TCL_OK;
}

/*
** Usage: sqlite4_column_text STMT column
**
** Usage: sqlite4_column_decltype STMT column
**
** Usage: sqlite4_column_name STMT column
*/
static int test_stmt_utf16(
  void * clientData,     /* Pointer to SQLite API function to be invoked */
  Tcl_Interp *interp,
  int objc,
  Tcl_Obj *CONST objv[]
){
#ifndef SQLITE4_OMIT_UTF16
  sqlite4_stmt *pStmt;
  int col;
  Tcl_Obj *pRet;
  const void *zName16;
  const void *(*xFunc)(sqlite4_stmt*, int, int*);
  int dummy;

  xFunc = (const void *(*)(sqlite4_stmt*, int))clientData;
  if( objc!=3 ){
    Tcl_AppendResult(interp, "wrong # args: should be \"",
       Tcl_GetString(objv[0]), " STMT column", 0);
    return TCL_ERROR;
  }

  if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
  if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR;

  zName16 = xFunc(pStmt, col, &dummy);
  if( zName16 ){
    int n;
    const char *z = zName16;
    for(n=0; z[n] || z[n+1]; n+=2){}
    pRet = Tcl_NewByteArrayObj(zName16, n+2);
    Tcl_SetObjResult(interp, pRet);
  }
#endif /* SQLITE4_OMIT_UTF16 */

  return TCL_OK;
}

void sqlite4TestInit(Tcl_Interp *interp){
  Sqlitetest_auth_init(interp);
  Sqlitetest_num_init(interp);
  Sqlitetest_func_Init(interp);
}

................................................................................
     { "sqlite4_column_decltype",test_stmt_utf8,(void*)sqlite4_column_decltype},
#endif
#ifdef SQLITE4_ENABLE_COLUMN_METADATA
{ "sqlite4_column_database_name",test_stmt_utf8,(void*)sqlite4_column_database_name},
{ "sqlite4_column_table_name",test_stmt_utf8,(void*)sqlite4_column_table_name},
{ "sqlite4_column_origin_name",test_stmt_utf8,(void*)sqlite4_column_origin_name},
#endif

#ifndef SQLITE4_OMIT_UTF16
  { "sqlite4_column_text16",  test_stmt_utf16, (void*)sqlite4_column_text16},
#endif

     { "sqlite4_create_collation",   test_create_collation, 0 },
     { "sqlite4_collation_needed",   test_collation_needed, 0 },
     { "sqlite4_profile",            test_profile, 0 },
     { "sqlite4_trace",              test_trace, 0 },
     { "working_64bit_int",          working_64bit_int,   0   },
     { "sqlite4_create_function_v2", test_create_function_v2, 0 },