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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:50:42+00:00 2026-05-28T05:50:42+00:00

I have a strange problem with sqlite which is driving me crazy. I have

  • 0

I have a strange problem with sqlite which is driving me crazy.

I have implemented a sqlite database in my app and when i launch the app via xcode everything works fine. In Simulator as well as on my ipad.
But when i build an ad-hoc version and install the ad-hoc version on my ipad the app crashes, when trying to start because it gets no data from the sql database, because there is no data in the database.
At the first start the App should initialize the Database with data taken from an xml file and then access the data solely via the sqlite database.
Works great if run from xcode, but not if run from ad-hoc version.

Has anyone an idea why this is so and how i can solve this issue? If sourcecode will be needed, i’ll provide it.

The databasefile is contained in the bundle, and even if it wouldn’t, it will be created.

Thx in advance,
Maverick1st

Right now i do this in my appDidFinishLaunchingWithOptions

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
[AppState sharedInstance].s_databasePath = [documentsDir stringByAppendingPathComponent:[AppState sharedInstance].s_databaseName];



if ([self checkForSQLiteDataBaseFile])
{
    if (![self checkForSQLiteDataBaseTable]) {
        [self loadDataFromXMLIntoNSDictionary];
    }
}

-(BOOL) checkForSQLiteDataBaseFile
{
    BOOL ret = NO;
    // Check if the SQL database has already been saved to the users phone, if not then copy it over
// Create a FileManager object, we will use this to check the status
// of the database and to copy it over if required
    NSFileManager *fileManager = [NSFileManager defaultManager];

// Check if the database has already been created in the users filesystem
// If the database already exists then return without doing anything
    if([fileManager fileExistsAtPath:[AppState sharedInstance].s_databasePath]) 
        {
            Log2(@"databasePath: %@", [AppState sharedInstance].s_databasePath);
            ret = YES;
            return ret;
        }

// If not then proceed to copy the database from the application to the users filesystem

// Get the path to the database in the application package
    NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:[AppState sharedInstance].s_databaseName];

    // Copy the database from the package to the users filesystem
    [fileManager copyItemAtPath:databasePathFromApp toPath:[AppState sharedInstance].s_databasePath error:nil];
    Log2(@"databasePath: %@", [AppState sharedInstance].s_databasePath);

    ret = YES;
    return ret;
}   

And this is my documentspath: databasePath: /var/mobile/Applications/0CE5F143-04AC-4E1C-9A94-2B253F86F854/Documents/KatalogDaten

i also found out, that my database is opened by sqlite, for the following statement is true:

if(sqlite3_open([[AppState sharedInstance].s_databasePath UTF8String], &database) == SQLITE_OK)

*EDIT**
after checking the filesystem of the app on my ipad with iExplorer i noticed, that the table is indeed there and has also content in itself. But since i work on a virtual table in my app because i need full-text-search i want to create a virtual table if none exists in that database and that seems to fail somehow. I’ll provide further updates if i find out more.

**Edit***

So, i think i found out where the error is, but not what causes it.

The following sourcecode is executed normally, but only returns the desired result, when run from xcode on my ipad and not when run from an ad-hoc version on my ipad.

if(sqlite3_open([[AppState sharedInstance].s_databasePath UTF8String], &database) == SQLITE_OK)
{
    NSLog(@"Database opened successfully!");
    const char *sqlQuery = [@"select DISTINCT tbl_name from sqlite_master where tbl_name = ?;" UTF8String]; 
    Log2(@"sqlquery for selecting distinct table: %s", sqlQuery);
    sqlite3_stmt *compiledQuery;
    if(sqlite3_prepare_v2(database, sqlQuery, -1, &compiledQuery, NULL) == SQLITE_OK) 
    {
        sqlite3_bind_text(compiledQuery, 1, [k_db_virtualTableName UTF8String], -1, SQLITE_TRANSIENT);

        if(sqlite3_step(compiledQuery)) 
        {
            // look if virtual table already exists
            if ((char *)sqlite3_column_text(compiledQuery, 0) == nil) 
            {
                NSLog(@"Create virtual table!");
                sqlite3_finalize(compiledQuery);

                sqlQuery = [[NSString stringWithFormat:@"CREATE VIRTUAL TABLE %@ USING FTS3 (%@);", k_db_virtualTableName, keyString] UTF8String];
                Log2(@"sqlQuery: %s", sqlQuery);        
                if(sqlite3_prepare_v2(database, sqlQuery, -1, &compiledQuery, NULL) == SQLITE_OK) 
                {   
                    NSLog(@"query for virtual table is ok!");
                    if(sqlite3_step(compiledQuery)) 
                    {
                        NSLog(@"query for virtual table was executed properly!");
                        sqlite3_finalize(compiledQuery);
                        [self fillSQLiteDataBaseTable: k_db_virtualTableName WithDataFromDict: [[[xmlDictionary objectForKey:@"UHRENTABELLE"] objectForKey:@"UHR"] mutableCopy]];
                    }
                    else
                    {
                        sqlite3_finalize(compiledQuery);
                    }
                }
            } 
            else
            {
                NSLog(@"Virtual Table already exists!!");
                sqlite3_finalize(compiledQuery);
            }
        }
    }
    else
    {
        NSLog(@"The following statement is not correct: %@", sqlQuery);
    }
}
sqlite3_close(database);

The Method fillSQLiteDataBaseTable is executed normally as well when run through xcode or from ad-hoc version. Only difference is, that with the ad-hoc version the creation of the virtual table fails without the app telling me. The app just continues as if nothing had happened but when i look into the sql file afterwards there is no virtual table there when run from ad-hoc version. The virtual table only exists when run from xCode.

  • 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-28T05:50:42+00:00Added an answer on May 28, 2026 at 5:50 am

    I forgot to add the following line to the head of my sqlite.c file

    #define SQLITE_ENABLE_FTS3
    

    So it was basically the problem, that when i ran my version from xcode. The sqlite version in my bundle was used, which seemed to support fts3 for some reason i don’t know without the need of enabling it with that define.

    The sqlite version on my iPad though does not support fts.
    So this might be the reason my sqlite was behaving so strange.

    Anyways. Now it runs perfectly smooth.

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

Sidebar

Related Questions

I have a strange database problem in django, using sqlite: In the Model PrivateMessage:
I have a strange problem when accessing android sqlite datbase. I have a line
I have strange problem for which I can't think of a solution. I have
I have strange problem. I have class which behaves similar dropdown list. package test.view;
I have a strange problem, in my settings file everything is enabled that needs
I'm fighting with this database and i have a strange problem... If I try
I have strange problem with sharepoint and ajax functionality. We have an UpdatePanel placed
i have strange problem doing reporting: i have numerous clients with different issued invoices.
We have very strange problem, one of our applications is continually querying server by
I have a strange problem with mod_rewrite, the rules that are relevant here are:

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.