Guest User

Untitled

a guest
Dec 18th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  2.  
  3. docsDir = [dirPaths objectAtIndex:0];
  4.  
  5. _dicData = [[NSMutableDictionary alloc] init];
  6.  
  7. // Build the path to the database file
  8. databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"Database.sqlite"]];
  9. NSLog(@"Data %@",databasePath);
  10. NSFileManager *filemgr = [NSFileManager defaultManager];
  11.  
  12. if ([filemgr fileExistsAtPath: databasePath ] == NO)
  13. {
  14. const char *dbpath = [databasePath UTF8String];
  15.  
  16. if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
  17. {
  18.  
  19. char *errMsg;
  20. const char *sql_stmt = "CREATE TABLE IF NOT EXISTS Info(ID INTEGER PRIMARY KEY AUTOINCREMENT, ALERT TEXT, XREF TEXT, text TEXT , GRAPHIC Text , PROMPT TEXT , VOICE TEXT)";
  21.  
  22. if (sqlite3_exec(contactDB, sql_stmt, NULL, NULL, &errMsg) != SQLITE_OK)
  23. {
  24. _lblstatus.text = @"Failed to create table";
  25. NSLog(@"SSS %@",_lblstatus.text);
  26. }
  27.  
  28. sqlite3_close(contactDB);
  29.  
  30. } else {
  31. _lblstatus.text = @"Failed to open/create database";
  32. NSLog(@"SSS %@",_lblstatus.text);
  33. }
  34.  
  35. - (IBAction)btnSave:(id)sender {
  36.  
  37. sqlite3_stmt *statement;
  38.  
  39. const char *dbpath = [databasePath UTF8String];
  40.  
  41. if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
  42. {
  43. NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO Info(ID, ALERT, XREF,TEXT,GRAPHIC,PROMPT,VOICE) VALUES ("%@", "%@", "%@","%@","%@","%@","%@")", _lblID.text, _lblAlert.text, _lblxref.text,_lbltext.text, _lblgraphic.text, _lblprompt.text,_lblvoice.text];
  44. NSLog(@"DDD %@",insertSQL);
  45.  
  46. const char *insert_stmt = [insertSQL UTF8String];
  47.  
  48. sqlite3_prepare_v2(contactDB, insert_stmt, -1, &statement, NULL);
  49. NSLog(@"Error");
  50. /* if (sqlite3_step(statement) == SQLITE_DONE)
  51. {
  52. _lblstatus.text = @"Contact added";
  53.  
  54. } else {
  55. _lblstatus.text = @"Failed to add contact";
  56. }*/
  57. sqlite3_finalize(statement);
  58. sqlite3_close(contactDB);
  59. }
  60.  
  61.  
  62. }
Add Comment
Please, Sign In to add comment