Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. -(int) insert:(NSString *)filePath withBrand:(NSString *)brand
  2. {
  3. sqlite3* db = NULL;
  4. int rc=0;
  5. rc = sqlite3_open_v2([filePath cStringUsingEncoding:NSUTF8StringEncoding], &db, SQLITE_OPEN_READWRITE , NULL);
  6. if (SQLITE_OK != rc)
  7. {
  8. sqlite3_close(db);
  9. NSLog(@"Failed to open db connection");
  10. }
  11. else
  12. {
  13. NSString * query = [NSString
  14. stringWithFormat:@"INSERT INTO brands (bikeBrandName) VALUES (?)"];
  15. char * errMsg;
  16. rc = sqlite3_exec(db, [query UTF8String] ,NULL,NULL,&errMsg);
  17. if(SQLITE_OK != rc)
  18. {
  19. NSLog(@"Failed to insert record rc:%d, msg=%s",rc,errMsg);
  20. }
  21. sqlite3_close(db);
  22. }
  23. return rc;
  24. }
  25.  
  26. -(int) insert:(NSString *)filePath withBrand:(NSString *)brand
  27. {
  28. sqlite3* db = NULL;
  29. int rc=0;
  30. rc = sqlite3_open_v2([filePath cStringUsingEncoding:NSUTF8StringEncoding], &db, SQLITE_OPEN_READWRITE , NULL);
  31. if (SQLITE_OK != rc)
  32. {
  33. sqlite3_close(db);
  34. NSLog(@"Failed to open db connection");
  35. }
  36. else
  37. {
  38. NSString * query = [NSString
  39. stringWithFormat:@"INSERT INTO brands (bikeBrandName) VALUES ("%@")",brand];
  40. char * errMsg;
  41. rc = sqlite3_exec(db, [query UTF8String] ,NULL,NULL,&errMsg);
  42. if(SQLITE_OK != rc)
  43. {
  44. NSLog(@"Failed to insert record rc:%d, msg=%s",rc,errMsg);
  45. }
  46. sqlite3_close(db);
  47. }
  48. return rc;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement