ObjSQLite3  Check-in [91e2a50711]

Overview
Comment:Use IRIs instead of paths
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 91e2a5071199dc8d87735ad50ee74a6ce030c22f1bb0d70668bef172384dcde3
User & Date: js 2024-08-11 11:48:19
Context
2024-08-11
11:49
ObjSQLite3.h: Import all exceptions check-in: d1beadb92d user: js tags: trunk
11:48
Use IRIs instead of paths check-in: 91e2a50711 user: js tags: trunk
11:40
Add documentation check-in: c78968b79b user: js tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/SL3Connection.h.

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







|

|



|


|

|




|
<



|

|



|



|

|




|
|







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
#ifdef SL3_PUBLIC_IVARS
@public
#endif
	sqlite3 *_conn;
}

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

/**
 * @brief Creates a new connection to the database at the specified IRI.
 *
 * @param IRI The IRI 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)connectionWithIRI: (OFIRI *)IRI flags: (int)flags;


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

/**
 * @brief Initializes an already allocated connection to connect to the
 *	  database at the specified IRI.
 *
 * @param IRI The IRI 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)initWithIRI: (OFIRI *)IRI
		      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

Changes to src/SL3Connection.m.

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
#import "SL3PreparedStatement.h"
#import "SL3PreparedStatement+Private.h"

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

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

+ (instancetype)connectionWithPath: (OFString *)path
			     flags: (int)flags
{
	return [[[self alloc] initWithPath: path
				     flags: flags] autorelease];
}

- (instancetype)initWithPath: (OFString *)path
{
	return [self initWithPath: path
			    flags: SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE];
}

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







|

|


|
<

|
<


|

|
|


|
<




|
>



|
|
|







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
#import "SL3PreparedStatement.h"
#import "SL3PreparedStatement+Private.h"

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

@implementation SL3Connection
+ (instancetype)connectionWithIRI: (OFIRI *)IRI
{
	return [[[self alloc] initWithIRI: IRI] autorelease];
}

+ (instancetype)connectionWithIRI: (OFIRI *)IRI flags: (int)flags

{
	return [[[self alloc] initWithIRI: IRI flags: flags] autorelease];

}

- (instancetype)initWithIRI: (OFIRI *)IRI
{
	return [self initWithIRI: IRI
			   flags: SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE];
}

- (instancetype)initWithIRI: (OFIRI *)IRI flags: (int)flags

{
	self = [super init];

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

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

	return self;
}

Changes to src/exceptions/SL3OpenFailedException.h.

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
 * @class SL3OpenFailedException SL3OpenFailedException.h
 *	  ObjSQLite3/ObjSQLite3.h
 *
 * @brief An exception indicating that a database could not be opened.
 */
@interface SL3OpenFailedException: SL3Exception
{
	OFString *_path;
	int _flags;
}

/**
 * @brief The path of the database that could not be opened.
 */
@property (readonly, nonatomic) OFString *path;

/**
 * @brief The flags with which the database could not be opened.
 */
@property (readonly, nonatomic) int flags;

+ (instancetype)exceptionWithConnection: (nullable SL3Connection *)connection
			      errorCode: (int)errorCode OF_UNAVAILABLE;

/**
 * @brief Creates a new open failed exception.
 *
 * @param path The path of the database that could not be opened
 * @param flags The flags with which the database could not be opened
 * @param errorCode The SQLite3 error code
 * @return A new, autoreleased open failed exception
 */
+ (instancetype)exceptionWithPath: (OFString *)path
			    flags: (int)flags
			errorCode: (int)errorCode;

- (instancetype)initWithConnection: (nullable SL3Connection *)connection
			 errorCode: (int)errorCode OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated open failed exception.
 *
 * @param path The path of the database that could not be opened
 * @param flags The flags with which the database could not be opened
 * @param errorCode The SQLite3 error code
 * @return An initialized open failed exception
 */
- (instancetype)initWithPath: (OFString *)path
		       flags: (int)flags
		   errorCode: (int)errorCode OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END







|




|

|












|




|
|
|







|




|
|
|



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
 * @class SL3OpenFailedException SL3OpenFailedException.h
 *	  ObjSQLite3/ObjSQLite3.h
 *
 * @brief An exception indicating that a database could not be opened.
 */
@interface SL3OpenFailedException: SL3Exception
{
	OFIRI *_IRI;
	int _flags;
}

/**
 * @brief The IRI of the database that could not be opened.
 */
@property (readonly, nonatomic) OFIRI *IRI;

/**
 * @brief The flags with which the database could not be opened.
 */
@property (readonly, nonatomic) int flags;

+ (instancetype)exceptionWithConnection: (nullable SL3Connection *)connection
			      errorCode: (int)errorCode OF_UNAVAILABLE;

/**
 * @brief Creates a new open failed exception.
 *
 * @param IRI The IRI of the database that could not be opened
 * @param flags The flags with which the database could not be opened
 * @param errorCode The SQLite3 error code
 * @return A new, autoreleased open failed exception
 */
+ (instancetype)exceptionWithIRI: (OFIRI *)IFI
			   flags: (int)flags
		       errorCode: (int)errorCode;

- (instancetype)initWithConnection: (nullable SL3Connection *)connection
			 errorCode: (int)errorCode OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated open failed exception.
 *
 * @param IRI The IRI of the database that could not be opened
 * @param flags The flags with which the database could not be opened
 * @param errorCode The SQLite3 error code
 * @return An initialized open failed exception
 */
- (instancetype)initWithIRI: (OFIRI *)IRI
		      flags: (int)flags
		  errorCode: (int)errorCode OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Changes to src/exceptions/SL3OpenFailedException.m.

15
16
17
18
19
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
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "SL3OpenFailedException.h"

@implementation SL3OpenFailedException
@synthesize path = _path, flags = _flags;

+ (instancetype)exceptionWithConnection: (SL3Connection *)connection
			      errorCode: (int)errorCode
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithPath: (OFString *)path
			    flags: (int)flags
			errorCode: (int)errorCode
{
	return [[[self alloc] initWithPath: path
				     flags: flags
				 errorCode: errorCode] autorelease];
}

- (instancetype)initWithConnection: (SL3Connection *)connection
			 errorCode: (int)errorCode
{
	OF_INVALID_INIT_METHOD
}

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

	@try {
		_path = [path copy];
		_flags = flags;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_path release];

	[super dealloc];
}
@end







|







|
|
|

|
|
|








|
|
|





|











|




15
16
17
18
19
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
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "SL3OpenFailedException.h"

@implementation SL3OpenFailedException
@synthesize IRI = _IRI, flags = _flags;

+ (instancetype)exceptionWithConnection: (SL3Connection *)connection
			      errorCode: (int)errorCode
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithIRI: (OFIRI *)IRI
			   flags: (int)flags
		       errorCode: (int)errorCode
{
	return [[[self alloc] initWithIRI: IRI
				    flags: flags
				errorCode: errorCode] autorelease];
}

- (instancetype)initWithConnection: (SL3Connection *)connection
			 errorCode: (int)errorCode
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithIRI: (OFIRI *)IRI
		      flags: (int)flags
		  errorCode: (int)errorCode
{
	self = [super initWithConnection: nil
			       errorCode: errorCode];

	@try {
		_IRI = [IRI copy];
		_flags = flags;
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)dealloc
{
	[_IRI release];

	[super dealloc];
}
@end

Changes to tests/Tests.m.

24
25
26
27
28
29
30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
@end

OF_APPLICATION_DELEGATE(Tests)

@implementation Tests
- (void)applicationDidFinishLaunching: (OFNotification *)notification
{

	OFFileManager *fileManager = [OFFileManager defaultManager];
	SL3Connection *conn;
	SL3PreparedStatement *stmt;

	if ([fileManager fileExistsAtPath: @"tests.db"])
	    [fileManager removeItemAtPath: @"tests.db"];

	conn = [SL3Connection connectionWithPath: @"tests.db"];

	[conn executeStatement: @"CREATE TABLE test (a INT, b TEXT, c BLOB)"];

	stmt = [conn prepareStatement:
	    @"INSERT INTO test (a, b, c) VALUES ($a, $b, $c)"];
	[stmt bindWithArray: [OFArray arrayWithObjects:
	    [OFNumber numberWithInt: 5],







>




|
|

|







24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
@end

OF_APPLICATION_DELEGATE(Tests)

@implementation Tests
- (void)applicationDidFinishLaunching: (OFNotification *)notification
{
	OFIRI *IRI = [OFIRI fileIRIWithPath: @"tests.db"];
	OFFileManager *fileManager = [OFFileManager defaultManager];
	SL3Connection *conn;
	SL3PreparedStatement *stmt;

	if ([fileManager fileExistsAtIRI: IRI])
		[fileManager removeItemAtIRI: IRI];

	conn = [SL3Connection connectionWithIRI: IRI];

	[conn executeStatement: @"CREATE TABLE test (a INT, b TEXT, c BLOB)"];

	stmt = [conn prepareStatement:
	    @"INSERT INTO test (a, b, c) VALUES ($a, $b, $c)"];
	[stmt bindWithArray: [OFArray arrayWithObjects:
	    [OFNumber numberWithInt: 5],