ObjSQLite3  Diff

Differences From Artifact [2f11a63715]:

To Artifact [e3ea62406e]:


1
2
3
4
5
6
7
8
9
/*
 * Copyright (c) 2020 Jonathan Schleifer <js@nil.im>
 *
 * https://fl.nil.im/objsqlite3
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *

|







1
2
3
4
5
6
7
8
9
/*
 * Copyright (c) 2020, 2024 Jonathan Schleifer <js@nil.im>
 *
 * https://fl.nil.im/objsqlite3
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
20
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

#include <sqlite3.h>

#import "SL3PreparedStatement.h"

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;

#ifdef OF_HAVE_BLOCKS









- (void)transactionWithBlock: (bool (^)(void))block;
#endif
@end

OF_ASSUME_NONNULL_END







>
>
>
>
>








>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>


>
>
>
>
>
>
>
>
>

>
>
>
>
>
>
>
>
>
>


>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
|
>

>
>
>
>
>
>
>
>
>





20
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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114

#include <sqlite3.h>

#import "SL3PreparedStatement.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class SL3Connection SL3Connection.h ObjSQLite3/ObjSQLite3.h
 *
 * @brief A connection to a database.
 */
@interface SL3Connection: OFObject
{
#ifdef SL3_PUBLIC_IVARS
@public
#endif
	sqlite3 *_conn;
}

/**
 * @brief Creates a new connection to the database at the specified path.
 *
 * @param path The path to the database
 * @return A new database connection
 * @throw SL3OpenFailedException The database could not be opened
 */
+ (instancetype)connectionWithPath: (OFString *)path;

/**
 * @brief Creates a new connection to the database at the specified path.
 *
 * @param path The path to the database
 * @param flags The flags to open the database with
 * @return A new database connection
 * @throw SL3OpenFailedException The database could not be opened
 */
+ (instancetype)connectionWithPath: (OFString *)path
			     flags: (int)flags;

/**
 * @brief Initializes an already allocated connection to connect to the
 *	  database at the specified path.
 *
 * @param path The path to the database
 * @return An initialized connection to the specified database
 * @throw SL3OpenFailedException The database could not be opened
 */
- (instancetype)initWithPath: (OFString *)path;

/**
 * @brief Initializes an already allocated connection to connect to the
 *	  database at the specified path.
 *
 * @param path The path to the database
 * @param flags The flags to open the database with
 * @return An initialized connection to the specified database
 * @throw SL3OpenFailedException The database could not be opened
 */
- (instancetype)initWithPath: (OFString *)path
		       flags: (int)flags OF_DESIGNATED_INITIALIZER;

/**
 * @brief Prepares the specified SQL statement for the connection and returns
 *	  it.
 *
 * @param SQLStatement An SQL statement to prepare
 * @return A prepared statement
 * @throw SL3PrepareStatementFailedException The statement could not be prepared
 */
- (SL3PreparedStatement *)prepareStatement: (OFConstantString *)SQLStatement;

/**
 * @brief Executes the specified statement without results.
 *
 * @param SQLStatement The SQL statement to execute
 * @throw SL3ExecuteStatementFailedException The statement could not be executed
 */
- (void)executeStatement: (OFConstantString *)SQLStatement;

#ifdef OF_HAVE_BLOCKS
/**
 * @brief Executes the specified block in an transaction.
 *
 * Before the block is executed, a transaction is started. If the block returns
 * true, the transaction is committed. If the block returns true or throws an
 * exception, the transaction is rolled back.
 *
 * @param block The block to execute in a transaction
 */
- (void)transactionWithBlock: (bool (^)(void))block;
#endif
@end

OF_ASSUME_NONNULL_END