· 8 years ago · Mar 30, 2018, 12:42 PM
1if([fileManager fileExistsAtPath:_dbPath] == YES) {
2 const char *dbPathagain = [_dbPath UTF8String];
3 if(sqlite3_open(dbPathagain, &_DB) == SQLITE_OK ) {
4 NSLog(@"database is open");
5 char *errorMessage;
6
7 const char *sql_statement = "CREATE TABLE IF NOT EXISTS NotiType(Alarm TEXT, Type TEXT, TPath TEXT)";
8
9
10 NSLog(@"created table success");
11 // sqlite3_stmt *statement = NULL;
12 // const char *dbPathagain = [ _dbPath UTF8String];
13
14 if([fileManager fileExistsAtPath:_dbPath] == YES) {
15 sqlite3_stmt *statement = NULL;
16 const char *dbPathagain = [_dbPath UTF8String];
17 if(sqlite3_open(dbPathagain, &_DB) == SQLITE_OK ) {
18 for(int itemIndex = 0; itemIndex < [azanst count];itemIndex++){
19
20 NSString *myname = [azanst objectAtIndex:itemIndex];
21 NSString *mytype = [alarmsstype objectAtIndex:itemIndex];
22 NSString *mytunepath = [alarmtune objectAtIndex:itemIndex];
23
24 NSString *insertSQLData = [NSString stringWithFormat:@"REPLACE INTO NotiType(Alarm, Type, TPath) VALUES ("%@", "%@","%@")", myname, mytype, mytunepath];
25 NSLog(@"here is alarm names %@", myname);
26 NSLog(@"here alarm types %@", mytype);
27 NSLog(@"here alarm tune path %@", mytunepath);
28 const char *insert_statement = [insertSQLData UTF8String];
29
30 sqlite3_prepare_v2(_DB, insert_statement, -1, &statement, NULL);
31
32 if (sqlite3_step(statement) == SQLITE_DONE) {
33 NSLog(@"data added successfully");
34 }
35 else {
36 NSLog(@"could not add timings");
37 }
38 }
39 sqlite3_finalize(statement);
40 sqlite3_close(_DB);
41 }
42 }
43 if (sqlite3_exec(_DB, sql_statement, NULL, NULL, &errorMessage) != SQLITE_OK) {
44 NSLog(@"failed to insert in table");
45 }
46 sqlite3_close(_DB);
47 }
48 else {
49 NSLog(@"failed to open db or cretate table");
50 NSLog(@"Database Error Message : %s", sqlite3_errmsg(_DB));
51 }
52}