ObjSQLite3  Check-in [02992f86b3]

Overview
Comment:SL3Connection: Add -[executeStatement:]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 02992f86b3c02a7784a12c4b9a7ffa7b70614999a07b799c567755bde3d24cea
User & Date: js 2020-10-01 23:13:36
Context
2020-10-01
23:20
Add initial tests check-in: bda6d49813 user: js tags: trunk
23:13
SL3Connection: Add -[executeStatement:] check-in: 02992f86b3 user: js tags: trunk
21:59
Update .fossil-settings/ignore-glob check-in: eb4ede18a3 user: js tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/SL3Connection.h.

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

47
48
49
OF_ASSUME_NONNULL_BEGIN

@interface SL3Connection: OFObject
{
#ifdef SL3_PUBLIC_IVARS
@public
#endif
	sqlite3 *_db;
}

+ (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;

@end

OF_ASSUME_NONNULL_END







|









>



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
OF_ASSUME_NONNULL_BEGIN

@interface SL3Connection: OFObject
{
#ifdef SL3_PUBLIC_IVARS
@public
#endif
	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

Changes to src/SL3Connection.m.

19
20
21
22
23
24
25

26
27
28
29
30
31
32
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import "SL3Connection.h"
#import "SL3PreparedStatement.h"


#import "SL3OpenFailedException.h"

@implementation SL3Connection
+ (instancetype)connectionWithPath: (OFString *)path
{
	return [[[self alloc] initWithPath: path] autorelease];
}







>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#import "SL3Connection.h"
#import "SL3PreparedStatement.h"

#import "SL3ExecuteStatementFailedException.h"
#import "SL3OpenFailedException.h"

@implementation SL3Connection
+ (instancetype)connectionWithPath: (OFString *)path
{
	return [[[self alloc] initWithPath: path] autorelease];
}
46
47
48
49
50
51
52
53

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79










80

- (instancetype)initWithPath: (OFString *)path
		       flags: (int)flags
{
	self = [super init];

	@try {
		int code = sqlite3_open_v2(path.UTF8String, &_db, flags, NULL);


		if (code != SQLITE_OK)
			@throw [SL3OpenFailedException exceptionWithPath: path
								   flags: flags
							       errorCode: code];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	sqlite3_close(_db);

	[super dealloc];
}

- (SL3PreparedStatement *)prepareStatement: (OFConstantString *)SQL
{
	return [[[SL3PreparedStatement alloc]
	    sl3_initWithConnection: self
		      SQLStatement: SQL] autorelease];
}










@end







|
>















|










>
>
>
>
>
>
>
>
>
>

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

- (instancetype)initWithPath: (OFString *)path
		       flags: (int)flags
{
	self = [super init];

	@try {
		int code = sqlite3_open_v2(path.UTF8String, &_conn, flags,
		    NULL);

		if (code != SQLITE_OK)
			@throw [SL3OpenFailedException exceptionWithPath: path
								   flags: flags
							       errorCode: code];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	sqlite3_close(_conn);

	[super dealloc];
}

- (SL3PreparedStatement *)prepareStatement: (OFConstantString *)SQL
{
	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

Changes to src/SL3PreparedStatement.m.

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
@implementation SL3PreparedStatement
- (instancetype)sl3_initWithConnection: (SL3Connection *)connection
			  SQLStatement: (OFConstantString *)SQLStatement
{
	self = [super init];

	@try {
		int code = sqlite3_prepare_v2(connection->_db,
		    SQLStatement.UTF8String, SQLStatement.UTF8StringLength,
		    &_stmt, NULL);

		if (code != SQLITE_OK)
			@throw [SL3PrepareStatementFailedException
			    exceptionWithConnection: connection
				       SQLStatement: SQLStatement







|







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
@implementation SL3PreparedStatement
- (instancetype)sl3_initWithConnection: (SL3Connection *)connection
			  SQLStatement: (OFConstantString *)SQLStatement
{
	self = [super init];

	@try {
		int code = sqlite3_prepare_v2(connection->_conn,
		    SQLStatement.UTF8String, SQLStatement.UTF8StringLength,
		    &_stmt, NULL);

		if (code != SQLITE_OK)
			@throw [SL3PrepareStatementFailedException
			    exceptionWithConnection: connection
				       SQLStatement: SQLStatement

Changes to src/exceptions/SL3ExecuteStatementFailedException.h.

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
@interface SL3ExecuteStatementFailedException: SL3Exception
{
	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;
@end

OF_ASSUME_NONNULL_END







<
<


<
<

|



29
30
31
32
33
34
35


36
37


38
39
40
41
42
@interface SL3ExecuteStatementFailedException: SL3Exception
{
	SL3PreparedStatement *_statement;
}

@property (readonly, nonatomic) SL3PreparedStatement *statement;



+ (instancetype)exceptionWithStatement: (SL3PreparedStatement *)statement
			     errorCode: (int)errorCode;


- (instancetype)initWithStatement: (SL3PreparedStatement *)statement
			errorCode: (int)errorCode;
@end

OF_ASSUME_NONNULL_END

Changes to src/exceptions/SL3ExecuteStatementFailedException.m.

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 */

#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];

	@try {







<
<
<
<
<
<







<
<
<
<
<
<







21
22
23
24
25
26
27






28
29
30
31
32
33
34






35
36
37
38
39
40
41
 */

#import "SL3ExecuteStatementFailedException.h"

@implementation SL3ExecuteStatementFailedException
@synthesize statement = _statement;







+ (instancetype)exceptionWithStatement: (SL3PreparedStatement *)statement
			     errorCode: (int)errorCode
{
	return [[[self alloc] initWithStatement: statement
				      errorCode: errorCode] autorelease];
}







- (instancetype)initWithStatement: (SL3PreparedStatement *)statement
			errorCode: (int)errorCode
{
	self = [super initWithConnection: statement->_connection
			       errorCode: errorCode];

	@try {