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 7080495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:48:09+00:00 2026-05-28T06:48:09+00:00

I made iPad application in which, I want to insert record into database table,

  • 0

I made iPad application in which,

I want to insert record into database table, but I am unable to do the same.

here is my code snippet,

-(void) insertRecordIntoTableNamed: (NSString *) symbol{

NSString *sql = [NSString stringWithFormat:@"INSERT INTO recentquotes ('symbol', 'dt_tm') VALUES ('%@',datetime())",symbol];

   NSLog(@"sql=%@",sql);

    char *err;                          

    if (sqlite3_exec(db, [sql UTF8String], NULL, NULL, &err) != SQLITE_OK)
    {
        sqlite3_close(db);
        NSAssert(0, @"Error updating table.");
    }

}

my NSLog shows:

sql=INSERT INTO recentquotes ('symbol', 'dt_tm') VALUES ('PATNI',datetime())

this statement is correct, but i am unable to see VALUES PATNI and datetime() in my database table

here is rest of the code,

NSString *filePahs = Nil;
-(NSString *) filePath {

    filePahs=[[NSBundle mainBundle] pathForResource:@"companymaster" ofType:@"sql"];
    NSLog(@"path=%@",filePahs);
    return filePahs;
}

result of above method is:

path=/Users/krunal/Library/Application Support/iPhone Simulator/5.0/Applications/9FF61238-2D1D-4CB7-8E24-9AC7CE9415BC/iStock kotak.app/companymaster.sql

-(void) openDB {
    //---create database---

    if (sqlite3_open([[self filePath] UTF8String], &db) != SQLITE_OK )
    {
        sqlite3_close(db);
        NSAssert(0, @"Database failed to open.");
    }
}



-(void) getAllRowsFromTableNamed: (NSString *) tableName {
    //---retrieve rows---
    NSString *qsql = @"SELECT * FROM recentquotes";
    sqlite3_stmt *statement;

    if (sqlite3_prepare_v2( db, [qsql UTF8String], -1, &statement, nil) ==
        SQLITE_OK) {
        NSLog(@"b4 while");
        while (sqlite3_step(statement) == SQLITE_ROW)
        {
            char *field1 = (char *) sqlite3_column_text(statement, 0);
                NSString *field1Str = [[NSString alloc] initWithUTF8String: field1]; 

            [recentqotarray addObject:field1Str];
            [field1Str release];

        }
        //---deletes the compiled statement from memory---
        sqlite3_finalize(statement);
        NSLog(@"recentqotarray=%@",recentqotarray);
    }   
}

edit

i wrote this, and when i checked my log i got like this, “in find data” , i didn’t got my sql=…

     - (void) finddata
{
    NSString *databasePath;
    const char *dbpath = [databasePath UTF8String];
    sqlite3_stmt    *statement;

    NSLog(@"in finddata");
    if (sqlite3_open(dbpath, &db) == SQLITE_OK)
    {
        NSString *querySQL = [NSString stringWithFormat: @"SELECT * FROM recentquotes"];
        NSLog(@"sql=%@",querySQL);
        const char *query_stmt = [querySQL UTF8String];

        if (sqlite3_prepare_v2(db, query_stmt, -1, &statement, NULL) == SQLITE_OK)
        {
            while (sqlite3_step(statement) == SQLITE_ROW)
            {                
                NSLog(@"Inside recent quote table");
                char *field1 = (char *) sqlite3_column_text(statement, 0);
                NSLog(@"Column name=%s",field1);
                NSString *field1Str = [[NSString alloc] initWithUTF8String: field1]; 


                [recentqotarray addObject:field1Str];
                NSLog(@"array=%@",recentqotarray);

              } 
            sqlite3_finalize(statement);
        }
        sqlite3_close(db);
    }
}

Thanks In Advance

  • 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-05-28T06:48:09+00:00Added an answer on May 28, 2026 at 6:48 am

    In your:

    NSString *sql = [NSString stringWithFormat:@"INSERT INTO recentquotes ('symbol', 'dt_tm') VALUES ('%@',datetime())",symbol];
    

    Instead of '%@' try using \"%@\" , and check if it inserts into your db.

    EDIT:

    I’ve been working on DB a lot lately, and i’ve been able to successfully insert data in my sqlite, i’ll write down what i use check if it helps:

    NSArray*dirPath;
    NSString*docDir;
    
    
    dirPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    docDir=[dirPath objectAtIndex:0];
    databasePath=[docDir stringByAppendingPathComponent:@"example.sqlite"];
    
    
    BOOL success;
    
    NSFileManager*fm=[NSFileManager defaultManager];
    success=[fm fileExistsAtPath:databasePath];
    
    if(success)
    {
       NSLog(@"Already present");
    }
    
    NSString*bundlePath=[[NSBundle mainBundle] pathForResource:@"example" ofType:@"sqlite"];
    NSError*error;
    success=[fm copyItemAtPath:bundlePath toPath:databasePath error:&error];
    
    if(success)
    {
        NSLog(@"Created successfully");
    }
    const char*dbPath=[databasePath UTF8String];
    
    if(sqlite3_open(dbPath, &myDB)==SQLITE_OK)
    {
    
            NSString*insertSQL=[NSString stringWithFormat:@"insert into extable (name) values (\"%@\")",[nametextField.text]];
    
            const char*insertStmt=[insertSQL UTF8String];
            char *errmsg=nil;
    
            if(sqlite3_exec(myDB, insertStmt, NULL, NULL, &errmsg)==SQLITE_OK)
            {
                NSLog(@"ADDED!");
            }
    
     sqlite3_close(myDB);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made an iPad application in which I want to support orientation, so I've
i have made iPhone Application and i want to make it iPad Compatible without
I made a application for Ipad and it was working fine on simultor but
i made iPad application, i want to fetch data from this url, http://ipad.idealake.com/stockquote.aspx?id=SBIN and
I have an nascent iPad application, which stores documents internally on the device in
Today I faced a strange problem. I have an application which is the same
I have made my application universal for iPhone and iPad (window-based application; universal) from
I'm trying to layout several custom views in a landscape iPad application (made landscape
I am currently developing an iPad application. I want this to communicate with a
So, I've made a collapsible menu into a web site based system which minimised

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.