Add documentation

FossilOrigin-Name: c78968b79b683101d6f1cc6d81e8ebfed96993428f6def8bc60a8ffb6a31fb36
This commit is contained in:
Jonathan Schleifer 2024-08-11 11:40:10 +00:00
parent 4fde495a88
commit 5c91e6f832
13 changed files with 394 additions and 35 deletions

19
Doxyfile Normal file
View file

@ -0,0 +1,19 @@
PROJECT_NAME = "ObjSQLite3"
OUTPUT_DIRECTORY = docs/
INPUT = src src/exceptions
FILE_PATTERNS = *.h *.m
HTML_OUTPUT = .
HAVE_DOT = NO
GENERATE_LATEX = NO
HIDE_UNDOC_CLASSES = YES
HIDE_UNDOC_MEMBERS = YES
TYPEDEF_HIDES_STRUCT = YES
PREDEFINED = _Nullable= \
OF_DESIGNATED_INITIALIZER= \
OF_HAVE_BLOCKS \
OF_GENERIC(...)= \
OF_NULLABLE_PROPERTY(...)=
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
IGNORE_PREFIX = SL3
EXTRACT_STATIC = yes

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2020, 2024 Jonathan Schleifer <js@nil.im>
*
* https://fl.nil.im/objsqlite3
*
@ -24,6 +24,11 @@
OF_ASSUME_NONNULL_BEGIN
/**
* @class SL3Connection SL3Connection.h ObjSQLite3/ObjSQLite3.h
*
* @brief A connection to a database.
*/
@interface SL3Connection: OFObject
{
#ifdef SL3_PUBLIC_IVARS
@ -32,15 +37,76 @@ OF_ASSUME_NONNULL_BEGIN
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;
- (SL3PreparedStatement *)prepareStatement: (OFConstantString *)SQL;
- (void)executeStatement: (OFConstantString *)SQL;
/**
* @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

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2020, 2024 Jonathan Schleifer <js@nil.im>
*
* https://fl.nil.im/objsqlite3
*
@ -70,16 +70,17 @@
[super dealloc];
}
- (SL3PreparedStatement *)prepareStatement: (OFConstantString *)SQL
- (SL3PreparedStatement *)prepareStatement: (OFConstantString *)SQLStatement
{
return [[[SL3PreparedStatement alloc]
sl3_initWithConnection: self
SQLStatement: SQL] autorelease];
SQLStatement: SQLStatement] autorelease];
}
- (void)executeStatement: (OFConstantString *)SQL
- (void)executeStatement: (OFConstantString *)SQLStatement
{
int code = sqlite3_exec(_conn, SQL.UTF8String, NULL, NULL, NULL);
int code =
sqlite3_exec(_conn, SQLStatement.UTF8String, NULL, NULL, NULL);
if (code != SQLITE_OK)
@throw [SL3ExecuteStatementFailedException

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2020, 2024 Jonathan Schleifer <js@nil.im>
*
* https://fl.nil.im/objsqlite3
*
@ -24,6 +24,11 @@ OF_ASSUME_NONNULL_BEGIN
@class SL3Connection;
/**
* @class SL3PreparedStatement SL3PreparedStatement.h ObjSQLite3/ObjSQLite3.h
*
* @brief A prepared statement.
*/
@interface SL3PreparedStatement: OFObject
{
#ifdef SL3_PUBLIC_IVARS
@ -33,18 +38,73 @@ OF_ASSUME_NONNULL_BEGIN
sqlite3_stmt *_stmt;
}
@property (readonly, nonatomic) OFArray *rowArray;
@property (readonly, nonatomic)
OFDictionary OF_GENERIC(OFString *, id) *rowDictionary;
/**
* @brief The current row as an array.
*/
@property (readonly, nonatomic) OFArray *currentRowArray;
/**
* @brief The current row as a dictionary.
*/
@property (readonly, nonatomic)
OFDictionary OF_GENERIC(OFString *, id) *currentRowDictionary;
/**
* @brief Binds the objects from the specified array.
*
* @param array An array of objects to bind
* @throw OFOutOfRangeException The array has more objects than columns
*/
- (void)bindWithArray: (OFArray *)array;
/**
* @brief Binds the objects from the specified dictionary that maps each column
* name to a value.
*
* @param dictionary A map of column names to values
* @throw OFUndefinedKeyException A column name which does not exist was
* specified
*/
- (void)bindWithDictionary:
(OFDictionary OF_GENERIC(OFString *, id) *)dictionary;
/**
* @brief Clears all bindings.
*
* @throw SL3ClearBindingsFailedException The bindings could not be cleared
*/
- (void)clearBindings;
/**
* @brief Steps the prepared statement, returning the next row, if any.
*
* @return Whether there was another row
* @throw SL3ExecuteStatementFailedException Executing the prepared statement
* failed
*/
- (bool)step;
- (id)objectForColumn: (size_t)column;
/**
* @brief Returns the object for the specified column of the current row.
*/
- (id)objectForCurrentRowAtColumn: (size_t)column;
/**
* @brief The number of columns.
*/
- (size_t)columnCount;
/**
* @brief Returns the name for the specified column.
*/
- (OFString *)nameForColumn: (size_t)column;
/**
* @brief Resets the prepared statement.
*
* @throw SL3ResetStatementFailedException The prepared statement could not be
* reset
*/
- (void)reset;
@end

View file

@ -172,7 +172,7 @@ bindObject(SL3PreparedStatement *statement, int column, id object)
return (code == SQLITE_ROW);
}
- (id)objectForColumn: (size_t)column
- (id)objectForCurrentRowAtColumn: (size_t)column
{
if (column > INT_MAX)
@throw [OFOutOfRangeException exception];
@ -216,27 +216,27 @@ bindObject(SL3PreparedStatement *statement, int column, id object)
return [OFString stringWithUTF8String: name];
}
- (OFArray *)rowArray
- (OFArray *)currentRowArray
{
size_t count = [self columnCount];
OFMutableArray *array = [OFMutableArray arrayWithCapacity: count];
for (size_t i = 0; i < count; i++)
[array addObject: [self objectForColumn: i]];
[array addObject: [self objectForCurrentRowAtColumn: i]];
[array makeImmutable];
return array;
}
- (OFDictionary OF_GENERIC(OFString *, id) *)rowDictionary
- (OFDictionary OF_GENERIC(OFString *, id) *)currentRowDictionary
{
size_t count = [self columnCount];
OFMutableDictionary *dictionary =
[OFMutableDictionary dictionaryWithCapacity: count];
for (size_t i = 0; i < count; i++)
[dictionary setObject: [self objectForColumn: i]
[dictionary setObject: [self objectForCurrentRowAtColumn: i]
forKey: [self nameForColumn: i]];
[dictionary makeImmutable];

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2020, 2024 Jonathan Schleifer <js@nil.im>
*
* https://fl.nil.im/objsqlite3
*
@ -22,6 +22,13 @@
OF_ASSUME_NONNULL_BEGIN
/**
* @class SL3BindObjectFailedException SL3BindObjectFailedException.h
* ObjSQLite3/ObjSQLite3.h
*
* @brief An exception indicating that binding an object to a prepared
* statement failed.
*/
@interface SL3BindObjectFailedException: SL3Exception
{
id _object;
@ -29,18 +36,53 @@ OF_ASSUME_NONNULL_BEGIN
SL3PreparedStatement *_statement;
}
/**
* @brief The object that could not be bound to a prepared statement.
*/
@property (readonly, nonatomic) id object;
/**
* @brief The column of the prepared statement to which the object could not be
* bound.
*/
@property (readonly, nonatomic) int column;
/**
* @brief The statement to which the object could not be bound.
*/
@property (readonly, nonatomic) SL3PreparedStatement *statement;
+ (instancetype)exceptionWithConnection: (nullable SL3Connection *)connection
errorCode: (int)errorCode OF_UNAVAILABLE;
/**
* @brief Creates an new bind object failed exception.
*
* @param object The object that could not be bound to a prepared statement
* @param column The column of the prepared statement to which the object could
* not be bound
* @param statement The statement to which the object could not be bound
* @param errorCode The SQLite3 error code
* @return A new, autoreleased bind object failed exception
*/
+ (instancetype)exceptionWithObject: (id)object
column: (int)column
statement: (SL3PreparedStatement *)statement
errorCode: (int)errorCode;
- (instancetype)initWithConnection: (nullable SL3Connection *)connection
errorCode: (int)errorCode OF_UNAVAILABLE;
/**
* @brief Initializes an already allocated bind object failed exception.
*
* @param object The object that could not be bound to a prepared statement
* @param column The column of the prepared statement to which the object could
* not be bound
* @param statement The statement to which the object could not be bound
* @param errorCode The SQLite3 error code
* @return An initialized bind object failed exception
*/
- (instancetype)initWithObject: (id)object
column: (int)column
statement: (SL3PreparedStatement *)statement

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2020, 2024 Jonathan Schleifer <js@nil.im>
*
* https://fl.nil.im/objsqlite3
*
@ -22,19 +22,45 @@
OF_ASSUME_NONNULL_BEGIN
/**
* @class SL3ClearBindingsFailedException SL3ClearBindingsFailedException.h
* ObjSQLite3/ObjSQLite3.h
*
* @brief An exception indicating that clearing a statement's bindings failed.
*/
@interface SL3ClearBindingsFailedException: SL3Exception
{
SL3PreparedStatement *_statement;
}
/**
* @brief The statement whose bindings could not be cleared.
*/
@property (readonly, nonatomic) SL3PreparedStatement *statement;
+ (instancetype)exceptionWithConnection: (nullable SL3Connection *)connection
errorCode: (int)errorCode OF_UNAVAILABLE;
/**
* @brief Creates a new clear bindings failed exception.
*
* @param statement The statement whose bindings could not be cleared
* @param errorCode The SQLite3 error code
* @return A new, autoreleased clear bindings failed exception
*/
+ (instancetype)exceptionWithStatement: (SL3PreparedStatement *)statement
errorCode: (int)errorCode;
- (instancetype)initWithConnection: (nullable SL3Connection *)connection
errorCode: (int)errorCode OF_UNAVAILABLE;
/**
* @brief Initializes an already allocated clear bindings failed exception.
*
* @param statement The statement whose bindings could not be cleared
* @param errorCode The SQLite3 error code
* @return An initialized clear bindings failed exception
*/
- (instancetype)initWithStatement: (SL3PreparedStatement *)statement
errorCode: (int)errorCode OF_DESIGNATED_INITIALIZER;
@end

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2020, 2024 Jonathan Schleifer <js@nil.im>
*
* https://fl.nil.im/objsqlite3
*
@ -22,19 +22,48 @@
OF_ASSUME_NONNULL_BEGIN
/**
* @class SL3Exception SL3Exception.h ObjSQLite3/ObjSQLite3.h
*
* @brief An SQLite3 exception.
*/
@interface SL3Exception: OFException
{
SL3Connection *_connection;
SL3Connection *_Nullable _connection;
int _errorCode;
}
/**
* @brief The connection for which the exception occurred.
*/
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) SL3Connection *connection;
/**
* @brief The SQLite3 error code.
*/
@property (readonly, nonatomic) int errorCode;
+ (instancetype)exception OF_UNAVAILABLE;
/**
* @brief Creates a new SQLite3 exception.
*
* @param connection The connection for which the exception occurred.
* @param errorCode The SQLite3 error code.
* @return A new, autoreleased SQLite3 exception
*/
+ (instancetype)exceptionWithConnection: (nullable SL3Connection *)connection
errorCode: (int)errorCode;
- (instancetype)init OF_UNAVAILABLE;
/**
* @brief Initializes an already allocated SQLite3 exception.
*
* @param connection The connection for which the exception occurred.
* @param errorCode The SQLite3 error code.
* @return An initialized SQLite3 exception
*/
- (instancetype)initWithConnection: (nullable SL3Connection *)connection
errorCode: (int)errorCode OF_DESIGNATED_INITIALIZER;
@end

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2020, 2024 Jonathan Schleifer <js@nil.im>
*
* https://fl.nil.im/objsqlite3
*
@ -22,15 +22,42 @@
OF_ASSUME_NONNULL_BEGIN
/**
* @class SL3ExecuteStatementFailedException
* SL3ExecuteStatementFailedException.h
* ObjSQLite3/ObjSQLite3.h
*
* @brief An exception indicating that executing a statement failed.
*/
@interface SL3ExecuteStatementFailedException: SL3Exception
{
SL3PreparedStatement *_statement;
SL3PreparedStatement *_Nullable _statement;
}
@property (readonly, nonatomic) SL3PreparedStatement *statement;
/**
* @brief The statement that could not be executed.
*/
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
SL3PreparedStatement *statement;
/**
* @brief Creates a new execute statement failed exception.
*
* @param statement The statement that could not be executed
* @param errorCode The SQLite3 error code
* @return A new, autoreleased execute statement exception failed.
*/
+ (instancetype)exceptionWithStatement: (SL3PreparedStatement *)statement
errorCode: (int)errorCode;
/**
* @brief Initializes an an already allocated execute statement failed
* exception.
*
* @param statement The statement that could not be executed
* @param errorCode The SQLite3 error code
* @return An initialized execute statement exception failed.
*/
- (instancetype)initWithStatement: (SL3PreparedStatement *)statement
errorCode: (int)errorCode;
@end

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2020, 2024 Jonathan Schleifer <js@nil.im>
*
* https://fl.nil.im/objsqlite3
*
@ -20,22 +20,54 @@
OF_ASSUME_NONNULL_BEGIN
/**
* @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;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2020, 2024 Jonathan Schleifer <js@nil.im>
*
* https://fl.nil.im/objsqlite3
*
@ -20,20 +20,51 @@
OF_ASSUME_NONNULL_BEGIN
/**
* @class SL3PrepareStatementFailedException
* SL3PrepareStatementFailedException.h
* ObjSQLite3/ObjSQLite3.h
*
* @brief An exception indicating that preparing a statement failed.
*/
@interface SL3PrepareStatementFailedException: SL3Exception
{
OFConstantString *_SQLStatement;
}
/**
* @brief The SQL statement which could not be prepared.
*/
@property (readonly, nonatomic) OFConstantString *SQLStatement;
+ (instancetype)exceptionWithConnection: (nullable SL3Connection *)connection
errorCode: (int)errorCode OF_UNAVAILABLE;
/**
* @brief Creates a new prepare statement failed exception.
*
* @param connection The connection for which the statement could not be
* prepared
* @param SQLStatement The SQL statement which could not be prepared
* @param errorCode The SQLite3 error code
* @return A new, autoreleased prepare statement failed exception
*/
+ (instancetype)exceptionWithConnection: (SL3Connection *)connection
SQLStatement: (OFConstantString *)SQLStatement
errorCode: (int)errorCode;
- (instancetype)initWithConnection: (nullable SL3Connection *)connection
errorCode: (int)errorCode OF_UNAVAILABLE;
/**
* @brief Initializes an already allocated prepare statement failed exception.
*
* @param connection The connection for which the statement could not be
* prepared
* @param SQLStatement The SQL statement which could not be prepared
* @param errorCode The SQLite3 error code
* @return An initialized prepare statement failed exception
*/
- (instancetype)initWithConnection: (SL3Connection *)connection
SQLStatement: (OFConstantString *)SQLStatement
errorCode: (int)errorCode OF_DESIGNATED_INITIALIZER;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2020, 2024 Jonathan Schleifer <js@nil.im>
*
* https://fl.nil.im/objsqlite3
*
@ -22,19 +22,45 @@
OF_ASSUME_NONNULL_BEGIN
/**
* @class SL3ResetStatementFailedException SL3ResetStatementFailedException.h
* ObjSQLite3/ObjSQLite3.h
*
* @param An exception indicating that resetting a statement failed.
*/
@interface SL3ResetStatementFailedException: SL3Exception
{
SL3PreparedStatement *_statement;
}
/**
* @brief The statement that could not be reset.
*/
@property (readonly, nonatomic) SL3PreparedStatement *statement;
+ (instancetype)exceptionWithConnection: (nullable SL3Connection *)connection
errorCode: (int)errorCode OF_UNAVAILABLE;
/**
* @brief Creates a new reset statement failed exception.
*
* @param statement The statement that could not be reset
* @param errorCode The SQLite3 error code
* @return A new, autoreleased reset statement failed exception.
*/
+ (instancetype)exceptionWithStatement: (SL3PreparedStatement *)statement
errorCode: (int)errorCode;
- (instancetype)initWithConnection: (nullable SL3Connection *)connection
errorCode: (int)errorCode OF_UNAVAILABLE;
/**
* @brief Initializes an already allocated reset statement failed exception.
*
* @param statement The statement that could not be reset
* @param errorCode The SQLite3 error code
* @return An initialized reset statement failed exception.
*/
- (instancetype)initWithStatement: (SL3PreparedStatement *)statement
errorCode: (int)errorCode OF_DESIGNATED_INITIALIZER;
@end

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021, 2023 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2020, 2021, 2023, 2024 Jonathan Schleifer <js@nil.im>
*
* https://fl.nil.im/objsqlite3
*
@ -87,13 +87,13 @@ OF_APPLICATION_DELEGATE(Tests)
OFEnsure(0);
}
OFEnsure([[stmt objectForColumn: 0] isEqual: a]);
OFEnsure([[stmt objectForColumn: 1] isEqual: b]);
OFEnsure([[stmt objectForColumn: 2] isEqual: c]);
OFEnsure([[stmt objectForCurrentRowAtColumn: 0] isEqual: a]);
OFEnsure([[stmt objectForCurrentRowAtColumn: 1] isEqual: b]);
OFEnsure([[stmt objectForCurrentRowAtColumn: 2] isEqual: c]);
OFEnsure([[stmt rowArray] isEqual: ([OFArray arrayWithObjects:
a, b, c, nil])]);
OFEnsure([[stmt rowDictionary] isEqual:
OFEnsure([[stmt currentRowArray] isEqual:
([OFArray arrayWithObjects: a, b, c, nil])]);
OFEnsure([[stmt currentRowDictionary] isEqual:
([OFDictionary dictionaryWithKeysAndObjects:
@"a", a, @"b", b, @"c", c, nil])]);
}