Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
SQL connector for Cocoa applications a la Perl's DBI.
Objective-C C
branch: delegate

This branch is 2 commits ahead, 148 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
CocoaSQL.xcodeproj
English.lproj
Source
Test
.gitattributes
.gitignore
CocoaSQL_Prefix.pch
Doxyfile
Info.plist
README.md
Unit Tests-Info.plist
otest.m
version.plist

README.md

About CocoaSQL

The aim of the CocoaSQL project is to deliver a de-facto database API for Cocoa. Also, we want it to be as Cocoa compliant as possible.

Our initial plan is to provide at least SQLite and MySQL connectors, and eventually extend it to other databases.

The project is, at the time of this writing, composed of the following protocols that must be implemented on a per driver basis:

  • CSQLDatabase
  • CSQLPreparedStatement

Additionally, provides the following concrete classes:

  • CSQLDatabase
  • CSQLBindValue

Sample Code

    #import <CocoaSQL.h>

NSError *error = nil;
NSMutableDictionary *options = [NSMutableDictionary dictionary];

// Connects to a SQLite database.
CSQLDatabase *database = [CSQLDatabase databaseWithDriver:@"SQLite" andOptions:options error:&error];

// Executes a query.
NSUInteger affectedRows = [database executeSQL:@"DELETE FROM t" error:&error];

// Creates a new prepared statement
CSQLPreparedStatement *statement = [database prepareStatement:@"SELECT * FROM t WHERE i = ? LIMIT 10" error:&error];

// Create the binding values. the bind*Value in NSMutableArray is added through
// the CocoaSQL category.
NSMutableArray *values = [NSMutableArray arrayWithCapacity:1];
[values bindIntValue:1];

// or simply by creating/populating an NSArray (or a normal NSMutableArray) with CSQLBindValues
NSArray *values = [NSArray arrayWithObject:[CSQLBindValue bindValueWithInt:1]];

// Executes the prepared statement.
BOOL success = [statement executeWithValues:values error:&error];

// Fetch all rows, one by one.
NSDictionary* row = nil;
while (row = [statement fetchRowAsDictionary:&error]) {
    NSLog(@"Row: %@", row);
}
Something went wrong with that request. Please try again.