Index: tool/tserver.c ================================================================== --- tool/tserver.c +++ tool/tserver.c @@ -78,10 +78,25 @@ return (i=='\n' || i=='\r'); } static int is_whitespace(int i){ return (i==' ' || i=='\t' || is_eol(i)); } + +/* +** Implementation of SQL scalar function usleep(). +*/ +static void usleepFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + int nUs; + sqlite3_vfs *pVfs = (sqlite3_vfs*)sqlite3_user_data(context); + assert( argc==1 ); + nUs = sqlite3_value_int64(argv[0]); + pVfs->xSleep(pVfs, nUs); +} static void trim_string(const char **pzStr, int *pnStr){ const char *zStr = *pzStr; int nStr = *pnStr; @@ -276,11 +291,10 @@ static void *handle_client(void *pArg){ char zCmd[32*1024]; /* Read buffer */ int nCmd = 0; /* Valid bytes in zCmd[] */ int res; /* Result of read() call */ int rc = SQLITE_OK; - int j; ClientCtx ctx; memset(&ctx, 0, sizeof(ClientCtx)); ctx.fd = (int)(intptr_t)pArg; @@ -288,10 +302,14 @@ rc = sqlite3_open(zDatabaseName, &ctx.db); if( rc!=SQLITE_OK ){ fprintf(stderr, "sqlite3_open(): %s\n", sqlite3_errmsg(ctx.db)); return 0; } + sqlite3_create_function( + ctx.db, "usleep", 1, SQLITE_UTF8, (void*)sqlite3_vfs_find(0), + usleepFunc, 0, 0 + ); while( rc==SQLITE_OK ){ int i; int iStart; int nConsume;