Add a proper build system
FossilOrigin-Name: 8679c61b2c82da9daa316ed5eb90ba1b69e608127afa318cbdbff56b53d65a74
This commit is contained in:
parent
71342537cf
commit
35212e3305
28 changed files with 5118 additions and 76 deletions
14
src/exceptions/Makefile
Normal file
14
src/exceptions/Makefile
Normal file
|
@ -0,0 +1,14 @@
|
|||
include ../../extra.mk
|
||||
|
||||
STATIC_PIC_LIB_NOINST = ${EXCEPTIONS_LIB_A}
|
||||
STATIC_LIB_NOINST = ${EXCEPTIONS_A}
|
||||
|
||||
SRCS = PGCommandFailedException.m \
|
||||
PGConnectionFailedException.m \
|
||||
PGException.m
|
||||
|
||||
INCLUDES = ${SRCS:.m=.h}
|
||||
|
||||
include ../../buildsys.mk
|
||||
|
||||
CPPFLAGS += -I. -I..
|
17
src/exceptions/PGCommandFailedException.h
Normal file
17
src/exceptions/PGCommandFailedException.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#import "PGException.h"
|
||||
|
||||
@interface PGCommandFailedException: PGException
|
||||
{
|
||||
OFString *_command;
|
||||
}
|
||||
|
||||
#ifdef OF_HAVE_PROPERTIES
|
||||
@property (readonly, copy, nonatomic) OFString *command;
|
||||
#endif
|
||||
|
||||
+ (instancetype)exceptionWithConnection: (PGConnection*)connection
|
||||
command: (OFString*)command;
|
||||
- initWithConnection: (PGConnection*)connection
|
||||
command: (OFString*)command;
|
||||
- (OFString*)command;
|
||||
@end
|
43
src/exceptions/PGCommandFailedException.m
Normal file
43
src/exceptions/PGCommandFailedException.m
Normal file
|
@ -0,0 +1,43 @@
|
|||
#import "PGCommandFailedException.h"
|
||||
|
||||
@implementation PGCommandFailedException
|
||||
+ (instancetype)exceptionWithConnection: (PGConnection*)connection
|
||||
command: (OFString*)command
|
||||
{
|
||||
return [[[self alloc] initWithConnection: connection
|
||||
command: command] autorelease];
|
||||
}
|
||||
|
||||
- initWithConnection: (PGConnection*)connection
|
||||
command: (OFString*)command
|
||||
{
|
||||
self = [super initWithConnection: connection];
|
||||
|
||||
@try {
|
||||
_command = [command copy];
|
||||
} @catch (id e) {
|
||||
[self release];
|
||||
@throw e;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[_command release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (OFString*)description
|
||||
{
|
||||
return [OFString stringWithFormat: @"A PostgreSQL command failed: %@\n"
|
||||
@"Command: %@", _error, _command];
|
||||
}
|
||||
|
||||
- (OFString*)command
|
||||
{
|
||||
OF_GETTER(_command, NO)
|
||||
}
|
||||
@end
|
4
src/exceptions/PGConnectionFailedException.h
Normal file
4
src/exceptions/PGConnectionFailedException.h
Normal file
|
@ -0,0 +1,4 @@
|
|||
#import "PGException.h"
|
||||
|
||||
@interface PGConnectionFailedException: PGException
|
||||
@end
|
10
src/exceptions/PGConnectionFailedException.m
Normal file
10
src/exceptions/PGConnectionFailedException.m
Normal file
|
@ -0,0 +1,10 @@
|
|||
#import "PGConnectionFailedException.h"
|
||||
|
||||
@implementation PGConnectionFailedException
|
||||
- (OFString*)description
|
||||
{
|
||||
return [OFString stringWithFormat:
|
||||
@"Establishing a PostgreSQL connection failed:\n%@\n"
|
||||
"Parameters: %@", _error, [_connection parameters]];
|
||||
}
|
||||
@end
|
18
src/exceptions/PGException.h
Normal file
18
src/exceptions/PGException.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#import <ObjFW/ObjFW.h>
|
||||
|
||||
#import "PGConnection.h"
|
||||
|
||||
@interface PGException: OFException
|
||||
{
|
||||
PGConnection *_connection;
|
||||
OFString *_error;
|
||||
}
|
||||
|
||||
#ifdef OF_HAVE_PROPERTIES
|
||||
@property (readonly, retain, nonatomic) PGConnection *connection;
|
||||
#endif
|
||||
|
||||
+ (instancetype)exceptionWithConnection: (PGConnection*)connection;
|
||||
- initWithConnection: (PGConnection*)connection;
|
||||
- (PGConnection*)connection;
|
||||
@end
|
44
src/exceptions/PGException.m
Normal file
44
src/exceptions/PGException.m
Normal file
|
@ -0,0 +1,44 @@
|
|||
#import "PGException.h"
|
||||
|
||||
@implementation PGException
|
||||
+ (instancetype)exceptionWithConnection: (PGConnection*)connection
|
||||
{
|
||||
return [[[self alloc] initWithConnection: connection] autorelease];
|
||||
}
|
||||
|
||||
- initWithConnection: (PGConnection*)connection
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
@try {
|
||||
_connection = [connection retain];
|
||||
_error = [[OFString alloc]
|
||||
initWithCString: PQerrorMessage([_connection PG_connection])
|
||||
encoding: [OFString nativeOSEncoding]];
|
||||
} @catch (id e) {
|
||||
[self release];
|
||||
@throw e;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[_connection release];
|
||||
[_error release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (OFString*)description
|
||||
{
|
||||
return [OFString stringWithFormat: @"A PostgreSQL operation failed: %@",
|
||||
_error];
|
||||
}
|
||||
|
||||
- (PGConnection*)connection
|
||||
{
|
||||
OF_GETTER(_connection, NO)
|
||||
}
|
||||
@end
|
Loading…
Add table
Add a link
Reference in a new issue