It looks like you're new here. If you want to get involved, click one of these buttons!
-(id)init {
self=[super init];
//Database Name
DBName=@\"chathistory.sqlite\";
//Getting Database path
NSArray *documentsPaths=NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString *documentsDir=[documentsPaths objectAtIndex:0];
DBPath =[documentsDir stringByAppendingPathComponent:DBName];
NSLog(@\"%@\",DBPath);
return self;
}
-(void)checkAndCreateDatabase{
BOOL Success;
//NSFileManager maintains File
NSFileManager *FileManager=[NSFileManager defaultManager];
//Checks Database Path
Success=[FileManager fileExistsAtPath:DBPath];
//if file exists it returns true
if (Success) {
return;
NSLog(@\"database failed\");
}
NSString *databasePathFromApp=[[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:DBName];
NSLog(@\"database created\");
[FileManager copyItemAtPath:databasePathFromApp toPath:DBPath error:nil];
}
-(void)insertDataUsername:(NSString *)user conv:(NSString *)sconv {
[self checkAndCreateDatabase];
//To setup Database object
sqlite3 *database;
[COLOR=\"Red\"] if (sqlite3_open([DBPath UTF8String], &database)== SQLITE_OK) {[/COLOR]
NSString *statement;
sqlite3_stmt *compliedstatement;
statement=[[NSString alloc]initWithFormat:@\"INSERT INTO usertable VALUES('%@', '%@')\",user,sconv];
NSLog(@\"%@,, %@\",user,sconv);
const char *sqlstatement =[statement UTF8String];
if (sqlite3_prepare_v2(database, sqlstatement, -1, &compliedstatement, NULL)==SQLITE_OK) {
//sqlite3_step(compiledstatement) executes the statement...
if (SQLITE_DONE!=sqlite3_step(compliedstatement)) {
NSAssert1(0, @\"Error by inserting. '%s'\", sqlite3_errmsg(database));
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@\"Error\" message:@\"Error by inserting\" delegate:self cancelButtonTitle:@\"Ok\" otherButtonTitles:@\"Done\", nil];
[alert show];
}
else
{
UIAlertView *alert1=[[UIAlertView alloc]initWithTitle:@\"Success!\" message:@\"Data Successfully Entered\" delegate:self cancelButtonTitle:@\"Ok\" otherButtonTitles:@\"Done\", nil];
[alert1 show];
}
}
sqlite3_finalize(compliedstatement);
}
//Closing Database
sqlite3_close(database);
}
Replies
Is there anyone to help me out!
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome