Enhance the command-line completion extension to return the names of
[sqlite.git] / test / tt3_vacuum.c
blob023fdfd74d1591670665ad64dbe5ac057f4fa4a5
1 /*
2 ** 2014 December 9
3 **
4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
6 **
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
11 *************************************************************************
13 ** This file contains multi-threaded tests that use shared-cache and
14 ** the VACUUM command.
16 ** Tests:
18 ** vacuum1
23 static char *vacuum1_thread_writer(int iTid, void *pArg){
24 Error err = {0}; /* Error code and message */
25 Sqlite db = {0}; /* SQLite database connection */
26 opendb(&err, &db, "test.db", 0);
27 i64 i = 0;
29 while( !timetostop(&err) ){
30 i++;
32 /* Insert lots of rows. Then delete some. */
33 execsql(&err, &db,
34 "WITH loop(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM loop WHERE i<100) "
35 "INSERT INTO t1 SELECT randomblob(50), randomblob(2500) FROM loop"
38 /* Delete lots of rows */
39 execsql(&err, &db, "DELETE FROM t1 WHERE rowid = :i", &i);
40 clear_error(&err, SQLITE_LOCKED);
42 /* Select the rows */
43 execsql(&err, &db, "SELECT * FROM t1 ORDER BY x");
44 clear_error(&err, SQLITE_LOCKED);
47 closedb(&err, &db);
48 print_and_free_err(&err);
49 return sqlite3_mprintf("ok");
52 static char *vacuum1_thread_vacuumer(int iTid, void *pArg){
53 Error err = {0}; /* Error code and message */
54 Sqlite db = {0}; /* SQLite database connection */
55 opendb(&err, &db, "test.db", 0);
57 do{
58 sql_script(&err, &db, "VACUUM");
59 clear_error(&err, SQLITE_LOCKED);
60 }while( !timetostop(&err) );
62 closedb(&err, &db);
63 print_and_free_err(&err);
64 return sqlite3_mprintf("ok");
67 static void vacuum1(int nMs){
68 Error err = {0};
69 Sqlite db = {0};
70 Threadset threads = {0};
72 opendb(&err, &db, "test.db", 1);
73 sql_script(&err, &db,
74 "CREATE TABLE t1(x PRIMARY KEY, y BLOB);"
75 "CREATE INDEX i1 ON t1(y);"
77 closedb(&err, &db);
79 setstoptime(&err, nMs);
81 sqlite3_enable_shared_cache(1);
82 launch_thread(&err, &threads, vacuum1_thread_writer, 0);
83 launch_thread(&err, &threads, vacuum1_thread_writer, 0);
84 launch_thread(&err, &threads, vacuum1_thread_writer, 0);
85 launch_thread(&err, &threads, vacuum1_thread_vacuumer, 0);
86 join_all_threads(&err, &threads);
87 sqlite3_enable_shared_cache(0);
89 print_and_free_err(&err);