Plausible Database

Introduction

Plausible Database provides a generic Objective-C interface for interacting with SQL databases. SQLite is the initial and primary target, but the API has been designed to support more traditional databases.

While the code is stable and unit tested, the API has not yet been finalized, and may see incompatible changes prior to the 1.0 release.

Plausible Database provides an Objective-C veneer over the underlying SQL database. Classes are automatically bound to statement parameters, and converted to and from the underlying SQL datatypes.

Creating a Connection

Open a connection to a database file:

 PLSqliteDatabase *db = [[PLSqliteDatabase alloc] initWithPath:  @"/path/to/database"];
 if (![db open])
     NSLog(@"Could not open database");
 

Update Statements

Update statements can be executed using -[PLDatabase executeUpdate:]

 if (![db executeUpdate: @"CREATE TABLE example (id INTEGER)"])
     NSLog(@"Table creation failed");

 if (![db executeUpdate: @"INSERT INTO example (id) VALUES (?)", [NSNumber numberWithInteger: 42]])
     NSLog(@"Data insert failed");
 

Query Statements

Queries can be executed using -[PLDatabase executeQuery:]. To iterate over the returned results, an NSObject instance conforming to PLResultSet will be returned.

 NSObject<PLResultSet> *results = [db executeQuery: @"SELECT id FROM example WHERE id = ?", [NSNumber numberWithInteger: 42]];
 while ([results next]) {
     NSLog(@"Value of column id is %d", [results intForColumn: @"id"]);
 }

 // Failure to close the result set will not leak memory, but may
 // retain database resources until the instance is deallocated.
 [results close];
 

Generated on Mon May 19 20:50:13 2008 for PlausibleDatabase by  doxygen 1.5.5