google-code-export / sqlite-manager

Automatically exported from code.google.com/p/sqlite-manager
1 stars 0 forks source link

read/write a copied db table with iphone simulator #346

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. verify a table can be read from iphone simulator
2. copy table
3. attempt to read copied table from iphone simulator

What is the actual output?
Data is not found

What is the expected output?
Data to be found

What version of the product are you using? On what target Application (e.g.
Firefox 3.5.1, etc.)? On what operating system?
Extension Version = most recent sqlite-manager
Application = xcode 3.1.3 iphone simulator 3.0
OS = mac osx 10.5.8

Please provide any additional information below. In some cases
errors/warnings may be logged in the Error Console (in Firefox) which is
available under the Tools menu or using Ctrl+Shift+J. If you find any
related to this extension, please report that too.

games table works
games2 table is the copied table that does not work

@interface GameAppDelegate (Private)
    - (void)createEditableCopyOfDatabaseIfNeeded;
    - (void)initializeGames;
@end

@implementation GameAppDelegate

@synthesize window,navigationController,games,gamers;

- (id)init {
    if (self = [super init]) {
        // 
    }
    return self;
}

- (void)applicationDidFinishLaunching:(UIApplication *)application {

    [self createEditableCopyOfDatabaseIfNeeded];
    [self initializeGames];
    //test - add parameters to pass so there isn't multiple methods
    [self initializeGamers];

    // Configure and show the window
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];
}

// Creates a writable copy of the bundled default database in the
application Documents directory.
- (void)createEditableCopyOfDatabaseIfNeeded {
    // First, test for existence.
    BOOL success;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSError *error;
    NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,
YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory
stringByAppendingPathComponent:@"Sports.sqlite"];
    success = [fileManager fileExistsAtPath:writableDBPath];
    if (success) return;
    // The writable database does not exist, so copy the default to the
appropriate location.
    NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:@"Sports.sqlite"];
    success = [fileManager copyItemAtPath:defaultDBPath
toPath:writableDBPath error:&error];
    if (!success) {
        NSAssert1(0, @"Failed to create writable database file with message
'%@'.", [error localizedDescription]);
    }
}

// Open the database connection and retrieve minimal information for all
objects.
- (void)initializeGames {
    NSMutableArray *gameArray = [[NSMutableArray alloc] init];
    self.games = gameArray;
    [gameArray release];

    // The database is stored in the application bundle. 
    NSArray *paths =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,
YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory
stringByAppendingPathComponent:@"Sports.sqlite"];
    // Open the database. The database was prepared outside the application.
    if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
        // Get the primary key for all games.
        const char *sql = "SELECT games_id FROM games2";
        sqlite3_stmt *statement;
        // Preparing a statement compiles the SQL query into a byte-code
program in the SQLite library.
        // The third parameter is either the length of the SQL string or -1
to read up to the first null terminator.        

        if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
            // We "step" through the results - once for each row.

            while (sqlite3_step(statement) == SQLITE_ROW) {
                // The second parameter indicates the column index into the
result set.
                int primaryKey = sqlite3_column_int(statement, 0);

                // We avoid the alloc-init-autorelease pattern here because
we are in a tight loop and
                // autorelease is slightly more expensive than release.
This design choice has nothing to do with
                // actual memory management - at the end of this block of
code, all the game objects allocated
                // here will be in memory regardless of whether we use
autorelease or release, because they are
                // retained by the games array.

                GAMES *gm = [[GAMES alloc] initWithPrimaryKey:primaryKey
database:database];
                [games addObject:gm];
                [gm release];               
            }
        }
        // "Finalize" the statement - releases the resources associated
with the statement.
        sqlite3_finalize(statement);
    } else {
        // Even though the open failed, call close to properly clean up
resources.
        sqlite3_close(database);
        NSAssert1(0, @"Failed to open database with message '%s'.",
sqlite3_errmsg(database));
        // Additional error handling, as appropriate...
    }
}

Original issue reported on code.google.com by roybrown77@gmail.com on 26 Oct 2009 at 11:00

GoogleCodeExporter commented 9 years ago
what exactly is xcode 3.1.3 iphone simulator 3.0?
Can it be installed on Ubuntu (the only OS I have)?

Original comment by tarakant...@gmail.com on 30 Oct 2009 at 11:34

GoogleCodeExporter commented 9 years ago
It is development system for Apple smart phone called 'iPhone'. IPhone operating
system is http://en.wikipedia.org/wiki/IPhone_OS. Simulator 3.0 simulates 
iPhone and
 works only on Mac OS X operating system. I am not aware of any ports to any other
platforms.

Original comment by a1rex2...@gmail.com on 15 Feb 2010 at 1:39

GoogleCodeExporter commented 9 years ago
need a sample db which should not be encrypted.

Original comment by mrinal.k...@gmail.com on 28 Feb 2010 at 11:45

GoogleCodeExporter commented 9 years ago
closing as cantreproduce for want of a sample.

Original comment by mrinal.k...@gmail.com on 31 Dec 2011 at 9:07