4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
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.
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 */
28 opendb(&err
, &db
, "test.db", 0);
29 while( !timetostop(&err
) ){
32 /* Insert lots of rows. Then delete some. */
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
);
43 execsql(&err
, &db
, "SELECT * FROM t1 ORDER BY x");
44 clear_error(&err
, SQLITE_LOCKED
);
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);
58 sql_script(&err
, &db
, "VACUUM");
59 clear_error(&err
, SQLITE_LOCKED
);
60 }while( !timetostop(&err
) );
63 print_and_free_err(&err
);
64 return sqlite3_mprintf("ok");
67 static void vacuum1(int nMs
){
70 Threadset threads
= {0};
72 opendb(&err
, &db
, "test.db", 1);
74 "CREATE TABLE t1(x PRIMARY KEY, y BLOB);"
75 "CREATE INDEX i1 ON t1(y);"
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
);