ObjSQLite3  Check-in [1ecc15c9b8]

Overview
Comment:Add -[transactionWithBlock:]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1ecc15c9b801a9531314936f644a43a863fc7811768c7c257b409adad349d6e6
User & Date: js 2020-10-04 01:28:44
Context
2020-10-09
22:10
Make row{Array,Dictionary} a property check-in: 643e6c6da7 user: js tags: trunk
2020-10-04
01:28
Add -[transactionWithBlock:] check-in: 1ecc15c9b8 user: js tags: trunk
2020-10-03
19:38
configure: Fix incomplete FRAMEWORK_LIBS check-in: 5ad548669b user: js tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/SL3Connection.h.

40
41
42
43
44
45
46



47
48
49
+ (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







>
>
>



40
41
42
43
44
45
46
47
48
49
50
51
52
+ (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;
#ifdef OF_HAVE_BLOCKS
- (void)transactionWithBlock: (bool (^)(void))block;
#endif
@end

OF_ASSUME_NONNULL_END

Changes to src/SL3Connection.m.

86
87
88
89
90
91
92





















93
	int code = sqlite3_exec(_conn, SQL.UTF8String, NULL, NULL, NULL);

	if (code != SQLITE_OK)
		@throw [SL3ExecuteStatementFailedException
		    exceptionWithConnection: self
				  errorCode: code];
}





















@end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
	int code = sqlite3_exec(_conn, SQL.UTF8String, NULL, NULL, NULL);

	if (code != SQLITE_OK)
		@throw [SL3ExecuteStatementFailedException
		    exceptionWithConnection: self
				  errorCode: code];
}

#ifdef OF_HAVE_BLOCKS
- (void)transactionWithBlock: (bool (^)(void))block
{
	bool commit;

	[self executeStatement: @"BEGIN TRANSACTION"];

	@try {
		commit = block();
	} @catch (id e) {
		[self executeStatement: @"ROLLBACK TRANSACTION"];
		@throw e;
	}

	if (commit)
		[self executeStatement: @"COMMIT TRANSACTION"];
	else
		[self executeStatement: @"ROLLBACK TRANSACTION"];
}
#endif
@end