Hi,
I am doing some programmatic stress / benchmark testing on sqlite in the
hope it'll be of use to me in my project.
I'm performing some simple stress tests to gauge read/write speeds, whereby
I fill a table with a large amount rows
However, I hit the following problem on writing:
Creating 100000 rows...
died on row 1075
SQL error 2: unable to open database fi
Press any key to continue . . .
I'm using version 3.5.2 and my stress test code (written in C) is attached.
Does anyone have any ideas as to why it fails?
Thanks,
Ged
#include <windows.h>
#include <stdio.h>
#include <sqlite3.h>
#define TESTDB "C:\\Users\\Ged\\Desktop\\sqlite stuff\\benchmarking\\testdb"
#define MAX_ROWS 100000
static int
ReadCallback(void *NotUsed,
int argc,
char **argv,
char **azColName)
{
/* do stuff */
return 0;
}
static BOOL
FillDatabase(sqlite3 *db)
{
INT ret, i;
char *zErrMsg = 0;
BOOL bRet = FALSE;
printf("Creating %d rows...\n", MAX_ROWS);
ret = sqlite3_exec(db,
"CREATE TABLE test (ID integer primary key
autoincrement, Field1 int, Field2 VARCHAR(50))",
NULL,
0,
&zErrMsg);
if (ret == SQLITE_OK)
{
for (i = 0; i < MAX_ROWS; i++)
{
ret = sqlite3_exec(db,
"INSERT INTO test(Field1, Field2) VALUES(15,
'Hello')",
NULL,
0,
&zErrMsg);
if (ret != SQLITE_OK)
{
fprintf(stderr, "died on row %d\n", i);
fprintf(stderr, "SQL error 2: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
return FALSE;
}
//Sleep(5);
}
bRet = TRUE;
}
else
{
fprintf(stderr, "SQL error 1: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
return bRet;
}
static VOID
ReadDatabase(sqlite3 *db)
{
INT ret;
char *zErrMsg = 0;
printf("Reading %d rows...\n", MAX_ROWS);
ret = sqlite3_exec(db,
"SELECT * FROM test",
ReadCallback,
0,
&zErrMsg);
if (ret != SQLITE_OK)
{
fprintf(stderr, "SQL error: %s\n", zErrMsg);
sqlite3_free(zErrMsg);
}
}
static BOOL
OpenDatabase(sqlite3 **db)
{
INT ret;
ret = sqlite3_open(TESTDB, db);
if (ret != SQLITE_OK)
{
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(*db));
}
return (ret == SQLITE_OK);
}
static VOID
CloseDatabase(sqlite3 *db)
{
if (db)
sqlite3_close(db);
}
int main (int argc, char* argv[])
{
sqlite3 *db = NULL;
DWORD startwrite = 0, startread = 0;
DWORD endwrite = 0, endread = 0;
DeleteFileA(TESTDB);
if (OpenDatabase(&db))
{
startwrite = GetTickCount();
if (FillDatabase(db))
{
endwrite = startread = GetTickCount();
ReadDatabase(db);
endread = GetTickCount();
}
CloseDatabase(db);
}
if (endwrite)
{
INT writetime = endwrite - startwrite;
if (writetime > 1000)
{
writetime /= 1000;
if (writetime > 60)
{
int min = writetime / 60;
int sec = writetime % 60;
printf("\ncreate time - %d.%d mins\n", min, sec);
}
else
printf("\ncreate time - %d secs\n", writetime);
}
else
printf("\ncreate time - %d ms\n", writetime);
if (endread)
printf("read time - %d ms\n\n", endread - startread);
}
system("PAUSE");
return 0;
}
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------