tags:

views:

1099

answers:

2
  NSString *event=@"max";
NSString *venue=@"tvm";
NSString *edate=@"may 6";
NSString *etime=@"10:30";
int admts=5;
NSString *ima=ticobj.iimg;
sqlite3 *database;
databaseName = @"smbhDB.sql";
sqlite3_stmt *addStatement ;
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
if(addStatement == nil) {
 const char *sql ="insert into tickets (admittance, venue, event, date, time, imagedata) Values (?,?,?,?,?,?)";

 if(sqlite3_prepare_v2(database, sql, -1, &addStatement, NULL) != SQLITE_OK)
  NSAssert1(0, @"444 Error while creating add  statement. '%s'", sqlite3_errmsg(database));
}

sqlite3_bind_int(addStatement,1,admts);

sqlite3_bind_text(addStatement, 2, [venue UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStatement, 3, [event UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStatement, 4, [edate UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStatement, 5, [etime UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(addStatement, 6, [ima UTF8String], -1, SQLITE_TRANSIENT);

if(SQLITE_DONE != sqlite3_step(addStatement))
 NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));

if(sqlite3_prepare_v2(database, sql, -1, &Statement, NULL) == SQLITE_OK) { sqlite3_exec(database, sql, -1, &Statement, NULL); }

sqlite3_reset(addStatement);

i can't execute this code . i don't konw what is the reason.. pls point me what is the error.

+2  A: 

Where is

sqlite3_open([databasePath UTF8String], &database); ?

You can't work with closed database

oxigen
A: 

I have a similar problem and my code does try to save the recordset. However, it craps out at 250 records every time? Does anyone know why would stop and then throw an assertion error message out?

Here is a snippet of code

if(isDirty) { if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) { if(updateStmt == nil) { const char *sql = "UPDATE AllPlayers SET Rank = ?, Status = ? WHERE PlayerID = ?"; if(sqlite3_prepare_v2(database, sql, -1, &updateStmt, NULL) != SQLITE_OK) NSAssert1(0, @"Error while creating update statement. '%s'", sqlite3_errmsg(database)); }

  // bind value to the sql parameters 
  sqlite3_bind_text(updateStmt, 1, [strRank UTF8String], -1, SQLITE_TRANSIENT);
  sqlite3_bind_text(updateStmt, 2, [strStatus UTF8String], -1, SQLITE_TRANSIENT);
  sqlite3_bind_text(updateStmt, 5, [strPlayerID UTF8String], -1, SQLITE_TRANSIENT);
   NSLog(@"name=%@",strFullName);
  if(SQLITE_DONE != sqlite3_step(updateStmt))
   NSAssert1(0, @"Error while updating. '%s'", sqlite3_errmsg(database));

  sqlite3_reset(updateStmt);

  isDirty = NO;
  }
}