WORKS WITH EXISTING DATABASE!
So, I answered my own question (above). Using all of Pete's steps, I
was able to get my large database loaded.
However, I didn't need to build the full database first in
Javascript. Well I did build an identical schema, but the full
database I built using other tools.
But copying over my sqlite db, and renaming it 0000000000000001.db, as
well as copying over the Database.db file, plus the other code
changes, did indeed work. I am amazed. Thank you thank you thank
you.
Now I did need to make the leap of faith that the files to edit were
PhoneGapDelegate.h and PhoneGapDelegate.m, NOT GlassApp*
Don't know if the project name changed recently, or if I downloaded an
older version or what, but hey, it worked.
Thanks much.
On Mar 3, 3:58 am, reverend <
rever...@ntw.net> wrote:
> I was pounding my head against installing a big (120K rows) SQLitedatabasein an iPhone application. It's a dictionary for a game.
> Trying to build thedatabasewith Javascript was prohibitive. I
> could do it, but it took forever, and sometimes crashed on the phone,
> even though it worked in the simulator.
>
> But from that, I was able to take thedatabasethat was build for the
> simulator, and copy it in to my Resources folder, and then modify the
> Objective C to install it in the proper location on the iPhone.
> Actually, there are 2 files that need to be installed. Thedatabase
> file itself, and the "Databases.db" file, which keeps track of the
> webkit databases and their names...
>
> So here's the process I used.
>
> * I built the SQLitedatabasefile in the iPhone simulator (it was
> named 0000000000000001.db)
>
> * The iPhone simulator files live (by default) at /Users/<your user>/
> Library/Application\ Support/iPhone\ Simulator/User/Applications/<your
> app id>/Library/WebKit/Databases/file__0/<databasename>
>
> * I copied both the "Databases.db" file (from the Databases folder),
> and the "0000000000000001.db" file (from the file_0 folder) in to the
> Resources folder of my project, which makes them included in the app
> bundle that is installed.
>
> * I then modified the GlassAppDelegate.h file to include the following
> INSIDE the @interface GlassAppDelegate section (inside the { })
>
> //Databasevariables
> NSString *databaseName;
> NSString *databasePath;
> NSString *databaseFile;
> NSString *masterName;
> NSString *masterPath;
> NSString *masterFile;
>
> * I added the following to the GlassAppDelegate.m file INSIDE the
> applicationDidFinishLaunching function
>
> //Copy over thedatabaseif it doesn't exist
> // Setup some globals
> databaseName = @"0000000000000001.db";
> masterName = @"Databases.db";
>
> // Get the path to the Library directory and append the databaseName
> NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains
> (NSLibraryDirectory, NSUserDomainMask, YES);
> NSString *libraryDir = [libraryPaths objectAtIndex:0];
> // the directory path for the Databases.db file
> masterPath = [libraryDir stringByAppendingPathComponent:@"WebKit/
> Databases/"];
> // the directory path for the 0000000000000001.db file
> databasePath = [libraryDir stringByAppendingPathComponent:@"WebKit/
> Databases/file__0/"];
> // the full path for the Databases.db file
> masterFile = [masterPath stringByAppendingPathComponent:masterName];
> // the full path for the 0000000000000001.db file
> databaseFile = [databasePath
> stringByAppendingPathComponent:databaseName];
> // Execute the "checkAndCreateDatabase" function
> [self checkAndCreateDatabase];
>
> * And finally, I added another function below
> applicationDidFinishLaunching called checkAndCreateDatabase, as
> follows:
>
> -(void) checkAndCreateDatabase{
> // Check if the SQLdatabasehas already been saved to the users
> phone, if not then copy it over
> BOOL success;
>
> // Create a FileManager object, we will use this to check the status
> // of thedatabaseand to copy it over if required
> NSFileManager *fileManager = [NSFileManager defaultManager];
>
> // Check if thedatabasehas already been created in the users
> filesystem
> success = [fileManager fileExistsAtPath:databasePath];
>
> // If thedatabasealready exists then return without doing anything
> if(success) return;
>
> // If not then proceed to copy thedatabasefrom the application to
> the users filesystem
>
> // Get the path to thedatabasein the application package
> NSString *databasePathFromApp = [[[NSBundle mainBundle] resourcePath]
> stringByAppendingPathComponent:databaseName];
> NSString *masterPathFromApp = [[[NSBundle mainBundle] resourcePath]
> stringByAppendingPathComponent:masterName];
>
> // Create thedatabasefolder structure
> [fileManager createDirectoryAtPath:databasePath
> withIntermediateDirectories:YES attributes:nil error:NULL];
>
> // Copy thedatabasefrom the package to the users filesystem
> [fileManager copyItemAtPath:databasePathFromApp toPath:databaseFile
> error:nil];
> // Copy the Databases.db from the package to the appropriate place
> [fileManager copyItemAtPath:masterPathFromApp toPath:masterFile
> error:nil];
>
> [fileManager release];
>
> }
>
> So this all works great! It is very quick, and won't overwrite thedatabaseupon subsequent launches...
>
> Hope it helps!
>
> Pete