Index: src/SL3Connection.h ================================================================== --- src/SL3Connection.h +++ src/SL3Connection.h @@ -32,18 +32,19 @@ @interface SL3Connection: OFObject { #ifdef SL3_PUBLIC_IVARS @public #endif - sqlite3 *_db; + sqlite3 *_conn; } + (instancetype)connectionWithPath: (OFString *)path; + (instancetype)connectionWithPath: (OFString *)path flags: (int)flags; - (instancetype)initWithPath: (OFString *)path; - (instancetype)initWithPath: (OFString *)path flags: (int)flags OF_DESIGNATED_INITIALIZER; - (SL3PreparedStatement *)prepareStatement: (OFConstantString *)SQL; +- (void)executeStatement: (OFConstantString *)SQL; @end OF_ASSUME_NONNULL_END Index: src/SL3Connection.m ================================================================== --- src/SL3Connection.m +++ src/SL3Connection.m @@ -21,10 +21,11 @@ */ #import "SL3Connection.h" #import "SL3PreparedStatement.h" +#import "SL3ExecuteStatementFailedException.h" #import "SL3OpenFailedException.h" @implementation SL3Connection + (instancetype)connectionWithPath: (OFString *)path { @@ -48,11 +49,12 @@ flags: (int)flags { self = [super init]; @try { - int code = sqlite3_open_v2(path.UTF8String, &_db, flags, NULL); + int code = sqlite3_open_v2(path.UTF8String, &_conn, flags, + NULL); if (code != SQLITE_OK) @throw [SL3OpenFailedException exceptionWithPath: path flags: flags errorCode: code]; @@ -64,11 +66,11 @@ return self; } - (void)dealloc { - sqlite3_close(_db); + sqlite3_close(_conn); [super dealloc]; } - (SL3PreparedStatement *)prepareStatement: (OFConstantString *)SQL @@ -75,6 +77,16 @@ { return [[[SL3PreparedStatement alloc] sl3_initWithConnection: self SQLStatement: SQL] autorelease]; } + +- (void)executeStatement: (OFConstantString *)SQL +{ + int code = sqlite3_exec(_conn, SQL.UTF8String, NULL, NULL, NULL); + + if (code != SQLITE_OK) + @throw [SL3ExecuteStatementFailedException + exceptionWithConnection: self + errorCode: code]; +} @end Index: src/SL3PreparedStatement.m ================================================================== --- src/SL3PreparedStatement.m +++ src/SL3PreparedStatement.m @@ -40,11 +40,11 @@ SQLStatement: (OFConstantString *)SQLStatement { self = [super init]; @try { - int code = sqlite3_prepare_v2(connection->_db, + int code = sqlite3_prepare_v2(connection->_conn, SQLStatement.UTF8String, SQLStatement.UTF8StringLength, &_stmt, NULL); if (code != SQLITE_OK) @throw [SL3PrepareStatementFailedException Index: src/exceptions/SL3ExecuteStatementFailedException.h ================================================================== --- src/exceptions/SL3ExecuteStatementFailedException.h +++ src/exceptions/SL3ExecuteStatementFailedException.h @@ -31,16 +31,12 @@ SL3PreparedStatement *_statement; } @property (readonly, nonatomic) SL3PreparedStatement *statement; -+ (instancetype)exceptionWithConnection: (nullable SL3Connection *)connection - errorCode: (int)errorCode OF_UNAVAILABLE; + (instancetype)exceptionWithStatement: (SL3PreparedStatement *)statement errorCode: (int)errorCode; -- (instancetype)initWithConnection: (nullable SL3Connection *)connection - errorCode: (int)errorCode OF_UNAVAILABLE; - (instancetype)initWithStatement: (SL3PreparedStatement *)statement - errorCode: (int)errorCode OF_DESIGNATED_INITIALIZER; + errorCode: (int)errorCode; @end OF_ASSUME_NONNULL_END Index: src/exceptions/SL3ExecuteStatementFailedException.m ================================================================== --- src/exceptions/SL3ExecuteStatementFailedException.m +++ src/exceptions/SL3ExecuteStatementFailedException.m @@ -23,29 +23,17 @@ #import "SL3ExecuteStatementFailedException.h" @implementation SL3ExecuteStatementFailedException @synthesize statement = _statement; -+ (instancetype)exceptionWithConnection: (SL3Connection *)connection - errorCode: (int)errorCode -{ - OF_UNRECOGNIZED_SELECTOR -} - + (instancetype)exceptionWithStatement: (SL3PreparedStatement *)statement errorCode: (int)errorCode { return [[[self alloc] initWithStatement: statement errorCode: errorCode] autorelease]; } -- (instancetype)initWithConnection: (SL3Connection *)connection - errorCode: (int)errorCode -{ - OF_INVALID_INIT_METHOD -} - - (instancetype)initWithStatement: (SL3PreparedStatement *)statement errorCode: (int)errorCode { self = [super initWithConnection: statement->_connection errorCode: errorCode];