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

  • SEARCH
  • Home
  • 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 8528043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:42:52+00:00 2026-06-11T08:42:52+00:00

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES); NSString *documentsDir = [paths objectAtIndex:0]; NSFileManager *fileManager

  • 0
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];

NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *dbPath =[documentsDir stringByAppendingPathComponent:@"register.sqlite"];
BOOL success = [fileManager fileExistsAtPath:dbPath]; 
sqlite3_stmt *selectstmt;
if(!success)
        {
             NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"register.sqlite"];
            success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];

            if (!success) 
                NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
        }

if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {

    sql = "select lastname,email,firstname from reg_FORM";

    if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {

         while(sqlite3_step(selectstmt) == SQLITE_ROW) {

             lastname = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 0)];
                    email=[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)];
                    firstname=[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 2)];
                    NSLog(@"----%@",lastname);
                    NSLog(@"----%@",email);
                    NSLog(@"----%@",firstname);

                }
        sqlite3_finalize(selectstmt);
            }     
        sqlite3_close(database);
        }

I am using this code to retrieve the values in db, but I did know how to insert data in db. I am trying this below code but it does not work

const char *sql = "insert into reg_FORM (firstname,lastname,email,company,phone) VALUES (aaa,aaa,aaa,aaaa,1223)";
            sqlite3_exec(database, [[NSString stringWithFormat:@"insert into reg_FORM (firstname,lastname,email,company,phone) VALUES (aaa,aaa,aaa,aaaa,1223)"] UTF8String], NULL, NULL, NULL);    

//give code for insert values in db

  • 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-11T08:42:53+00:00Added an answer on June 11, 2026 at 8:42 am
    {
        BOOL returnValue = YES;
        sqlite3_stmt *insertStmt = nil;
        sqlite3 *UserDB ;   
        if (sqlite3_config(SQLITE_CONFIG_SERIALIZED) == SQLITE_OK)
        {
            NSLog(@"Can now use sqlite on multiple threads, using the same connection");
        }
    
        int ret = sqlite3_enable_shared_cache(1);
        if(ret != SQLITE_OK)
        {
    
        }
        // Open the database. The database was prepared outside the application.
        if (sqlite3_open([app.dataBasePath UTF8String], &UserDB) == SQLITE_OK)
        {
                if(insertStmt == nil) 
                {   
                    NSString *strValue = [NSString stringWithFormat:@"insert into languagemaster Values(?,?)"];
                    const char *sql = [strValue UTF8String];
                    if(sqlite3_prepare_v2(UserDB, sql, -1, &insertStmt, NULL) != SQLITE_OK)
                    {
                        NSLog(@"Error while creating insertStmt in tblUserAccount %@", [NSString stringWithUTF8String:(char *)sqlite3_errmsg(UserDB)]);
                        returnValue = NO;
                    }
                }
    
                if(sqlite3_bind_int(insertStmt, 1, langid) ) // langid is int
                {
                    return NO;
                }
                if(sqlite3_bind_text(insertStmt, 2, [strLanguageName  UTF8String], -1, SQLITE_TRANSIENT) != SQLITE_OK)   // strLanguageName is string
                {
                    return NO;
                }   
    
                if(SQLITE_DONE != sqlite3_step(insertStmt)) 
                {           
                    NSLog(@"Error while Executing insertStmt in tblLocation %@", [NSString stringWithUTF8String:(char *)sqlite3_errmsg(UserDB)]);           
                    returnValue = NO;
                }
    
                sqlite3_reset(insertStmt);
    
                if (insertStmt) 
                {
                    sqlite3_finalize(insertStmt);
                    insertStmt = nil;
                }
        }
        sqlite3_close(UserDB);  
    
        return returnValue;                           
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

BOOL success; NSFileManager *fileManager = [[NSFileManager defaultManager]autorelease]; NSError *error; NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *myPlistPath =
+ (void)findAndCopyOfDatabaseIfNeeded{ NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [path objectAtIndex:0]; NSFileManager
-(void)myDatabaseFunction { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [path objectAtIndex:0]; NSString *databasePath =
- (IBAction)EnterButtonPressed:(id)sender { Sqlite *sqlite = [[Sqlite alloc] init]; NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); NSString
What am I doing wrong here: NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); NSString
With the following way... NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths
I'm using: #if TARGET_IPHONE_SIMULATOR == 0 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory
I'm trying to write an image to disk: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

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.