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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:22:04+00:00 2026-06-11T19:22:04+00:00

i want to save some text into my database with foloowing code. But i

  • 0

i want to save some text into my database with foloowing code. But i can´t get it work…Useally that is the way to store smt into a Database…

-(void)saveToDB
{
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *dbPath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"datenbankSpeed"];
BOOL success = [fileMgr fileExistsAtPath:dbPath];
if(!success)
{
    NSLog(@"Cannot locate database file '%@'.", dbPath);
}
if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
{
    NSLog(@"An error has occured: %s", sqlite3_errmsg(db));

}


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

    NSString *insertSQL = [NSString stringWithFormat:@"INSERT INTO DATEN(typ, date, download, upload, ping, comment) VALUES (\"%@\", \"%@\", \"%@\",\"%@\", \"%@\",\"%@\")", @"1", @"24.09.2012", topDownloadLabel.text, topUploadLabel.text, pingLabel.text, @"Comment"];

    const char *insert_stmt = [insertSQL UTF8String];
    printf("%s\n", insert_stmt);
    NSLog(@"%@", [NSString stringWithUTF8String:insert_stmt]);

    if (sqlite3_prepare_v2(db, insert_stmt, -1, &sqlStatement, NULL) == SQLITE_OK)
    {
        if (sqlite3_step(sqlStatement) == SQLITE_DONE)
        {
            UIAlertView *didFailWithErrorMessage = [[UIAlertView alloc] initWithTitle: @"NSURLConnection " message: @"All good"  delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
            [didFailWithErrorMessage show];
            [didFailWithErrorMessage release];
        }
        else
        {
            UIAlertView *didFailWithErrorMessage = [[UIAlertView alloc] initWithTitle: @"NSURLConnection " message: @"nada"  delegate: self cancelButtonTitle: @"Ok" otherButtonTitles: nil];
            [didFailWithErrorMessage show];
            [didFailWithErrorMessage release];
        }

    }
            sqlite3_finalize(sqlStatement);
    sqlite3_close(db);
}
}

but for some reason it only works in the simulator! But on my phone it won´t work… It always goes into the ELSE here:

if (sqlite3_step(sqlStatement) == SQLITE_DONE)
  • 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-11T19:22:06+00:00Added an answer on June 11, 2026 at 7:22 pm

    I am unable to find the issue, however i have some suggesions,

    Not sure if this is your main problem, but it looks like you’re modifying your database right in the bundle, which is too bad. The bundle is going to get erased/replaced when you release an update, for example.

    When you app starts, you should look for the database in the documents directory, and if it’s not there, (which it won’t be the first time you start) you copy your default database from the bundle to the docs directory.

    Code:

    - (void)applicationDidFinishLaunching:(UIApplication *)application {
    
        [self copyDatabaseIfNeeded];
    
        // Configure and show the window
        [window addSubview:[navigationController view]];
        [window makeKeyAndVisible];
    }
    
    - (void) copyDatabaseIfNeeded {
    
        //Using NSFileManager we can perform many file system operations.
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSError *error;
        NSString *dbPath = [self getDBPath];
        BOOL success = [fileManager fileExistsAtPath:dbPath]; 
    
        if(!success) {
    
            NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@\"datenbankSpeed.sqlite\"];
            success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];
            NSLog(@\"Database file copied from bundle to %@\", dbPath);
    
            if (!success) 
                NSAssert1(0, @\"Failed to create writable database file with message '%@'.\", [error localizedDescription]);
        } else {
    
            NSLog(@\"Database file found at path %@\", dbPath);
    
        }
    }
    

    Device is Case Sensitive. iPhone device care about case of the string,

    example “database.sqlite” and “DataBase.sqlite” is different files for device, but the same files for simulator.So please check you query or code string cases.

    Also you can log the insertSQL in console, copy it from console and open the Bundle sqlite file and execute the query using execute section. See whats happening 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to save some data into sqlite database and the read it, there
I have a textbox that a user can type some text into. The area
I have some saved text in a session list that i want to save
I want to save some custom data into application configuration file and I need
I have some arbitrary pixel data that I want to save as a PNG.
I have some pages that I want to save the PRINT version of the
I want to save the arabic word into oracle database. User type a arabic
I have some jQuery global variables that I want to just put into my
I have a PHP MySQL query that inserts some data into a MySQL database
So I've developed a system that saves database insert/update commands into a text file

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.