SL3Connection: Add -[executeStatement:]
FossilOrigin-Name: 02992f86b3c02a7784a12c4b9a7ffa7b70614999a07b799c567755bde3d24cea
This commit is contained in:
parent
6c2ddfe254
commit
68eee4790f
5 changed files with 18 additions and 21 deletions
|
@ -34,7 +34,7 @@ OF_ASSUME_NONNULL_BEGIN
|
|||
#ifdef SL3_PUBLIC_IVARS
|
||||
@public
|
||||
#endif
|
||||
sqlite3 *_db;
|
||||
sqlite3 *_conn;
|
||||
}
|
||||
|
||||
+ (instancetype)connectionWithPath: (OFString *)path;
|
||||
|
@ -44,6 +44,7 @@ OF_ASSUME_NONNULL_BEGIN
|
|||
- (instancetype)initWithPath: (OFString *)path
|
||||
flags: (int)flags OF_DESIGNATED_INITIALIZER;
|
||||
- (SL3PreparedStatement *)prepareStatement: (OFConstantString *)SQL;
|
||||
- (void)executeStatement: (OFConstantString *)SQL;
|
||||
@end
|
||||
|
||||
OF_ASSUME_NONNULL_END
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#import "SL3Connection.h"
|
||||
#import "SL3PreparedStatement.h"
|
||||
|
||||
#import "SL3ExecuteStatementFailedException.h"
|
||||
#import "SL3OpenFailedException.h"
|
||||
|
||||
@implementation SL3Connection
|
||||
|
@ -50,7 +51,8 @@
|
|||
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
|
||||
|
@ -66,7 +68,7 @@
|
|||
|
||||
- (void)dealloc
|
||||
{
|
||||
sqlite3_close(_db);
|
||||
sqlite3_close(_conn);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
@ -77,4 +79,14 @@
|
|||
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
|
||||
|
|
|
@ -42,7 +42,7 @@ releaseObject(void *object)
|
|||
self = [super init];
|
||||
|
||||
@try {
|
||||
int code = sqlite3_prepare_v2(connection->_db,
|
||||
int code = sqlite3_prepare_v2(connection->_conn,
|
||||
SQLStatement.UTF8String, SQLStatement.UTF8StringLength,
|
||||
&_stmt, NULL);
|
||||
|
||||
|
|
|
@ -33,14 +33,10 @@ OF_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@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
|
||||
|
|
|
@ -25,12 +25,6 @@
|
|||
@implementation SL3ExecuteStatementFailedException
|
||||
@synthesize statement = _statement;
|
||||
|
||||
+ (instancetype)exceptionWithConnection: (SL3Connection *)connection
|
||||
errorCode: (int)errorCode
|
||||
{
|
||||
OF_UNRECOGNIZED_SELECTOR
|
||||
}
|
||||
|
||||
+ (instancetype)exceptionWithStatement: (SL3PreparedStatement *)statement
|
||||
errorCode: (int)errorCode
|
||||
{
|
||||
|
@ -38,12 +32,6 @@
|
|||
errorCode: errorCode] autorelease];
|
||||
}
|
||||
|
||||
- (instancetype)initWithConnection: (SL3Connection *)connection
|
||||
errorCode: (int)errorCode
|
||||
{
|
||||
OF_INVALID_INIT_METHOD
|
||||
}
|
||||
|
||||
- (instancetype)initWithStatement: (SL3PreparedStatement *)statement
|
||||
errorCode: (int)errorCode
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue