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
|
#ifdef SL3_PUBLIC_IVARS
|
||||||
@public
|
@public
|
||||||
#endif
|
#endif
|
||||||
sqlite3 *_db;
|
sqlite3 *_conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (instancetype)connectionWithPath: (OFString *)path;
|
+ (instancetype)connectionWithPath: (OFString *)path;
|
||||||
|
@ -44,6 +44,7 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
- (instancetype)initWithPath: (OFString *)path
|
- (instancetype)initWithPath: (OFString *)path
|
||||||
flags: (int)flags OF_DESIGNATED_INITIALIZER;
|
flags: (int)flags OF_DESIGNATED_INITIALIZER;
|
||||||
- (SL3PreparedStatement *)prepareStatement: (OFConstantString *)SQL;
|
- (SL3PreparedStatement *)prepareStatement: (OFConstantString *)SQL;
|
||||||
|
- (void)executeStatement: (OFConstantString *)SQL;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
OF_ASSUME_NONNULL_END
|
OF_ASSUME_NONNULL_END
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#import "SL3Connection.h"
|
#import "SL3Connection.h"
|
||||||
#import "SL3PreparedStatement.h"
|
#import "SL3PreparedStatement.h"
|
||||||
|
|
||||||
|
#import "SL3ExecuteStatementFailedException.h"
|
||||||
#import "SL3OpenFailedException.h"
|
#import "SL3OpenFailedException.h"
|
||||||
|
|
||||||
@implementation SL3Connection
|
@implementation SL3Connection
|
||||||
|
@ -50,7 +51,8 @@
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
@try {
|
@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)
|
if (code != SQLITE_OK)
|
||||||
@throw [SL3OpenFailedException exceptionWithPath: path
|
@throw [SL3OpenFailedException exceptionWithPath: path
|
||||||
|
@ -66,7 +68,7 @@
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
sqlite3_close(_db);
|
sqlite3_close(_conn);
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
@ -77,4 +79,14 @@
|
||||||
sl3_initWithConnection: self
|
sl3_initWithConnection: self
|
||||||
SQLStatement: SQL] autorelease];
|
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
|
@end
|
||||||
|
|
|
@ -42,7 +42,7 @@ releaseObject(void *object)
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
@try {
|
@try {
|
||||||
int code = sqlite3_prepare_v2(connection->_db,
|
int code = sqlite3_prepare_v2(connection->_conn,
|
||||||
SQLStatement.UTF8String, SQLStatement.UTF8StringLength,
|
SQLStatement.UTF8String, SQLStatement.UTF8StringLength,
|
||||||
&_stmt, NULL);
|
&_stmt, NULL);
|
||||||
|
|
||||||
|
|
|
@ -33,14 +33,10 @@ OF_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@property (readonly, nonatomic) SL3PreparedStatement *statement;
|
@property (readonly, nonatomic) SL3PreparedStatement *statement;
|
||||||
|
|
||||||
+ (instancetype)exceptionWithConnection: (nullable SL3Connection *)connection
|
|
||||||
errorCode: (int)errorCode OF_UNAVAILABLE;
|
|
||||||
+ (instancetype)exceptionWithStatement: (SL3PreparedStatement *)statement
|
+ (instancetype)exceptionWithStatement: (SL3PreparedStatement *)statement
|
||||||
errorCode: (int)errorCode;
|
errorCode: (int)errorCode;
|
||||||
- (instancetype)initWithConnection: (nullable SL3Connection *)connection
|
|
||||||
errorCode: (int)errorCode OF_UNAVAILABLE;
|
|
||||||
- (instancetype)initWithStatement: (SL3PreparedStatement *)statement
|
- (instancetype)initWithStatement: (SL3PreparedStatement *)statement
|
||||||
errorCode: (int)errorCode OF_DESIGNATED_INITIALIZER;
|
errorCode: (int)errorCode;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
OF_ASSUME_NONNULL_END
|
OF_ASSUME_NONNULL_END
|
||||||
|
|
|
@ -25,12 +25,6 @@
|
||||||
@implementation SL3ExecuteStatementFailedException
|
@implementation SL3ExecuteStatementFailedException
|
||||||
@synthesize statement = _statement;
|
@synthesize statement = _statement;
|
||||||
|
|
||||||
+ (instancetype)exceptionWithConnection: (SL3Connection *)connection
|
|
||||||
errorCode: (int)errorCode
|
|
||||||
{
|
|
||||||
OF_UNRECOGNIZED_SELECTOR
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (instancetype)exceptionWithStatement: (SL3PreparedStatement *)statement
|
+ (instancetype)exceptionWithStatement: (SL3PreparedStatement *)statement
|
||||||
errorCode: (int)errorCode
|
errorCode: (int)errorCode
|
||||||
{
|
{
|
||||||
|
@ -38,12 +32,6 @@
|
||||||
errorCode: errorCode] autorelease];
|
errorCode: errorCode] autorelease];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithConnection: (SL3Connection *)connection
|
|
||||||
errorCode: (int)errorCode
|
|
||||||
{
|
|
||||||
OF_INVALID_INIT_METHOD
|
|
||||||
}
|
|
||||||
|
|
||||||
- (instancetype)initWithStatement: (SL3PreparedStatement *)statement
|
- (instancetype)initWithStatement: (SL3PreparedStatement *)statement
|
||||||
errorCode: (int)errorCode
|
errorCode: (int)errorCode
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue