aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/threadtest1.c44
-rw-r--r--test/threadtest2.c20
2 files changed, 31 insertions, 33 deletions
diff --git a/test/threadtest1.c b/test/threadtest1.c
index 5aad85ee3..f5ff112e6 100644
--- a/test/threadtest1.c
+++ b/test/threadtest1.c
@@ -41,17 +41,17 @@ static void Exit(int rc){
exit(rc);
}
-extern char *sqlite_mprintf(const char *zFormat, ...);
-extern char *sqlite_vmprintf(const char *zFormat, va_list);
+extern char *sqlite3_mprintf(const char *zFormat, ...);
+extern char *sqlite3_vmprintf(const char *zFormat, va_list);
/*
** When a lock occurs, yield.
*/
-static int db_is_locked(void *NotUsed, int iNotUsed){
+static int db_is_locked(void *NotUsed, int iCount){
/* sched_yield(); */
- if( verbose ) printf("BUSY %s\n", (char*)NotUsed);
+ if( verbose ) printf("BUSY %s #%d\n", (char*)NotUsed, iCount);
usleep(100);
- return 1;
+ return iCount<25;
}
/*
@@ -90,7 +90,7 @@ static int db_query_callback(
if( azArg==0 ) return 0;
for(i=0; i<nArg; i++){
pResult->azElem[pResult->nElem++] =
- sqlite_mprintf("%s",azArg[i] ? azArg[i] : "");
+ sqlite3_mprintf("%s",azArg[i] ? azArg[i] : "");
}
return 0;
}
@@ -106,15 +106,15 @@ char **db_query(sqlite *db, const char *zFile, const char *zFormat, ...){
va_list ap;
struct QueryResult sResult;
va_start(ap, zFormat);
- zSql = sqlite_vmprintf(zFormat, ap);
+ zSql = sqlite3_vmprintf(zFormat, ap);
va_end(ap);
memset(&sResult, 0, sizeof(sResult));
sResult.zFile = zFile;
if( verbose ) printf("QUERY %s: %s\n", zFile, zSql);
- rc = sqlite_exec(db, zSql, db_query_callback, &sResult, &zErrMsg);
+ rc = sqlite3_exec(db, zSql, db_query_callback, &sResult, &zErrMsg);
if( rc==SQLITE_SCHEMA ){
if( zErrMsg ) free(zErrMsg);
- rc = sqlite_exec(db, zSql, db_query_callback, &sResult, &zErrMsg);
+ rc = sqlite3_exec(db, zSql, db_query_callback, &sResult, &zErrMsg);
}
if( verbose ) printf("DONE %s %s\n", zFile, zSql);
if( zErrMsg ){
@@ -123,7 +123,7 @@ char **db_query(sqlite *db, const char *zFile, const char *zFormat, ...){
free(zSql);
Exit(1);
}
- sqlite_freemem(zSql);
+ sqlite3_free(zSql);
if( sResult.azElem==0 ){
db_query_callback(&sResult, 0, 0, 0);
}
@@ -140,22 +140,20 @@ void db_execute(sqlite *db, const char *zFile, const char *zFormat, ...){
char *zErrMsg = 0;
va_list ap;
va_start(ap, zFormat);
- zSql = sqlite_vmprintf(zFormat, ap);
+ zSql = sqlite3_vmprintf(zFormat, ap);
va_end(ap);
if( verbose ) printf("EXEC %s: %s\n", zFile, zSql);
- rc = sqlite_exec(db, zSql, 0, 0, &zErrMsg);
- while( rc==SQLITE_SCHEMA ){
- if( zErrMsg ) free(zErrMsg);
- rc = sqlite_exec(db, zSql, 0, 0, &zErrMsg);
- }
+ do{
+ rc = sqlite3_exec(db, zSql, 0, 0, &zErrMsg);
+ }while( rc==SQLITE_BUSY );
if( verbose ) printf("DONE %s: %s\n", zFile, zSql);
if( zErrMsg ){
fprintf(stdout,"%s: command failed: %s - %s\n", zFile, zSql, zErrMsg);
free(zErrMsg);
- sqlite_freemem(zSql);
+ sqlite3_free(zSql);
Exit(1);
}
- sqlite_freemem(zSql);
+ sqlite3_free(zSql);
}
/*
@@ -164,7 +162,7 @@ void db_execute(sqlite *db, const char *zFile, const char *zFormat, ...){
void db_query_free(char **az){
int i;
for(i=0; az[i]; i++){
- sqlite_freemem(az[i]);
+ sqlite3_free(az[i]);
}
free(az);
}
@@ -207,12 +205,12 @@ static void *worker_bee(void *pArg){
printf("%s: START\n", zFilename);
fflush(stdout);
for(cnt=0; cnt<10; cnt++){
- db = sqlite_open(&zFilename[2], 0, &azErr);
+ sqlite3_open(&zFilename[2], &db);
if( db==0 ){
fprintf(stdout,"%s: can't open\n", zFilename);
Exit(1);
}
- sqlite_busy_handler(db, db_is_locked, zFilename);
+ sqlite3_busy_handler(db, db_is_locked, zFilename);
db_execute(db, zFilename, "CREATE TABLE t%d(a,b,c);", t);
for(i=1; i<=100; i++){
db_execute(db, zFilename, "INSERT INTO t%d VALUES(%d,%d,%d);",
@@ -233,7 +231,7 @@ static void *worker_bee(void *pArg){
db_check(zFilename, "readback", az, z1, z2, 0);
}
db_execute(db, zFilename, "DROP TABLE t%d;", t);
- sqlite_close(db);
+ sqlite3_close(db);
}
printf("%s: END\n", zFilename);
/* unlink(zFilename); */
@@ -263,7 +261,7 @@ int main(int argc, char **argv){
unlink(zBuf);
}
for(i=0; i<n; i++){
- zFile = sqlite_mprintf("%d.testdb-%d", i%2+1, (i+2)/2);
+ zFile = sqlite3_mprintf("%d.testdb-%d", i%2+1, (i+2)/2);
unlink(zFile);
pthread_create(&id, 0, worker_bee, (void*)zFile);
pthread_detach(id);
diff --git a/test/threadtest2.c b/test/threadtest2.c
index 7b08d37b9..deaffdaf0 100644
--- a/test/threadtest2.c
+++ b/test/threadtest2.c
@@ -57,12 +57,12 @@ int integrity_check(sqlite *db){
int rc;
if( all_stop ) return 0;
/* fprintf(stderr,"pid=%d: CHECK\n", getpid()); */
- rc = sqlite_exec(db, "pragma integrity_check", check_callback, 0, 0);
+ rc = sqlite3_exec(db, "pragma integrity_check", check_callback, 0, 0);
if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
fprintf(stderr,"pid=%d, Integrity check returns %d\n", getpid(), rc);
}
if( all_stop ){
- sqlite_exec(db, "pragma integrity_check", check_callback, 0, 0);
+ sqlite3_exec(db, "pragma integrity_check", check_callback, 0, 0);
}
return 0;
}
@@ -76,14 +76,14 @@ void *worker(void *notUsed){
int cnt = 0;
while( !all_stop && cnt++<10000 ){
if( cnt%1000==0 ) printf("pid=%d: %d\n", getpid(), cnt);
- while( (db = sqlite_open(DB_FILE, 0, 0))==0 ) sched_yield();
- sqlite_exec(db, "PRAGMA synchronous=OFF", 0, 0, 0);
+ while( (sqlite3_open(DB_FILE, &db))!=SQLITE_OK ) sched_yield();
+ sqlite3_exec(db, "PRAGMA synchronous=OFF", 0, 0, 0);
integrity_check(db);
- if( all_stop ){ sqlite_close(db); break; }
+ if( all_stop ){ sqlite3_close(db); break; }
/* fprintf(stderr, "pid=%d: BEGIN\n", getpid()); */
- rc = sqlite_exec(db, "INSERT INTO t1 VALUES('bogus data')", 0, 0, 0);
+ rc = sqlite3_exec(db, "INSERT INTO t1 VALUES('bogus data')", 0, 0, 0);
/* fprintf(stderr, "pid=%d: END rc=%d\n", getpid(), rc); */
- sqlite_close(db);
+ sqlite3_close(db);
}
return 0;
}
@@ -97,17 +97,17 @@ int main(int argc, char **argv){
pthread_t aThread[5];
if( strcmp(DB_FILE,":memory:") ) unlink(DB_FILE);
- db = sqlite_open(DB_FILE, 0, 0);
+ sqlite3_open(DB_FILE, &db);
if( db==0 ){
fprintf(stderr,"unable to initialize database\n");
exit(1);
}
- rc = sqlite_exec(db, "CREATE TABLE t1(x);", 0,0,0);
+ rc = sqlite3_exec(db, "CREATE TABLE t1(x);", 0,0,0);
if( rc ){
fprintf(stderr,"cannot create table t1: %d\n", rc);
exit(1);
}
- sqlite_close(db);
+ sqlite3_close(db);
for(i=0; i<sizeof(aThread)/sizeof(aThread[0]); i++){
pthread_create(&aThread[i], 0, worker, 0);
}