I am having foreign key constraint in my table but when i am inserting data using terminal it is working fine but when i doing it in xcode project it is not working
what may be the problem.
how can i enable pragma foreign_keys = ON,through program.
I am using below code for insertion but i think foreign key is not enabled.
just tell me how can i enable foreign keys through program.
+(BOOL)insertEmployee:(int)din :(NSString*)name{
NSArray *arrDocPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *strDestPath = [NSString stringWithFormat:@"%@/samplepillbox1.sqlite",[arrDocPath objectAtIndex:0]];
sqlite3 *dbEmployee;
if(sqlite3_open([strDestPath UTF8String], &dbEmployee)==SQLITE_OK)
{
//NSString *insertQuery = [NSString stringWithFormat:@"insert into maintable_master(din,brand_name) values(%d,'%@')",din,name];
//NSString *insertQuery = [NSString stringWithFormat:@"insert into doctor_master(din,firstname) values(%d,'%@')",din,name];
NSString *insertQuery = [NSString stringWithFormat:@"insert into schedule_master(din,start_date) values(%d,'%@')",din,name];
void *v;
char *errmsg;
if(sqlite3_exec(dbEmployee, [insertQuery UTF8String], 0, v, &errmsg)==SQLITE_OK)
{
NSLog(@"inserted successfully");
return YES;
}
}
return NO;}
You should be able to set the pragma just as you would run a more standard SQL statement. Typically, you set the pragma immediately after opening the database connection.
So your code should look something along this: