Change prefix to PGSQL

Two letter prefixes are too risky to cause collisions.

FossilOrigin-Name: 77c26b4fcecfc3e46c1e0b9412a9a88d0139604e2ad45e54b0c8734d464ea2c6
This commit is contained in:
Jonathan Schleifer 2024-08-11 18:00:52 +00:00
parent 181e9b2e62
commit d205d00765
20 changed files with 112 additions and 111 deletions

View file

@ -13,5 +13,5 @@ PREDEFINED = OF_DESIGNATED_INITIALIZER= \
OF_SENTINEL
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
IGNORE_PREFIX = PG
IGNORE_PREFIX = PGSQL
EXTRACT_STATIC = yes

View file

@ -16,10 +16,10 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
#import "PGResult.h"
#import "PGResultRow.h"
#import "PGConnection.h"
#import "PGSQLResult.h"
#import "PGSQLResultRow.h"
#import "PGSQLConnection.h"
#import "PGException.h"
#import "PGCommandFailedException.h"
#import "PGConnectionFailedException.h"
#import "PGSQLException.h"
#import "PGSQLExecuteCommandFailedException.h"
#import "PGSQLConnectionFailedException.h"

View file

@ -16,11 +16,11 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
#import "PGConnection.h"
#import "PGSQLConnection.h"
OF_ASSUME_NONNULL_BEGIN
@interface PGConnection ()
@interface PGSQLConnection ()
@property (readonly, nonatomic) PGconn *pg_connection;
@end

View file

@ -20,7 +20,7 @@
#import <ObjFW/ObjFW.h>
#import "PGResult.h"
#import "PGSQLResult.h"
OF_ASSUME_NONNULL_BEGIN
@ -29,14 +29,14 @@ OF_ASSUME_NONNULL_BEGIN
/**
* @brief A result row.
*/
typedef OFDictionary OF_GENERIC(OFString *, id) *PGRow;
typedef OFDictionary OF_GENERIC(OFString *, id) *PGSQLRow;
/**
* @class PGConnection PGConnection.h ObjPgSQL/ObjPgSQL.h
* @class PGSQLConnection PGSQLConnection.h ObjPgSQL/ObjPgSQL.h
*
* @brief A connection to a database.
*/
@interface PGConnection: OFObject
@interface PGSQLConnection: OFObject
{
PGconn *_connection;
OFDictionary OF_GENERIC(OFString *, OFString *) *_parameters;
@ -52,7 +52,7 @@ typedef OFDictionary OF_GENERIC(OFString *, id) *PGRow;
/**
* @brief Connects to the database.
*
* @throw PGConnectionFailedException The connection failed
* @throw PGSQLConnectionFailedException The connection failed
*/
- (void)connect;
@ -71,9 +71,9 @@ typedef OFDictionary OF_GENERIC(OFString *, id) *PGRow;
*
* @param command The command to execute
* @return The result of the command, if any
* @throw PGCommandFailedException Executing the command failed.
* @throw PGSQLCommandFailedException Executing the command failed.
*/
- (nullable PGResult *)executeCommand: (OFConstantString *)command;
- (nullable PGSQLResult *)executeCommand: (OFConstantString *)command;
/**
* @brief Executes the specified command.
@ -81,10 +81,10 @@ typedef OFDictionary OF_GENERIC(OFString *, id) *PGRow;
* @param command The command to execute
* @param firstParameter First parameter for the command
* @return The result of the command, if any
* @throw PGCommandFailedException Executing the command failed.
* @throw PGSQLCommandFailedException Executing the command failed.
*/
- (nullable PGResult *)executeCommand: (OFConstantString *)command
parameters: (id)firstParameter, ... OF_SENTINEL;
- (nullable PGSQLResult *)executeCommand: (OFConstantString *)command
parameters: (id)firstParameter, ... OF_SENTINEL;
@end
OF_ASSUME_NONNULL_END

View file

@ -16,15 +16,15 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
#import "PGConnection.h"
#import "PGConnection+Private.h"
#import "PGResult.h"
#import "PGResult+Private.h"
#import "PGSQLConnection.h"
#import "PGSQLConnection+Private.h"
#import "PGSQLResult.h"
#import "PGSQLResult+Private.h"
#import "PGConnectionFailedException.h"
#import "PGExecuteCommandFailedException.h"
#import "PGSQLConnectionFailedException.h"
#import "PGSQLExecuteCommandFailedException.h"
@implementation PGConnection
@implementation PGSQLConnection
@synthesize pg_connection = _connection, parameters = _parameters;
- (instancetype)init
@ -73,7 +73,7 @@
@throw [OFOutOfMemoryException exception];
if (PQstatus(_connection) == CONNECTION_BAD)
@throw [PGConnectionFailedException
@throw [PGSQLConnectionFailedException
exceptionWithConnection: self];
objc_autoreleasePoolPop(pool);
@ -92,33 +92,33 @@
_connection = NULL;
}
- (PGResult *)executeCommand: (OFConstantString *)command
- (PGSQLResult *)executeCommand: (OFConstantString *)command
{
PGresult *result = PQexec(_connection, command.UTF8String);
if (PQresultStatus(result) == PGRES_FATAL_ERROR) {
PQclear(result);
@throw [PGExecuteCommandFailedException
@throw [PGSQLExecuteCommandFailedException
exceptionWithConnection: self
command: command];
}
switch (PQresultStatus(result)) {
case PGRES_TUPLES_OK:
return [PGResult pg_resultWithResult: result];
return [PGSQLResult pg_resultWithResult: result];
case PGRES_COMMAND_OK:
PQclear(result);
return nil;
default:
PQclear(result);
@throw [PGExecuteCommandFailedException
@throw [PGSQLExecuteCommandFailedException
exceptionWithConnection: self
command: command];
}
}
- (PGResult *)executeCommand: (OFConstantString *)command
parameters: (id)parameter, ...
- (PGSQLResult *)executeCommand: (OFConstantString *)command
parameters: (id)parameter, ...
{
void *pool = objc_autoreleasePoolPush();
PGresult *result;
@ -167,13 +167,13 @@
switch (PQresultStatus(result)) {
case PGRES_TUPLES_OK:
return [PGResult pg_resultWithResult: result];
return [PGSQLResult pg_resultWithResult: result];
case PGRES_COMMAND_OK:
PQclear(result);
return nil;
default:
PQclear(result);
@throw [PGExecuteCommandFailedException
@throw [PGSQLExecuteCommandFailedException
exceptionWithConnection: self
command: command];
}

View file

@ -16,11 +16,11 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
#import "PGResult.h"
#import "PGSQLResult.h"
OF_ASSUME_NONNULL_BEGIN
@interface PGResult ()
@interface PGSQLResult ()
@property (readonly, nonatomic) PGresult *pg_result;
+ (instancetype)pg_resultWithResult: (PGresult *)result;

View file

@ -22,17 +22,17 @@
OF_ASSUME_NONNULL_BEGIN
@class PGResultRow;
@class PGSQLResultRow;
/**
* @class PGResult PGResult.h ObjPgSQL/ObjPgSQL.h
* @class PGSQLResult PGSQLResult.h ObjPgSQL/ObjPgSQL.h
*
* @brief A PostgreSQL result.
*
* This is a regular OFArray, where each entry in the array represents a result
* row.
*/
@interface PGResult: OFArray OF_GENERIC(PGResultRow *)
@interface PGSQLResult: OFArray OF_GENERIC(PGSQLResultRow *)
{
PGresult *_result;
}

View file

@ -16,12 +16,12 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
#import "PGResult.h"
#import "PGResult+Private.h"
#import "PGResultRow.h"
#import "PGResultRow+Private.h"
#import "PGSQLResult.h"
#import "PGSQLResult+Private.h"
#import "PGSQLResultRow.h"
#import "PGSQLResultRow+Private.h"
@implementation PGResult
@implementation PGSQLResult
@synthesize pg_result = _result;
+ (instancetype)pg_resultWithResult: (PGresult *)result
@ -56,6 +56,6 @@
if (index > LONG_MAX || (long)index > PQntuples(_result))
@throw [OFOutOfRangeException exception];
return [PGResultRow pg_rowWithResult: self row: (int)index];
return [PGSQLResultRow pg_rowWithResult: self row: (int)index];
}
@end

View file

@ -16,13 +16,13 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
#import "PGResultRow.h"
#import "PGSQLResultRow.h"
OF_ASSUME_NONNULL_BEGIN
@interface PGResultRow ()
+ (instancetype)pg_rowWithResult: (PGResult *)result row: (int)row;
- (instancetype)pg_initWithResult: (PGResult *)result row: (int)row;
@interface PGSQLResultRow ()
+ (instancetype)pg_rowWithResult: (PGSQLResult *)result row: (int)row;
- (instancetype)pg_initWithResult: (PGSQLResult *)result row: (int)row;
@end
OF_ASSUME_NONNULL_END

View file

@ -20,21 +20,21 @@
#import <ObjFW/ObjFW.h>
#import "PGResult.h"
#import "PGSQLResult.h"
OF_ASSUME_NONNULL_BEGIN
/**
* @class PGResult PGResult.h ObjPgSQL/ObjPgSQL.h
* @class PGSQLResult PGSQLResult.h ObjPgSQL/ObjPgSQL.h
*
* @brief A PostgreSQL result row.
*
* This is a regular OFDictionary, where each entry in the dictionary
* represents a column of the result row.
*/
@interface PGResultRow: OFDictionary OF_GENERIC(OFString *, id)
@interface PGSQLResultRow: OFDictionary OF_GENERIC(OFString *, id)
{
PGResult *_result;
PGSQLResult *_result;
PGresult *_res;
int _row;
}

View file

@ -16,8 +16,8 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
#import "PGResultRow.h"
#import "PGResult+Private.h"
#import "PGSQLResultRow.h"
#import "PGSQLResult+Private.h"
static id
convertType(PGresult *res, int column, OFString *string)
@ -46,29 +46,29 @@ convertType(PGresult *res, int column, OFString *string)
return string;
}
@interface PGResultRowEnumerator: OFEnumerator
@interface PGSQLResultRowEnumerator: OFEnumerator
{
PGResult *_result;
PGSQLResult *_result;
PGresult *_res;
int _row, _pos, _count;
}
- (instancetype)initWithResult: (PGResult*)result row: (int)row;
- (instancetype)initWithResult: (PGSQLResult*)result row: (int)row;
@end
@interface PGResultRowKeyEnumerator: PGResultRowEnumerator
@interface PGSQLResultRowKeyEnumerator: PGSQLResultRowEnumerator
@end
@interface PGResultRowObjectEnumerator: PGResultRowEnumerator
@interface PGSQLResultRowObjectEnumerator: PGSQLResultRowEnumerator
@end
@implementation PGResultRow
+ (instancetype)pg_rowWithResult: (PGResult *)result row: (int)row
@implementation PGSQLResultRow
+ (instancetype)pg_rowWithResult: (PGSQLResult *)result row: (int)row
{
return [[[self alloc] pg_initWithResult: result row: row] autorelease];
}
- (instancetype)pg_initWithResult: (PGResult *)result row: (int)row
- (instancetype)pg_initWithResult: (PGSQLResult *)result row: (int)row
{
self = [super init];
@ -115,14 +115,14 @@ convertType(PGresult *res, int column, OFString *string)
- (OFEnumerator *)keyEnumerator
{
return [[[PGResultRowKeyEnumerator alloc]
return [[[PGSQLResultRowKeyEnumerator alloc]
initWithResult: _result
row: _row] autorelease];
}
- (OFEnumerator *)objectEnumerator
{
return [[[PGResultRowObjectEnumerator alloc]
return [[[PGSQLResultRowObjectEnumerator alloc]
initWithResult: _result
row: _row] autorelease];
}
@ -160,8 +160,8 @@ convertType(PGresult *res, int column, OFString *string)
}
@end
@implementation PGResultRowEnumerator
- (instancetype)initWithResult: (PGResult *)result row: (int)row
@implementation PGSQLResultRowEnumerator
- (instancetype)initWithResult: (PGSQLResult *)result row: (int)row
{
self = [super init];
@ -186,7 +186,7 @@ convertType(PGresult *res, int column, OFString *string)
}
@end
@implementation PGResultRowKeyEnumerator
@implementation PGSQLResultRowKeyEnumerator
- (id)nextObject
{
if (_pos >= _count)
@ -202,7 +202,7 @@ convertType(PGresult *res, int column, OFString *string)
}
@end
@implementation PGResultRowObjectEnumerator
@implementation PGSQLResultRowObjectEnumerator
- (id)nextObject
{
id object;

View file

@ -16,17 +16,17 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
#import "PGException.h"
#import "PGSQLException.h"
OF_ASSUME_NONNULL_BEGIN
/**
* @class PGConnectionFailedException PGConnectionFailedException.h
* @class PGSQLConnectionFailedException PGSQLConnectionFailedException.h
* PgSQL/PgSQL.h
*
* @brief An exception indicating that connecting to the database failed.
*/
@interface PGConnectionFailedException: PGException
@interface PGSQLConnectionFailedException: PGSQLException
@end
OF_ASSUME_NONNULL_END

View file

@ -16,9 +16,9 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
#import "PGConnectionFailedException.h"
#import "PGSQLConnectionFailedException.h"
@implementation PGConnectionFailedException
@implementation PGSQLConnectionFailedException
- (OFString *)description
{
return [OFString stringWithFormat:

View file

@ -18,25 +18,25 @@
#import <ObjFW/ObjFW.h>
#import "PGConnection.h"
#import "PGSQLConnection.h"
OF_ASSUME_NONNULL_BEGIN
/**
* @class PGException PGException.h ObjPgSQL/ObjPgSQL.h
* @class PGSQLException PGSQLException.h ObjPgSQL/ObjPgSQL.h
*
* @brief A PostgreSQL exception.
*/
@interface PGException: OFException
@interface PGSQLException: OFException
{
PGConnection *_connection;
PGSQLConnection *_connection;
OFString *_errorMessage;
}
/**
* @brief The connection for which the exception occurred.
*/
@property (readonly, nonatomic) PGConnection *connection;
@property (readonly, nonatomic) PGSQLConnection *connection;
/**
* @brief An error message for the exception.
@ -51,7 +51,7 @@ OF_ASSUME_NONNULL_BEGIN
* @param connection The connection for which the exception occurred
* @return A new, autoreleased PostgreSQL exception
*/
+ (instancetype)exceptionWithConnection: (PGConnection *)connection;
+ (instancetype)exceptionWithConnection: (PGSQLConnection *)connection;
- (instancetype)init OF_UNAVAILABLE;
@ -61,7 +61,7 @@ OF_ASSUME_NONNULL_BEGIN
* @param connection The connection for which the exception occurred
* @return An initialized PostgreSQL exception
*/
- (instancetype)initWithConnection: (PGConnection *)connection
- (instancetype)initWithConnection: (PGSQLConnection *)connection
OF_DESIGNATED_INITIALIZER;
@end

View file

@ -16,10 +16,10 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
#import "PGException.h"
#import "PGConnection+Private.h"
#import "PGSQLException.h"
#import "PGSQLConnection+Private.h"
@implementation PGException
@implementation PGSQLException
@synthesize connection = _connection, errorMessage = _errorMessage;
+ (instancetype)exception
@ -27,7 +27,7 @@
OF_UNRECOGNIZED_SELECTOR
}
+ (instancetype)exceptionWithConnection: (PGConnection *)connection
+ (instancetype)exceptionWithConnection: (PGSQLConnection *)connection
{
return [[[self alloc] initWithConnection: connection] autorelease];
}
@ -37,7 +37,7 @@
OF_INVALID_INIT_METHOD
}
- (instancetype)initWithConnection: (PGConnection *)connection
- (instancetype)initWithConnection: (PGSQLConnection *)connection
{
self = [super init];

View file

@ -16,17 +16,18 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
#import "PGException.h"
#import "PGSQLException.h"
OF_ASSUME_NONNULL_BEGIN
/**
* @class PGExecuteCommandFailedException PGExecuteCommandFailedException.h
* @class PGSQLExecuteCommandFailedException
* PGSQLExecuteCommandFailedException.h
* ObjPgSQL/ObjPgSQL.h
*
* @brief An exception indicating that executing a command failed.
*/
@interface PGExecuteCommandFailedException: PGException
@interface PGSQLExecuteCommandFailedException: PGSQLException
{
OFConstantString *_command;
}
@ -36,7 +37,7 @@ OF_ASSUME_NONNULL_BEGIN
*/
@property (readonly, nonatomic) OFConstantString *command;
+ (instancetype)exceptionWithConnection: (PGConnection *)connection
+ (instancetype)exceptionWithConnection: (PGSQLConnection *)connection
OF_UNAVAILABLE;
/**
@ -46,10 +47,11 @@ OF_ASSUME_NONNULL_BEGIN
* @param command The command which could not be executed
* @return A new, autoreleased execute command failed exception
*/
+ (instancetype)exceptionWithConnection: (PGConnection *)connection
+ (instancetype)exceptionWithConnection: (PGSQLConnection *)connection
command: (OFConstantString *)command;
- (instancetype)initWithConnection: (PGConnection *)connection OF_UNAVAILABLE;
- (instancetype)initWithConnection: (PGSQLConnection *)connection
OF_UNAVAILABLE;
/**
* @brief Initializes an already allocated execte command failed exception.
@ -58,7 +60,7 @@ OF_ASSUME_NONNULL_BEGIN
* @param command The command which could not be executed
* @return An initialized execute command failed exception
*/
- (instancetype)initWithConnection: (PGConnection *)connection
- (instancetype)initWithConnection: (PGSQLConnection *)connection
command: (OFConstantString *)command
OF_DESIGNATED_INITIALIZER;
@end

View file

@ -16,29 +16,29 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
#import "PGExecuteCommandFailedException.h"
#import "PGSQLExecuteCommandFailedException.h"
@implementation PGExecuteCommandFailedException
@implementation PGSQLExecuteCommandFailedException
@synthesize command = _command;
+ (instancetype)exceptionWithConnection: (PGConnection *)connection
+ (instancetype)exceptionWithConnection: (PGSQLConnection *)connection
{
OF_UNRECOGNIZED_SELECTOR
}
+ (instancetype)exceptionWithConnection: (PGConnection *)connection
+ (instancetype)exceptionWithConnection: (PGSQLConnection *)connection
command: (OFConstantString *)command
{
return [[[self alloc] initWithConnection: connection
command: command] autorelease];
}
- (instancetype)initWithConnection: (PGConnection *)connection
- (instancetype)initWithConnection: (PGSQLConnection *)connection
{
OF_INVALID_INIT_METHOD
}
- (instancetype)initWithConnection: (PGConnection *)connection
- (instancetype)initWithConnection: (PGSQLConnection *)connection
command: (OFConstantString *)command
{
self = [super initWithConnection: connection];

View file

@ -1,5 +1,5 @@
exceptions_sources = files(
'PGConnectionFailedException.m',
'PGException.m',
'PGExecuteCommandFailedException.m',
'PGSQLConnectionFailedException.m',
'PGSQLException.m',
'PGSQLExecuteCommandFailedException.m',
)

View file

@ -3,9 +3,9 @@ fs = import('fs')
subdir('exceptions')
sources = files(
'PGConnection.m',
'PGResult.m',
'PGResultRow.m',
'PGSQLConnection.m',
'PGSQLResult.m',
'PGSQLResultRow.m',
)
objpgsql = library('objpgsql',

View file

@ -18,12 +18,11 @@
#import <ObjFW/ObjFW.h>
#import "PGConnection.h"
#import "PGConnectionFailedException.h"
#import "ObjPgSQL.h"
@interface Test: OFObject <OFApplicationDelegate>
{
PGConnection *_connection;
PGSQLConnection *_connection;
}
@end
@ -34,9 +33,9 @@ OF_APPLICATION_DELEGATE(Test)
{
OFString *username =
[[OFApplication environment] objectForKey: @"USER"];
PGResult *result;
PGSQLResult *result;
_connection = [[PGConnection alloc] init];
_connection = [[PGSQLConnection alloc] init];
[_connection setParameters:
[OFDictionary dictionaryWithKeysAndObjects: @"user", username,
@"dbname", username,