ObjSQLite3  Diff

Differences From Artifact [05cf9280fa]:

To Artifact [e8eef4d654]:


19
20
21
22
23
24
25

26
27
28
29
30
31
32
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
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, &_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];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	sqlite3_close(_db);
	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