first of all I am from spain so sorry about my grammar. I am writing some data to a sqlite data base, here is my code:
@try {
NSFileManager *fileMgr=[NSFileManager defaultManager];
NSString *dbPath=[[[NSBundle mainBundle]resourcePath] stringByAppendingPathComponent:@"capturas.sqlite"];
BOOL succes=[fileMgr fileExistsAtPath:dbPath];
if(!succes)
{
NSLog(@"Cannot locate database '%@'.",dbPath);
}
if (!(sqlite3_open([dbPath UTF8String], &dbcapturas)==SQLITE_OK)) {
NSLog(@"An error has occured: %@",sqlite3_errmsg(dbcapturas));
}
//sqlite3_stmt *sqlStatement;
NSString *asd=numero.text;
NSString *insertStatement=[NSString stringWithFormat:@"INSERT INTO captura(key,tecnico, fecha,provincia,municipio,latitud,longitud,altura,familia,especie,numero,comentario)Values(\"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\", \"%@\")",asd,tecnico,fechaHora,tecnico,municipio,latitud,longitud,altura,tecnico,animal,asd,coment];
char *error;
if((sqlite3_exec(dbcapturas, [insertStatement UTF8String], NULL, NULL, &error))==SQLITE_OK)
{
NSLog(@"Person inserted.");
}
else
{
NSLog(@"Error: %s", error);
}
} @catch (NSException *exception) {
NSLog(@"fail");
}
@finally {
}
the first time I click on the save button I get:
2012-07-04 12:17:45.644 adasdasd[1783:f803] Person inserted.
and the second time I get :
2012-07-04 12:29:18.959 adasdasd[1840:f803] Error: column key is not unique
So my code should be ok but when I open the database its totally empty, any idea?