#mobile-application-10-DerbyApp-build-iphone-Classes-PlausibleDatabase-PlausibleDatabase.h / h
@defgroup functions Plausible Database Functions Reference
@defgroup constants Plausible Database Constants Reference
@defgroup enums Enumerations @ingroup constants
@defgroup globals Global Variables @ingroup constants
@defgroup exceptions Exceptions @ingroup constants
NSError codes in the Plausible Database error domain. @ingroup enums
An unknown error has occured. If this code is received, it is a bug, and should be reported.
File not found.
An SQL query failed.
The provided SQL statement was invalid.
@mainpage Plausible Database @section intro_sec 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. Objects are automatically bound to statement parameters, and converted to and from the underlying SQL datatypes. Library classes supporting subclassing are explicitly documented. Due to Objective-C's fragile base classes, binary compatibility with subclasses is NOT guaranteed. You should avoid subclassing library classes -- use class composition instead. @section doc_sections Documentation Sections - @subpage exec_sql - @subpage error_handling @section services Integration & Development Services Plausible Database is provided free of charge under the BSD license, and may be freely integrated with any application. We can provide assistance with integrating our code in your own iPhone or Mac application, as well as development of additional features -- including support for additional databases -- under a license of your choosing (higher rates apply for non BSD-licensed work). Contact Plausible Labs for more information: http://www.plausiblelabs.com
logo exec_sql Basic SQL Programming Guide @section create_conn Creating a Connection Open a connection to a database file: <pre> PLSqliteDatabase *db = [[PLSqliteDatabase alloc] initWithPath: @"/path/to/database"]; if (![db open]) NSLog(@"Could not open database"); </pre> @section exec_update Update Statements Update statements can be executed using -[PLDatabase executeUpdate:] <pre> 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"); </pre> @section exec_query Query Statements Queries can be executed using -[PLDatabase executeQuery:]. To iterate over the returned results, an NSObject instance conforming to PLResultSet will be returned. <pre> 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]; </pre> @section prepared_stmt Prepared Statements Pre-compilation of SQL statements and advanced parameter binding are supported by PLPreparedStatement. A prepared statement can be constructed using -[PLDatabase prepareStatement:]. <pre> NSObject<PLPreparedStatement> *stmt = [db prepareStatement: @"INSERT INTO example (name, color) VALUES (?, ?)"]; // Bind the parameters [stmt bindParameters: [NSArray arrayWithObjects: @"Widget", @"Blue", nil]]; // Execute the INSERT if ([stmt executeUpdate] == NO) NSLog(@"INSERT failed"); </pre> @subsection named_params Name-based Parameter Binding Name-based parameter binding is also supported: <pre> // Prepare the statement NSObject<PLPreparedStatement> *stmt = [db prepareStatement: @"INSERT INTO test (name, color) VALUES (:name, :color)"]; // Bind the parameters using a dictionary NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithCapacity: 2]; [parameters setObject: @"Widget" forKey: @"name"]; [parameters setObject: @"Blue" forKey: @"color"]; [stmt bindParameterDictionary: parameters]; // Execute the INSERT if ([stmt executeUpdate] == NO) NSLog(@"INSERT failed"); </pre>
logo error_handling Error Handling Programming Guide Where a method may return an error, Plausible Database provides access to the underlying cause via an optional NSError argument. All returned errors will be a member of one of the below defined domains, however, new domains and error codes may be added at any time. If you do not wish to report on the error cause, many methods support a simple form that requires no NSError argument. @section Error Domains, Codes, and User Info @subsection database_errors Database Errors Any errors in the database driver use the #PLDatabaseErrorDomain error domain, and and one of the error codes defined in #PLDatabaseError. Additionally, the following keys will be available in the NSError user info dictionary: - #PLDatabaseErrorQueryStringKey - Query which caused the error (optional). - #PLDatabaseErrorVendorErrorKey - The native database error code. - #PLDatabaseErrorVendorStringKey - The native database error string.
(C) Æliens 04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.