Universal application DB question - iphone

I'm making an universal application for both iPhone and iPad and I was wondering if there is an specific location where I have to put my sqlite database? Because apperently he can't find it and giving a result of not being able to open the database! = app not working :/
Currently I have my database in the "Other Sources" folder.
//Maakt een lijst van path strings voor de specifieke directories voor de specifieke domains.
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//Eerste object van paths wordt in de string gezet!
NSString *documentsDir = [documentPaths objectAtIndex:0];
//er wordt gezocht naar todo.sqlite in het opgegeven path!
NSString *databasePath = [documentsDir stringByAppendingPathComponent:#"todo.sqlite"];
pad = databasePath;
if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
status = TRUE; //DEBUG PURPOSES ONLY!
const char *sql = "SELECT pk FROM todo";
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
int primaryKey = sqlite3_column_int(statement, 0);
Taak *taak = [[Taak alloc] initWithPrimaryKey:primaryKey database:database];
[taken addObject:taak];
[taak release];
}
}
sqlite3_finalize(statement);
}else {
status = FALSE; //DEBUG PURPOSES ONLY!
sqlite3_close(database);
NSAssert1(0, #"Failed to open database with message '%s'.", sqlite3_errmsg(database));
}
This is my connection code and I searched a lot of forums and tutorials and everyone is doing it like that!

if(sqlite3_open([databasepath UTF8String], &database) == SQLITE_OK) {
const char* sqlStatement;
sqlStatement="select fld_carromdescription from tbl_carrom where fld_carromdetails like?";
sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL);
printf( "could not prepare statemnt: %s\n", sqlite3_errmsg(database));
if( sqlite3_prepare_v2(database, sqlStatement, -1, & compiledStatement, NULL) == SQLITE_OK ) {
sqlite3_bind_text(compiledStatement,1,[[usdflt objectForKey:#"phone"] UTF8String] , -1,SQLITE_STATIC);
NSLog(#"Database check111");
// [tablearray removeAllObjects];
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
printf("in loop");
#try {
NSLog(#"Database check");
txtview.text=[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement,0)];
toplbl.text=[usdflt valueForKey:#"phone"];
[txtview scrollRangeToVisible:NSMakeRange(0, 0)];
}
#catch (NSException * e) {
}
#finally {
}
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
Try this out.
I am also using the sqliteDB in other sources only. I have done 3 universal applications. I have no difficulties to get the access.

Related

Prepare-error : no such table: items

this function is showing me the error that "Prepare-error #0: no such table: items
". can some one please help me out in resolving this error.
- (void)viewDidLoad
{
[super viewDidLoad];
const char *dbpath = [databasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &contactDB)== SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat:#"Select name FROM items"];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(contactDB, query_stmt, -1, &statement, NULL) == SQLITE_OK)
{ NSLog(#"Data not fetched");
if (sqlite3_step(statement) == SQLITE_ROW)
{NSLog(#"Prepare-error #%i: %s", (sqlite3_prepare_v2(contactDB, [querySQL UTF8String], -1, &statement, NULL) == SQLITE_OK), sqlite3_errmsg(contactDB));
NSString *namefeild = [[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
[list objectAtIndex:namefeild];
}
else{
NSLog(#"Data not fetched");
}
sqlite3_finalize(statement);
}else {NSLog(#"Prepare-error #%i: %s", (sqlite3_prepare_v2(contactDB, query_stmt, -1, &statement, NULL) == SQLITE_OK), sqlite3_errmsg(contactDB));}
sqlite3_close(contactDB);
}
These two functions are n different viewcontrollers.
In view didload the database is created.
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *docsDir;
NSArray *dirPath;
dirPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPath objectAtIndex:0];
databasePath = [[NSString alloc]initWithString:[docsDir stringByAppendingPathComponent:#"contactDB"]];
NSFileManager *filemgr = [NSFileManager defaultManager];
if ([filemgr fileExistsAtPath: databasePath] == NO) {
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK) {
char *errMsg;
const char *sql_stmt = "create table if not exists items(name varchar, price integer, description varchar)";
if (sqlite3_exec(contactDB, sql_stmt, NULL, NULL, &errMsg) != SQLITE_OK)
{
NSLog(#"Fail to create table");
}
sqlite3_close(contactDB);
}else{
NSLog(#"Failed to open database");
}
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
and in save action the data is added to the database.
- (IBAction)save:(id)sender {
sqlite3_stmt *statement;
const char *dbpath = [ databasePath UTF8String];
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK) {
NSString *insertSQL = [NSString stringWithFormat:#"insert into items(name, price, description) values (\"%#\",\"%#\",\"%#\")", nametxt.text, pricetxt.text, description.text];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(contactDB, insert_stmt, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
NSLog(#"contact added");
nametxt.text= #"";
pricetxt.text = #"";
description.text = #"";
}else{
NSLog(#"Failed to add contact");
}
sqlite3_finalize(statement);
sqlite3_close(contactDB);
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
const char *dbpath = [databasePath UTF8String];
NSLog("%#", databasePath);
...
...
}
Copy the database path to your clipboard and paste it into your console.
cd "[database path]"
sqlite3 database_filename.db
.dump
After the .dump command, do you see the creation statement for your table? If not, then you need to double check the location of where you are actually creating your database. It would actually be very helpful if you updated your answer with the contents of the .dump command.
Typically this means that the table does not exist in the database you opened. You should find the database in your simulator's Documents folder (~/Library/Application Support/iPhone Simulator) and, open it in your MacOS SQLite tool of choice, see for yourself whether the table is there. I suspect it will not be there.
A common source of this problem is for a file at the databasePath to not exist (e.g. you might have copy of database in the bundle, but not the Documents folder), in which case sqlite3_open will quietly create a new, blank database at databasePath.
Assuming you don't want it to create a blank database when it doesn't find it, you should:
Remove your app from the simulator/device (so that any blank databases are removed);
Check your original opening routine and use NSFileManager to check for the existence of the database if it's not already there (perhaps copying the database from the bundle to documents before continuing);
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:databasePath]) {
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:#"itemsdb" ofType:#"sqlite"];
[fileManager copyItemAtPath:bundlePath toPath:databasePath error:nil];
}
Or perhaps your code should dynamically create the table(s) if the database didn't exist, but the idea is the same. Check for existence of the file before opening it.
Perhaps in the future, consider using sqlite3_open_v2 with the SQLITE_OPEN_READWRITE option (but not the SQLITE_OPEN_CREATE option), which will not create the database for you and will report an error if the database was not found.
Having said the above (which is the general counsel when someone encounters an error like yours, where the table that you know "should" be there, isn't), there are specific issues unique to your code sample in the way you handle error reporting:
If step succeeds, you're reporting an error. Surely you meant to only do that if step failed.
The error you generate as a result of step says "prepare error". Surely that should be "step error".
Your logging of errors is calling the function that failed again in order to get the return code. You should save the return code when you first called the function, saving you from having to call it again for your error message. (This is important because sometimes the value returned by the function will change and reset your error message. Don't call the failed function again!) It's also more efficient to just save the original return code.
Thus:
if (sqlite3_open(dbpath, &contactDB)== SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat:#"Select name FROM items"];
const char *query_stmt = [querySQL UTF8String];
int rc; // variable to hold the return code
if ((rc = sqlite3_prepare_v2(contactDB, query_stmt, -1, &statement, NULL)) == SQLITE_OK)
{
if ((rc = sqlite3_step(statement)) == SQLITE_ROW)
{
NSString *namefeild = [[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(statement, 0)];
[list objectAtIndex:namefeild];
}
else {
if (rc == SQLITE_DONE)
NSLog(#"step found no data");
else
NSLog(#"step-error #%i: %s", rc, sqlite3_errmsg(contactDB));
}
sqlite3_finalize(statement);
} else {
NSLog(#"Prepare-error #%i: %s", rc, sqlite3_errmsg(contactDB));
}
sqlite3_close(contactDB);
}

Unable to remove data from database ios

I have database, but when i tried to remove data from the database nothing happens, what should i do to make sure it works? Because when i pressed delete the dta is still in the database
This is the code:
/file path to database
-(NSString*)filePath {
NSArray*paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [[paths objectAtIndex:0]stringByAppendingPathComponent:#"bp.sql"];
}
//open database
-(void)openDB {
if(sqlite3_open([[self filePath]UTF8String], &db) !=SQLITE_OK) {
sqlite3_close(db);
NSAssert(0, #"Databese failed to open");
}
else {
NSLog(#"database opemed");
}
}
- (IBAction)del:(id)sender {
NSString*sql = [NSString stringWithFormat:#"DELETE key, theDate, customer, code1, code2 FROM summary WHERE key=\"%#\"",customerName];
const char* query_stmt = [sql UTF8String];
sqlite3_stmt*statement;
sqlite3_prepare_v2(db, query_stmt, -1, & statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
NSAssert(0, #"database object delete failed");
} else {
NSLog(#"No error");
}
sqlite3_finalize(statement);
sqlite3_close(db)
You can't delete specific column values using the DELETE query. It's for removing the entire row.
The problem is with the following query:
NSString*sql = [NSString stringWithFormat:#"DELETE key, theDate, customer, code1, code2 FROM summary WHERE key=\"%#\"",customerName];
Change it to:
NSString*sql = [NSString stringWithFormat:#"DELETE FROM summary WHERE key=\"%#\"",customerName];
If you need to remove particular column value of a row use the UPDATE query.
Please check the sqlite documentation for the details
All the functions that you wrote like checking filepath, opendb should occur in the same function(maybe inside your del function).
This is how I will do it:
-(void)updateStatus:(NSString *)queryString {
NSString *docsDir;
NSArray *dirPaths;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
strDatabasePath = [NSString stringWithString:[docsDir stringByAppendingPathComponent:#"bp.sql"]];
NSFileManager *filemgr = [NSFileManager defaultManager];
if ([filemgr fileExistsAtPath: strDatabasePath] == YES)
{
const char *dbpath = [strDatabasePath UTF8String];
if (sqlite3_open(dbpath, &sqlDatabase) == SQLITE_OK)
{
const char* beginString = "BEGIN;";
sqlite3_stmt *compiledstatement;
sqlite3_prepare_v2(sqlDatabase, beginString, -1, &compiledstatement, NULL);
if (sqlite3_step(compiledstatement) == SQLITE_DONE) {}
else DLog(#"Failed!");
sqlite3_finalize(compiledstatement);
DLog(#"QUERY : %#",queryString);
const char *selectStatement = [queryString UTF8String];
sqlite3_prepare_v2(sqlDatabase, selectStatement, -1, &compiledstatement, NULL);
//sqlite3_bind_text(compiledstatement,1,[statusString UTF8String],-1,SQLITE_TRANSIENT);
if (sqlite3_step(compiledstatement) == SQLITE_DONE) {}
else DLog(#"Failed!");
sqlite3_finalize(compiledstatement);
const char* endString="END;";
sqlite3_prepare_v2(sqlDatabase, endString, -1, &compiledstatement, NULL);
if (sqlite3_step(compiledstatement) == SQLITE_DONE) {}
else DLog(#"Failed!");
sqlite3_finalize(compiledstatement);
sqlite3_close(sqlDatabase);
}
else DLog(#"Failed to open table");
}
}
NSString *queryString;
queryString = [NSString stringWithFormat:#"DELETE key, theDate, customer, code1, code2 FROM summary WHERE key=\"%#\"",customerName];
[self updateStatus:queryString];
Hope this helps...
-(BOOL)DeleteWishList:(int)rowno
{
NSString *queryString=[NSString stringWithFormat:#"delete from wishtable where _id=%d",rowno];
[self openDB];
char *err;
if (sqlite3_exec(dBObject, [queryString UTF8String], NULL,NULL, &err)!= SQLITE_OK)
{
sqlite3_close(dBObject);
return NO;
}
else
{
return YES;
}
}

Difficulty deploying database with my iphone app

I have an application that needs a database. The application is running fine in the simulator. But when i try to deploy it onto the iphone then it gives me the error that 'no such table animal'. Where is the problem? I am providing the code for better understanding
(void)viewDidLoad
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:#"AnimalDatabase.sql"];
sqlite3 *database;
if(sqlite3_open([filePath UTF8String], &database) == SQLITE_OK)
{
const char *sqlStatement = "insert into animal (id, name) VALUES (?, ?)";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
//NSLog(filePath);
sqlite3_bind_int(compiledStatement, 1, 12);
//NSLog(#"A");
sqlite3_bind_text( compiledStatement, 2, [#"abc" UTF8String], -1, SQLITE_TRANSIENT);
//NSLog(#"B");
if(sqlite3_step(compiledStatement) != SQLITE_DONE )
{
//NSLog(#"C");
NSLog( #"Error: %s", sqlite3_errmsg(database) );
}
else
{
//NSLog(#"D");
NSLog( #"Insert into row id = %d", sqlite3_last_insert_rowid(database));
}
}
else
{
NSAssert1(0, #"Error while creating insert statement. '%s'", sqlite3_errmsg(database));
}
sqlite3_finalize(compiledStatement);
}
else
{
NSLog(#"Error Occured");
}
sqlite3_close(database);
[super viewDidLoad];
}
I think you need to look at what is being transfered to your iPhone. I had issues with this, there are some strange issues around how the database is created or not created on the actual iPhone. I think what is happening in your case is that no database is being transfered, and then your call to
sqlite3_open
is actually creating the database so you don't receive an error until you call a select statement.
Check your documentation on where to place the db in your resources to ensure it is copied to your iPhone when building.
The most likely reason is that the AnimalDatabase.sql file doesn't exist so there is no Animal table to insert into.

Assertion failure when trying to write (INSERT, UPDATE) to sqlite database on iPhone

I have a really frustrating error that I've spent hours looking at and cannot fix. I can get data from my db no problem with this code, but inserting or updating gives me these errors:
*** Assertion failure in +[Functions db_insert_answer:question_type:score:], /Volumes/Xcode/Kanji/Classes/Functions.m:129
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error inserting: db_insert_answer:question_type:score:'
Here is the code I'm using:
[Functions db_insert_answer:[[dict_question objectForKey:#"JISDec"] intValue] question_type:#"kanji_meaning" score:arc4random() % 100];
//update EF, Next_question, n here
[Functions db_update_EF:[dict_question objectForKey:#"question"] EF:EF];
To call these functions:
+(sqlite3_stmt *)db_query:(NSString *)queryText{
sqlite3 *database = [self get_db];
sqlite3_stmt *statement;
NSLog(queryText);
if (sqlite3_prepare_v2(database, [queryText UTF8String], -1, &statement, nil) == SQLITE_OK) {
} else {
NSLog(#"HMM, COULDNT RUN QUERY: %s\n", sqlite3_errmsg(database));
}
sqlite3_close(database);
return statement;
}
+(void)db_insert_answer:(int)obj_id question_type:(NSString *)question_type score:(int)score{
sqlite3 *database = [self get_db];
sqlite3_stmt *statement;
char *errorMsg;
char *update = "INSERT INTO Answers (obj_id, question_type, score, date) VALUES (?, ?, ?, DATE())";
if (sqlite3_prepare_v2(database, update, -1, &statement, nil) == SQLITE_OK) {
sqlite3_bind_int(statement, 1, obj_id);
sqlite3_bind_text(statement, 2, [question_type UTF8String], -1, NULL);
sqlite3_bind_int(statement, 3, score);
}
if (sqlite3_step(statement) != SQLITE_DONE){
NSAssert1(0, #"Error inserting: %s", errorMsg);
}
sqlite3_finalize(statement);
sqlite3_close(database);
NSLog(#"Answer saved");
}
+(void)db_update_EF:(NSString *)kanji EF:(int)EF{
sqlite3 *database = [self get_db];
sqlite3_stmt *statement;
//NSLog(queryText);
char *errorMsg;
char *update = "UPDATE Kanji SET EF = ? WHERE Kanji = '?'";
if (sqlite3_prepare_v2(database, update, -1, &statement, nil) == SQLITE_OK) {
sqlite3_bind_int(statement, 1, EF);
sqlite3_bind_text(statement, 2, [kanji UTF8String], -1, NULL);
} else {
NSLog(#"HMM, COULDNT RUN QUERY: %s\n", sqlite3_errmsg(database));
}
if (sqlite3_step(statement) != SQLITE_DONE){
NSAssert1(0, #"Error updating: %s", errorMsg);
}
sqlite3_finalize(statement);
sqlite3_close(database);
NSLog(#"Update saved");
}
+(sqlite3 *)get_db{
sqlite3 *database;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *copyFrom = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"/kanji_training.sqlite"];
if([fileManager fileExistsAtPath:[self dataFilePath]]) {
//NSLog(#"DB FILE ALREADY EXISTS");
} else {
[fileManager copyItemAtPath:copyFrom toPath:[self dataFilePath] error:nil];
NSLog(#"COPIED DB TO DOCUMENTS BECAUSE IT DIDNT EXIST: NEW INSTALL");
}
if (sqlite3_open([[self dataFilePath] UTF8String], &database) != SQLITE_OK) {
sqlite3_close(database); NSAssert(0, #"Failed to open database");
NSLog(#"FAILED TO OPEN DB");
} else {
if([fileManager fileExistsAtPath:[self dataFilePath]]) {
//NSLog(#"DB PATH:");
//NSLog([self dataFilePath]);
}
}
return database;
}
+ (NSString *)dataFilePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:#"kanji_training.sqlite"];
}
I really can't work it out! Can anyone help me?
Many thanks.
in db_insert_answer, you prepare your statement
if the prepare is SQLITE_OK, you bind your variables
however, regardless of preparation OK or not, you run the statement (which could be invalid)
you also do the same thing in db_update_EF
start there
char *update = "UPDATE Kanji SET EF = ? WHERE Kanji = '?'";
Replace it with
char *update = "UPDATE Kanji SET EF = ? WHERE Kanji = ?";
It's already a string. You don't need single quotes around that question mark.

iphone sqlite3 object allocation memory up but no leaks

i've been trying to figure out wh. sqy my object allocation keeps rigth up every time i call this function, Instruments reports no leaks but I get a heck of a lot of object coming from
sqlite3_exec --> sqlite3Prepare --> sqlite3Parser --> yy_reduce --> malloc & also a whole bunch from
& from
sqlite3Step --> sqlite3VdbeExec --> sqlite3BtreeInsert --> malloc
I tried solving it by following the suggestions posted here: http://www.iphonedevsdk.com/forum/iphone-sdk-development/7092-sqlite3-database-gobbling-up-memory.html but haven't been able to fix it
ANY HELP is appreciated, my code is below
+(void)getDesignationsInLibrary:(NSString *)library
{
NSAutoreleasePool *localPool = [[NSAutoreleasePool alloc] init];
NSString *dbName = #"s8.sqlite";
NSArray *documentPaths = \
NSSearchPathForDirectoriesInDomains \
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = \
[documentPaths objectAtIndex:0];
NSString *databasePath = \
[documentsDir stringByAppendingPathComponent:dbName];
[[DT sharedDT].designationsInLibrary removeAllObjects];
NSString *sqlString;
for(int i=0;i<[[DT sharedDT].typesInLibrary count];i++)
{
if(sqlite3_open([databasePath UTF8String], &db)==SQLITE_OK)
{
if (sqlite3_exec(db, "PRAGMA CACHE_SIZE=50;", NULL, NULL, NULL) != SQLITE_OK) {
NSAssert1(0, #"Error: failed to set cache size with message '%s'.", sqlite3_errmsg(db));
}
NSMutableString *lib=[NSMutableString stringWithString:library];
[lib appendString:#"-"];
[lib appendString:[[DT sharedDT].typesInLibrary objectAtIndex:i]];
if([DT sharedDT].sortedBy==#"AISC Default")
{
sqlString = [NSString stringWithFormat:#"select DESIGNATION from \"%#\";",lib];
}
else
{
sqlString = [NSString stringWithFormat:#"select DESIGNATION from \"%#\" order by cast(%# as numeric) %#;",lib, [DT sharedDT].sortedBy, [DT sharedDT].sortAscDesc];
}
const char *sql = [sqlString cStringUsingEncoding:NSASCIIStringEncoding];
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(db,sql,-1,&selectstmt, NULL)==SQLITE_OK)
{
while(sqlite3_step(selectstmt)==SQLITE_ROW)
{
[[DT sharedDT].designationsInLibrary addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt,0)]];
}
sqlite3_finalize(selectstmt);
selectstmt=nil;
}
}
}
sqlite3_close(db);
[localPool release];
}
It seems, that you're opening db on every loop cycle, but close only once, before function exit
So try to change:
}
sqlite3_close(db);
[localPool release];
}
to
sqlite3_close(db);
}
[localPool release];
}
Or even better change:
for(int i=0;i [[DT sharedDT].typesInLibrary count];i++)
{
if(sqlite3_open([databasePath UTF8String], &db)==SQLITE_OK)
{
if (sqlite3_exec(db, "PRAGMA CACHE_SIZE=50;", NULL, NULL, NULL) != SQLITE_OK) {
NSAssert1(0, #"Error: failed to set cache size with message '%s'.", sqlite3_errmsg(db));
}
to:
if(sqlite3_open([databasePath UTF8String], &db)==SQLITE_OK)
{
if (sqlite3_exec(db, "PRAGMA CACHE_SIZE=50;", NULL, NULL, NULL) != SQLITE_OK) {
NSAssert1(0, #"Error: failed to set cache size with message '%s'.", sqlite3_errmsg(db));
}
for(int i=0;i [[DT sharedDT].typesInLibrary count];i++)
{
...
because you're always open the same database
Try invoking sqlite3_exec with:
pragma cache_size=1
Sqlite seems to gobble up memory for caching.