Permalink
Browse files

initial release.

  • Loading branch information...
1 parent 5edab2e commit de7718c0090ec529e323c837a19fee751bac403e Igor Sutton committed with Igor Sutton Mar 26, 2010
Showing with 2,735 additions and 0 deletions.
  1. +162 −0 CSQLDatabase.h
  2. +21 −0 CSQLPreparedStatement.h
  3. +63 −0 CSSQLiteDatabase.h
  4. +295 −0 CSSQLiteDatabase.m
  5. +450 −0 CocoaSQL.xcodeproj/project.pbxproj
  6. +7 −0 CocoaSQL_Prefix.pch
  7. +1,600 −0 Doxyfile
  8. +2 −0 English.lproj/InfoPlist.strings
  9. +28 −0 Info.plist
  10. +9 −0 csql.h
  11. +82 −0 csql.m
  12. +16 −0 version.plist
View
@@ -0,0 +1,162 @@
+//
+// CSQLDatabase.h
+// CocoaSQL
+//
+// Created by Igor Sutton on 3/25/10.
+// Copyright 2010 CocoaSQL.org. All rights reserved.
+//
+
+@protocol CSQLDatabase
+
+#pragma mark -
+#pragma mark Class methods
+
+#pragma mark -
+#pragma mark Instance methods
+
+/**
+
+ Executes a SQL statement with bind values. If any error happened during the
+ statement's execution, this method populates <code>error</code> and returns
+ <code>NO</code>.
+
+ @param sql The SQL statement to be executed.
+ @param values An <code>NSArray</code> instance with values.
+ @param error An <code>NSError</code> instance.
+
+ @return BOOL <code>YES</code> if the statement was successfully executed,
+ <code>NO</code> otherwise.
+
+ */
+- (BOOL)executeSQL:(NSString *)sql
+ withValues:(NSArray *)values
+ error:(NSError **)error;
+
+/**
+
+ Executes a SQL statement. If any error happened during the statement's
+ execution, this method populates <code>error</code> and returns
+ <code>NO</code>.
+
+ @param sql The SQL statement to be executed.
+ @param error An <code>NSError</code> instance.
+
+ @returns BOOL <code>YES</code> if the statement was successfully executed,
+ <code>NO</code> otherwise.
+
+ */
+- (BOOL)executeSQL:(NSString *)sql
+ error:(NSError **)error;
+
+/**
+
+ Returns a NSDictionary instance containing the first row of the given SQL
+ statement. If any error occurred during the statement's execution,
+ <code>nil</code> is returned and <code>error</code> is populated.
+
+ @param sql The SQL statement to be executed.
+ @param values An <code>NSArray</code> instance with values.
+ @param error An <code>NSError</code> instance.
+
+ @return <code>NSDictionary</code> The first row as a <code>NSDictionary</code>,
+ with the columns as keys.
+
+ */
+- (NSDictionary *)fetchRowAsDictionaryWithSQL:(NSString *)sql
+ withValues:(NSArray *)values
+ error:(NSError **)error;
+
+/**
+
+ Returns an <code>NSDictionary</code> instance containing the first row of the
+ given SQL statement. If any error occurred during the statement's execution,
+ <code>nil</code> is returned and <code>error</code> is populated.
+
+ @param sql The SQL statement to be executed.
+ @param error An <code>NSError</code> instance.
+
+ @return <code>NSDictionary</code> The first row as a <code>NSDictionary</code>,
+ with the columns as keys.
+
+ */
+- (NSDictionary *)fetchRowAsDictionaryWithSQL:(NSString *)sql
+ error:(NSError **)error;
+
+/**
+
+ Returns an <code>NSArray</code> instance containing the first row of the given
+ SQL statement. If any error occurred during the statement's execution,
+ <code>nil</code> is returned and <code>error</code> is populated.
+
+ @param sql The SQL statement to be executed.
+ @param values An <code>NSArray</code> instance with values.
+ @param error An <code>NSError</code> instance.
+
+ @return <code>NSArray</code> The first row as a <code>NSArray</code>.
+
+ */
+- (NSArray *)fetchRowAsArrayWithSQL:(NSString *)sql
+ withValues:(NSArray *)values
+ error:(NSError **)error;
+
+/**
+
+ Returns an <code>NSArray</code> instance containing the first row of the given
+ SQL statement. If any error occurred during the statement's execution,
+ <code>nil</code> is returned and <code>error</code> is populated.
+
+ @param sql The SQL statement to be executed.
+ @param error An <code>NSError</code> instance.
+
+ @return <code>NSArray</code> The first row as a <code>NSArray</code>.
+
+ */
+- (NSArray *)fetchRowAsArrayWithSQL:(NSString *)sql
+ error:(NSError **)error;
+
+/**
+
+ Returns an <code>NSArray</code> instance containing all the rows returned by
+ the SQL statement as <code>NSDictionary</code>. If any error occurred during
+ the statement's execution, <code>nil</code> is returned and <code>error</code>
+ is populated.
+
+ @param sql The SQL statement to be executed.
+ @param values An <code>NSArray</code> instance with values.
+ @param error An <code>NSError</code> instance.
+
+ @return <code>NSArray</code> <code>NSArray</code> containing all the rows
+ returned by the statement as <code>NSDictionary</code>, with the column names
+ as keys.
+
+ */
+- (NSArray *)fetchRowsAsDictionariesWithSQL:(NSString *)sql
+ withValues:(NSArray *)values
+ error:(NSError **)error;
+
+/**
+
+ Returns an <code>NSArray</code> instance containing all the rows returned by
+ the SQL statement as <code>NSDictionary</code>. If any error occurred during
+ the statement's execution, <code>nil</code> is returned and <code>error</code>
+ is populated.
+
+ @param sql The SQL statement to be executed.
+ @param error An <code>NSError</code> instance.
+
+ @return <code>NSArray</code> <code>NSArray</code> containing all the rows
+ returned by the statement as <code>NSDictionary</code>, with the column names
+ as keys.
+
+ */
+- (NSArray *)fetchRowsAsDictionariesWithSQL:(NSString *)sql
+ error:(NSError **)error;
+
+- (NSArray *)fetchRowsAsArraysWithSQL:(NSString *)sql
+ withValues:(NSArray *)values
+ error:(NSError **)error;
+
+- (NSArray *)fetchRowsAsArraysWithSQL:(NSString *)sql
+ error:(NSError **)error;
+
+@end
View
@@ -0,0 +1,21 @@
+/*
+ * CSQLPreparedStatement.h
+ * CocoaSQL
+ *
+ * Created by Igor Sutton on 3/26/10.
+ * Copyright 2010 CocoaSQL.org. All rights reserved.
+ *
+ */
+
+@protocol CSQLPreparedStatement
+
+- (BOOL)executeWithValues:(NSArray *)values error:(NSError **)error;
+
+- (BOOL)execute:(NSError **)error;
+
+- (NSDictionary *)fetchRowAsDictionary;
+
+- (NSArray *)fetchRowAsArray;
+
+@end
+
View
@@ -0,0 +1,63 @@
+//
+// CSSQLite.h
+// CocoaSQL
+//
+// Created by Igor Sutton on 3/25/10.
+// Copyright 2010 CocoaSQL.org. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+#import "CSQLDatabase.h"
+
+#include <sqlite3.h>
+
+typedef int (*CSQLiteCallback)(void *, int, char**, char**);
+
+@interface CSSQLiteDatabase : NSObject <CSQLDatabase> {
+ @private
+ NSString *path;
+ sqlite3 *sqliteDatabase;
+}
+
+#pragma mark -
+#pragma mark Initialization related messages
+
++ (id)databaseWithPath:(NSString *)aPath
+ error:(NSError **)error;
+
+- (id)initWithPath:(NSString *)aPath
+ error:(NSError **)error;
+
+#pragma mark -
+#pragma mark CSSQLiteDatabase related messages
+
+- (BOOL)executeSQL:(NSString *)sql
+ withValues:(NSArray *)values
+ callback:(CSQLiteCallback)callbackFunction
+ context:(void *)context
+ error:(NSError **)error;
+
+@end
+
+#pragma mark -
+#pragma mark SQLite callbacks
+
+int rowAsArrayCallback(void *callbackContext,
+ int columnCount,
+ char **columnValues,
+ char **columnNames);
+
+int rowAsDictionaryCallback(void *callbackContext,
+ int columnCount,
+ char **columnValues,
+ char **columnNames);
+
+int rowsAsDictionariesCallback(void *callbackContext,
+ int columnCount,
+ char **columnValues,
+ char **columnNames);
+
+int rowsAsArraysCallback(void *callbackContext,
+ int columnCount,
+ char **columnValues,
+ char **columnNames);
Oops, something went wrong.

0 comments on commit de7718c

Please sign in to comment.