#include "sqlite3.h"
#include <stdio.h>
#include <time.h>
int main(int argc, char *argv[])
{
if( argc < 2 )
{
return 1;
}
time_t time_start = time(0);
const char *inputdirectory = argv[1];
unsigned int nfiles = d.
Load( inputdirectory,
true);
if( !b ) return 1;
time_t time_scanner = time(0);
std::cout << "Finished loading data from : " << nfiles << " files" << std::endl;
sqlite3* db;
sqlite3_open("./dicom.db", &db);
if(db == 0)
{
std::cerr << "Could not open database." << std::endl;
return 1;
}
const char sql_stmt[] = "create table browser (seriesuid, studyuid)";
int ret;
char *errmsg;
ret = sqlite3_exec(db, sql_stmt, 0, 0, &errmsg);
if(ret != SQLITE_OK)
{
printf("Error in statement: %s [%s].\n", sql_stmt, errmsg);
return 1;
}
Directory::FilenamesType::const_iterator file = files.begin();
sqlite3_stmt *stmt;
if ( sqlite3_prepare(
db,
"insert into browser values (?,?)",
-1,
&stmt,
0
)
!= SQLITE_OK)
{
printf("\nCould not prepare statement.");
return 1;
}
for(; file != files.end(); ++file)
{
const char *filename = file->c_str();
bool b = s.
IsKey(filename);
if( b )
{
const Scanner::TagToValue &mapping = s.
GetMapping(filename);
Scanner::TagToValue::const_iterator it = mapping.begin();
sqlite3_reset(stmt);
for( int index = 1; it != mapping.end(); ++it, ++index)
{
const char *value = it->second;
if (sqlite3_bind_text (
stmt,
index,
value,
strlen(value),
SQLITE_STATIC
)
!= SQLITE_OK)
{
printf("\nCould not bind int.\n");
return 1;
}
}
if (sqlite3_step(stmt) != SQLITE_DONE)
{
printf("\nCould not step (execute) stmt.\n");
return 1;
}
}
}
sqlite3_close(db);
time_t time_sqlite = time(0);
std::cout << "Time to scan DICOM files: " << (time_scanner - time_start) << std::endl;
std::cout << "Time to build SQLITE3: " << (time_sqlite - time_scanner) << std::endl;
return 0;
}