I have setup a database connection and made a call to the connection
in an attempt to see how database connectivity works. Here is the
code I tried. No errors are generated. The connection is created in
one class and used in another.
//connection creation. This is stored in a NSMutable dictionary.
[[BxDatabaseConnection alloc] initWithSQLiteFile:@"demo.sqlite"
locking:YES error:&errString]
BxDatabaseConnection *theDB = [controller.theDatabaseDefinitions
getDatabaseForName:@"exampleSQLiteDB"];
NSArray *result = [theDB fetchAll:@"SELECT * FROM user"];
NSLog(@"result: %@",result);
The log always reports "results (null)". I have verified that the
table exists and that it has four records.
Ideas?
Thanks,
Lee
I generated the file with the Firefox SQLiteManager plugin. I believe
it generates SQLite 3.0. I have used these generated files, including
this one, in my iPhone apps and have had no problem. I know that
there I am using SQLite 3.0.
I changed the code to start a transaction, insert a single record,
retrieve all of the records, end the transaction. No errors were
thrown. The query still returns nothing.
Where next?
This is the last item for the example app of my port of the
QuickConnect MVC framework. Once this is working I can send it to you
with an explanation for feedback regarding creating an Xcode template
for QC and Bombax together.
Thanks,
Lee
#import "MyHandler.h"
@implementation MyHandler
- (id)renderWithTransport:(BxTransport *)transport {
[transport setHeader:@"Content-Type"
value:@"text/plain"];
BxDatabaseConnection *conn = [[BxDatabaseConnection alloc]
initWithSQLiteFile:@"test.sqlite3"
locking:YES
error:nil];
[conn beginTransaction];
[conn execute:@"CREATE TABLE users (name TEXT, password TEXT)"];
[conn execute:@"INSERT INTO users (name, password) VALUES
('Stephen', 'joshua')"];
[conn executeWith:@"INSERT INTO users (name, password) VALUES (:
1, :2)", @"John", @"secret"];
NSArray *results = [conn fetchAll:@"SELECT * FROM users"];
for (NSArray *result in results) {
[transport writeFormat:@"Name: %@ Password: %@\n", [result
objectAtIndex:0], [result objectAtIndex:1]];
}
[conn commitTransaction];
[conn close];
[conn release];
return self;
}
@end
I think I have isolated the cause of the problem.
I have included the .sqlite file in the Resources group of the
project. It is being copied into the debug build directory by the
target declarations. If I open the orignal file in the project
directory using the Firefox plugin or MesaSQLite everything is fine.
If I open the file found in the debug build directory after a build
and debug is begun The Firefox plugin shows an empty database and
MesaSQLite displays the message "file is encrypted or is not a
database file".
If I copy the original sqlite file directly into the debug build
directory after a build and debug is begun everything works fine when
the query executes.
The code you sent does work. It creates the file after the build
process is complete.
Are you doing something in a special build step? Am I including the
file in the project in a way that you did not intend?
Thanks,
Lee