Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7856449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:43:07+00:00 2026-06-02T20:43:07+00:00

I am having foreign key constraint in my table but when i am inserting

  • 0

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;}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:43:10+00:00Added an answer on June 2, 2026 at 8:43 pm

    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:

    // 1. open the connection
    ...
    
    // 2. set the pragma
    if (sqlite3_exec(dbEmployee, @"PRAGMA foreign_keys = ON", 0, v, &errmsg) != SQLITE_OK)
    {
        NSLog(@"failed to set the foreign_key pragma");
        return -1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble figuring out how to create a foreign key constraint. My data
In mysql i m selecting from a table shouts having a foreign key to
I'm trying to add a foreign key to an existing table, and was having
I'm working on a database backup engine using JPA. Everything is working fine but
I've been having problems creating a foreign key in Java Db through Netbeans. I'm
I'm having a problem with foreign key in mysql.I'm trying to insert a row
I am having trouble with foreign keys Dynamic Data and entity framework 4.0. It
I'm trying to get CodeFirst working, and am having a problem with foreign keys
I'm having a trouble with getting the id after inserting a new Record using
I'm having some problems implementing an algorithm to read a foreign process' memory. Here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.