ObjPgSQL  Check-in [77c26b4fce]

Overview
Comment:Change prefix to PGSQL

Two letter prefixes are too risky to cause collisions.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 77c26b4fcecfc3e46c1e0b9412a9a88d0139604e2ad45e54b0c8734d464ea2c6
User & Date: js 2024-08-11 18:00:52
Context
2024-08-11
18:01
Set version to 1.0 check-in: 33735ae0cd user: js tags: trunk, 1.0-release
18:00
Change prefix to PGSQL check-in: 77c26b4fce user: js tags: trunk
17:48
Remove .gitignore check-in: 6a6b563eda user: js tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Doxyfile.

9
10
11
12
13
14
15
16
17
HIDE_UNDOC_MEMBERS = YES
TYPEDEF_HIDES_STRUCT = YES
PREDEFINED = OF_DESIGNATED_INITIALIZER=	\
	     OF_GENERIC(...)=		\
	     OF_SENTINEL
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
IGNORE_PREFIX = PG
EXTRACT_STATIC = yes







|

9
10
11
12
13
14
15
16
17
HIDE_UNDOC_MEMBERS = YES
TYPEDEF_HIDES_STRUCT = YES
PREDEFINED = OF_DESIGNATED_INITIALIZER=	\
	     OF_GENERIC(...)=		\
	     OF_SENTINEL
MACRO_EXPANSION = YES
EXPAND_ONLY_PREDEF = YES
IGNORE_PREFIX = PGSQL
EXTRACT_STATIC = yes

Changes to src/ObjPgSQL.h.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGResult.h"
#import "PGResultRow.h"
#import "PGConnection.h"

#import "PGException.h"
#import "PGCommandFailedException.h"
#import "PGConnectionFailedException.h"







|
|
|

|
|
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGSQLResult.h"
#import "PGSQLResultRow.h"
#import "PGSQLConnection.h"

#import "PGSQLException.h"
#import "PGSQLExecuteCommandFailedException.h"
#import "PGSQLConnectionFailedException.h"

Name change from src/PGConnection+Private.h to src/PGSQLConnection+Private.h.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGConnection.h"

OF_ASSUME_NONNULL_BEGIN

@interface PGConnection ()
@property (readonly, nonatomic) PGconn *pg_connection;
@end

OF_ASSUME_NONNULL_END







|



|




12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGSQLConnection.h"

OF_ASSUME_NONNULL_BEGIN

@interface PGSQLConnection ()
@property (readonly, nonatomic) PGconn *pg_connection;
@end

OF_ASSUME_NONNULL_END

Name change from src/PGConnection.h to src/PGSQLConnection.h.

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
 * PERFORMANCE OF THIS SOFTWARE.
 */

#include <libpq-fe.h>

#import <ObjFW/ObjFW.h>

#import "PGResult.h"

OF_ASSUME_NONNULL_BEGIN

/** @file */

/**
 * @brief A result row.
 */
typedef OFDictionary OF_GENERIC(OFString *, id) *PGRow;

/**
 * @class PGConnection PGConnection.h ObjPgSQL/ObjPgSQL.h
 *
 * @brief A connection to a database.
 */
@interface PGConnection: OFObject
{
	PGconn *_connection;
	OFDictionary OF_GENERIC(OFString *, OFString *) *_parameters;
}

/**
 * @brief The parameters for the database connection. See `PQconnectdb` in the
 *	  PostgreSQL documentation.
 */
@property (nonatomic, copy)
    OFDictionary OF_GENERIC(OFString *, OFString *) *parameters;

/**
 * @brief Connects to the database.
 *
 * @throw PGConnectionFailedException The connection failed
 */
- (void)connect;

/**
 * @brief Resets the connection to the database.
 */
- (void)reset;

/**
 * @brief Closes the connection to the database.
 */
- (void)close;

/**
 * @brief Executes the specified command.
 *
 * @param command The command to execute
 * @return The result of the command, if any
 * @throw PGCommandFailedException Executing the command failed.
 */
- (nullable PGResult *)executeCommand: (OFConstantString *)command;

/**
 * @brief Executes the specified command.
 *
 * @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.
 */
- (nullable PGResult *)executeCommand: (OFConstantString *)command
			   parameters: (id)firstParameter, ... OF_SENTINEL;
@end

OF_ASSUME_NONNULL_END







|








|


|



|















|


















|

|







|

|
|



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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
 * PERFORMANCE OF THIS SOFTWARE.
 */

#include <libpq-fe.h>

#import <ObjFW/ObjFW.h>

#import "PGSQLResult.h"

OF_ASSUME_NONNULL_BEGIN

/** @file */

/**
 * @brief A result row.
 */
typedef OFDictionary OF_GENERIC(OFString *, id) *PGSQLRow;

/**
 * @class PGSQLConnection PGSQLConnection.h ObjPgSQL/ObjPgSQL.h
 *
 * @brief A connection to a database.
 */
@interface PGSQLConnection: OFObject
{
	PGconn *_connection;
	OFDictionary OF_GENERIC(OFString *, OFString *) *_parameters;
}

/**
 * @brief The parameters for the database connection. See `PQconnectdb` in the
 *	  PostgreSQL documentation.
 */
@property (nonatomic, copy)
    OFDictionary OF_GENERIC(OFString *, OFString *) *parameters;

/**
 * @brief Connects to the database.
 *
 * @throw PGSQLConnectionFailedException The connection failed
 */
- (void)connect;

/**
 * @brief Resets the connection to the database.
 */
- (void)reset;

/**
 * @brief Closes the connection to the database.
 */
- (void)close;

/**
 * @brief Executes the specified command.
 *
 * @param command The command to execute
 * @return The result of the command, if any
 * @throw PGSQLCommandFailedException Executing the command failed.
 */
- (nullable PGSQLResult *)executeCommand: (OFConstantString *)command;

/**
 * @brief Executes the specified command.
 *
 * @param command The command to execute
 * @param firstParameter First parameter for the command
 * @return The result of the command, if any
 * @throw PGSQLCommandFailedException Executing the command failed.
 */
- (nullable PGSQLResult *)executeCommand: (OFConstantString *)command
			      parameters: (id)firstParameter, ... OF_SENTINEL;
@end

OF_ASSUME_NONNULL_END

Name change from src/PGConnection.m to src/PGSQLConnection.m.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGConnection.h"
#import "PGConnection+Private.h"
#import "PGResult.h"
#import "PGResult+Private.h"

#import "PGConnectionFailedException.h"
#import "PGExecuteCommandFailedException.h"

@implementation PGConnection
@synthesize pg_connection = _connection, parameters = _parameters;

- (instancetype)init
{
	self = [super init];

	@try {







|
|
|
|

|
|

|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGSQLConnection.h"
#import "PGSQLConnection+Private.h"
#import "PGSQLResult.h"
#import "PGSQLResult+Private.h"

#import "PGSQLConnectionFailedException.h"
#import "PGSQLExecuteCommandFailedException.h"

@implementation PGSQLConnection
@synthesize pg_connection = _connection, parameters = _parameters;

- (instancetype)init
{
	self = [super init];

	@try {
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
			    @"%@=%@", key, object];
	}

	if ((_connection = PQconnectdb(connectionInfo.UTF8String)) == NULL)
		@throw [OFOutOfMemoryException exception];

	if (PQstatus(_connection) == CONNECTION_BAD)
		@throw [PGConnectionFailedException
		    exceptionWithConnection: self];

	objc_autoreleasePoolPop(pool);
}

- (void)reset
{
	PQreset(_connection);
}

- (void)close
{
	if (_connection != NULL)
		PQfinish(_connection);

	_connection = NULL;
}

- (PGResult *)executeCommand: (OFConstantString *)command
{
	PGresult *result = PQexec(_connection, command.UTF8String);

	if (PQresultStatus(result) == PGRES_FATAL_ERROR) {
		PQclear(result);
		@throw [PGExecuteCommandFailedException
		    exceptionWithConnection: self
				    command: command];
	}

	switch (PQresultStatus(result)) {
	case PGRES_TUPLES_OK:
		return [PGResult pg_resultWithResult: result];
	case PGRES_COMMAND_OK:
		PQclear(result);
		return nil;
	default:
		PQclear(result);
		@throw [PGExecuteCommandFailedException
		    exceptionWithConnection: self
				    command: command];
	}
}

- (PGResult *)executeCommand: (OFConstantString *)command
		  parameters: (id)parameter, ...
{
	void *pool = objc_autoreleasePoolPush();
	PGresult *result;
	const char **values;
	va_list args, args2;
	int argsCount;








|


















|





|






|





|





|
|







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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
			    @"%@=%@", key, object];
	}

	if ((_connection = PQconnectdb(connectionInfo.UTF8String)) == NULL)
		@throw [OFOutOfMemoryException exception];

	if (PQstatus(_connection) == CONNECTION_BAD)
		@throw [PGSQLConnectionFailedException
		    exceptionWithConnection: self];

	objc_autoreleasePoolPop(pool);
}

- (void)reset
{
	PQreset(_connection);
}

- (void)close
{
	if (_connection != NULL)
		PQfinish(_connection);

	_connection = NULL;
}

- (PGSQLResult *)executeCommand: (OFConstantString *)command
{
	PGresult *result = PQexec(_connection, command.UTF8String);

	if (PQresultStatus(result) == PGRES_FATAL_ERROR) {
		PQclear(result);
		@throw [PGSQLExecuteCommandFailedException
		    exceptionWithConnection: self
				    command: command];
	}

	switch (PQresultStatus(result)) {
	case PGRES_TUPLES_OK:
		return [PGSQLResult pg_resultWithResult: result];
	case PGRES_COMMAND_OK:
		PQclear(result);
		return nil;
	default:
		PQclear(result);
		@throw [PGSQLExecuteCommandFailedException
		    exceptionWithConnection: self
				    command: command];
	}
}

- (PGSQLResult *)executeCommand: (OFConstantString *)command
		     parameters: (id)parameter, ...
{
	void *pool = objc_autoreleasePoolPush();
	PGresult *result;
	const char **values;
	va_list args, args2;
	int argsCount;

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
		OFFreeMemory(values);
	}

	objc_autoreleasePoolPop(pool);

	switch (PQresultStatus(result)) {
	case PGRES_TUPLES_OK:
		return [PGResult pg_resultWithResult: result];
	case PGRES_COMMAND_OK:
		PQclear(result);
		return nil;
	default:
		PQclear(result);
		@throw [PGExecuteCommandFailedException
		    exceptionWithConnection: self
				    command: command];
	}
}
@end







|





|





163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
		OFFreeMemory(values);
	}

	objc_autoreleasePoolPop(pool);

	switch (PQresultStatus(result)) {
	case PGRES_TUPLES_OK:
		return [PGSQLResult pg_resultWithResult: result];
	case PGRES_COMMAND_OK:
		PQclear(result);
		return nil;
	default:
		PQclear(result);
		@throw [PGSQLExecuteCommandFailedException
		    exceptionWithConnection: self
				    command: command];
	}
}
@end

Name change from src/PGResult+Private.h to src/PGSQLResult+Private.h.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGResult.h"

OF_ASSUME_NONNULL_BEGIN

@interface PGResult ()
@property (readonly, nonatomic) PGresult *pg_result;

+ (instancetype)pg_resultWithResult: (PGresult *)result;
- (instancetype)pg_initWithResult: (PGresult *)result;
@end

OF_ASSUME_NONNULL_END







|



|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGSQLResult.h"

OF_ASSUME_NONNULL_BEGIN

@interface PGSQLResult ()
@property (readonly, nonatomic) PGresult *pg_result;

+ (instancetype)pg_resultWithResult: (PGresult *)result;
- (instancetype)pg_initWithResult: (PGresult *)result;
@end

OF_ASSUME_NONNULL_END

Name change from src/PGResult.h to src/PGSQLResult.h.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

#include <libpq-fe.h>

#import <ObjFW/ObjFW.h>

OF_ASSUME_NONNULL_BEGIN

@class PGResultRow;

/**
 * @class PGResult PGResult.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 *)
{
	PGresult *_result;
}
@end

OF_ASSUME_NONNULL_END







|


|






|






18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

#include <libpq-fe.h>

#import <ObjFW/ObjFW.h>

OF_ASSUME_NONNULL_BEGIN

@class PGSQLResultRow;

/**
 * @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 PGSQLResult: OFArray OF_GENERIC(PGSQLResultRow *)
{
	PGresult *_result;
}
@end

OF_ASSUME_NONNULL_END

Name change from src/PGResult.m to src/PGSQLResult.m.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGResult.h"
#import "PGResult+Private.h"
#import "PGResultRow.h"
#import "PGResultRow+Private.h"

@implementation PGResult
@synthesize pg_result = _result;

+ (instancetype)pg_resultWithResult: (PGresult *)result
{
	return [[[self alloc] pg_initWithResult: result] autorelease];
}








|
|
|
|

|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGSQLResult.h"
#import "PGSQLResult+Private.h"
#import "PGSQLResultRow.h"
#import "PGSQLResultRow+Private.h"

@implementation PGSQLResult
@synthesize pg_result = _result;

+ (instancetype)pg_resultWithResult: (PGresult *)result
{
	return [[[self alloc] pg_initWithResult: result] autorelease];
}

52
53
54
55
56
57
58
59
60
61
}

- (id)objectAtIndex: (size_t)index
{
	if (index > LONG_MAX || (long)index > PQntuples(_result))
		@throw [OFOutOfRangeException exception];

	return [PGResultRow pg_rowWithResult: self row: (int)index];
}
@end







|


52
53
54
55
56
57
58
59
60
61
}

- (id)objectAtIndex: (size_t)index
{
	if (index > LONG_MAX || (long)index > PQntuples(_result))
		@throw [OFOutOfRangeException exception];

	return [PGSQLResultRow pg_rowWithResult: self row: (int)index];
}
@end

Name change from src/PGResultRow+Private.h to src/PGSQLResultRow+Private.h.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGResultRow.h"

OF_ASSUME_NONNULL_BEGIN

@interface PGResultRow ()
+ (instancetype)pg_rowWithResult: (PGResult *)result row: (int)row;
- (instancetype)pg_initWithResult: (PGResult *)result row: (int)row;
@end

OF_ASSUME_NONNULL_END







|



|
|
|



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGSQLResultRow.h"

OF_ASSUME_NONNULL_BEGIN

@interface PGSQLResultRow ()
+ (instancetype)pg_rowWithResult: (PGSQLResult *)result row: (int)row;
- (instancetype)pg_initWithResult: (PGSQLResult *)result row: (int)row;
@end

OF_ASSUME_NONNULL_END

Name change from src/PGResultRow.h to src/PGSQLResultRow.h.

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
 * PERFORMANCE OF THIS SOFTWARE.
 */

#include <libpq-fe.h>

#import <ObjFW/ObjFW.h>

#import "PGResult.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class PGResult PGResult.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)
{
	PGResult *_result;
	PGresult *_res;
	int _row;
}
@end

OF_ASSUME_NONNULL_END







|




|






|

|






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
 * PERFORMANCE OF THIS SOFTWARE.
 */

#include <libpq-fe.h>

#import <ObjFW/ObjFW.h>

#import "PGSQLResult.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @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 PGSQLResultRow: OFDictionary OF_GENERIC(OFString *, id)
{
	PGSQLResult *_result;
	PGresult *_res;
	int _row;
}
@end

OF_ASSUME_NONNULL_END

Name change from src/PGResultRow.m to src/PGSQLResultRow.m.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGResultRow.h"
#import "PGResult+Private.h"

static id
convertType(PGresult *res, int column, OFString *string)
{
	switch (PQftype(res, column)) {
	case 16:  /* BOOLOID */
		if ([string isEqual: @"t"])







|
|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGSQLResultRow.h"
#import "PGSQLResult+Private.h"

static id
convertType(PGresult *res, int column, OFString *string)
{
	switch (PQftype(res, column)) {
	case 16:  /* BOOLOID */
		if ([string isEqual: @"t"])
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
	case 701: /* FLOAT8OID */
		return [OFNumber numberWithDouble: string.doubleValue];
	}

	return string;
}

@interface PGResultRowEnumerator: OFEnumerator
{
	PGResult *_result;
	PGresult *_res;
	int _row, _pos, _count;
}

- (instancetype)initWithResult: (PGResult*)result row: (int)row;
@end

@interface PGResultRowKeyEnumerator: PGResultRowEnumerator
@end

@interface PGResultRowObjectEnumerator: PGResultRowEnumerator
@end

@implementation PGResultRow
+ (instancetype)pg_rowWithResult: (PGResult *)result row: (int)row
{
	return [[[self alloc] pg_initWithResult: result row: row] autorelease];
}

- (instancetype)pg_initWithResult: (PGResult *)result row: (int)row
{
	self = [super init];

	_result = [result retain];
	_res = result.pg_result;
	_row = row;








|

|




|


|


|


|
|




|







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
	case 701: /* FLOAT8OID */
		return [OFNumber numberWithDouble: string.doubleValue];
	}

	return string;
}

@interface PGSQLResultRowEnumerator: OFEnumerator
{
	PGSQLResult *_result;
	PGresult *_res;
	int _row, _pos, _count;
}

- (instancetype)initWithResult: (PGSQLResult*)result row: (int)row;
@end

@interface PGSQLResultRowKeyEnumerator: PGSQLResultRowEnumerator
@end

@interface PGSQLResultRowObjectEnumerator: PGSQLResultRowEnumerator
@end

@implementation PGSQLResultRow
+ (instancetype)pg_rowWithResult: (PGSQLResult *)result row: (int)row
{
	return [[[self alloc] pg_initWithResult: result row: row] autorelease];
}

- (instancetype)pg_initWithResult: (PGSQLResult *)result row: (int)row
{
	self = [super init];

	_result = [result retain];
	_res = result.pg_result;
	_row = row;

111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

	return convertType(_res, column,
	    [OFString stringWithUTF8String: PQgetvalue(_res, _row, column)]);
}

- (OFEnumerator *)keyEnumerator
{
	return [[[PGResultRowKeyEnumerator alloc]
	    initWithResult: _result
		       row: _row] autorelease];
}

- (OFEnumerator *)objectEnumerator
{
	return [[[PGResultRowObjectEnumerator alloc]
	    initWithResult: _result
		       row: _row] autorelease];
}

- (int)countByEnumeratingWithState: (OFFastEnumerationState *)state
			   objects: (id *)objects
			     count: (int)count







|






|







111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

	return convertType(_res, column,
	    [OFString stringWithUTF8String: PQgetvalue(_res, _row, column)]);
}

- (OFEnumerator *)keyEnumerator
{
	return [[[PGSQLResultRowKeyEnumerator alloc]
	    initWithResult: _result
		       row: _row] autorelease];
}

- (OFEnumerator *)objectEnumerator
{
	return [[[PGSQLResultRowObjectEnumerator alloc]
	    initWithResult: _result
		       row: _row] autorelease];
}

- (int)countByEnumeratingWithState: (OFFastEnumerationState *)state
			   objects: (id *)objects
			     count: (int)count
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
	state->itemsPtr = objects;
	state->mutationsPtr = (unsigned long *)self;

	return j;
}
@end

@implementation PGResultRowEnumerator
- (instancetype)initWithResult: (PGResult *)result row: (int)row
{
	self = [super init];

	_result = [result retain];
	_res = result.pg_result;
	_row = row;
	_count = PQnfields(_res);







|
|







156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
	state->itemsPtr = objects;
	state->mutationsPtr = (unsigned long *)self;

	return j;
}
@end

@implementation PGSQLResultRowEnumerator
- (instancetype)initWithResult: (PGSQLResult *)result row: (int)row
{
	self = [super init];

	_result = [result retain];
	_res = result.pg_result;
	_row = row;
	_count = PQnfields(_res);
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

- (void)reset
{
	_pos = 0;
}
@end

@implementation PGResultRowKeyEnumerator
- (id)nextObject
{
	if (_pos >= _count)
		return nil;

	while (_pos < _count && PQgetisnull(_res, _row, _pos))
		_pos++;

	if (_pos >= _count)
		return nil;

	return [OFString stringWithUTF8String: PQfname(_res, _pos++)];
}
@end

@implementation PGResultRowObjectEnumerator
- (id)nextObject
{
	id object;

	if (_pos >= _count)
		return nil;








|















|







182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

- (void)reset
{
	_pos = 0;
}
@end

@implementation PGSQLResultRowKeyEnumerator
- (id)nextObject
{
	if (_pos >= _count)
		return nil;

	while (_pos < _count && PQgetisnull(_res, _row, _pos))
		_pos++;

	if (_pos >= _count)
		return nil;

	return [OFString stringWithUTF8String: PQfname(_res, _pos++)];
}
@end

@implementation PGSQLResultRowObjectEnumerator
- (id)nextObject
{
	id object;

	if (_pos >= _count)
		return nil;

Name change from src/exceptions/PGConnectionFailedException.h to src/exceptions/PGSQLConnectionFailedException.h.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGException.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class PGConnectionFailedException PGConnectionFailedException.h
 *	  PgSQL/PgSQL.h
 *
 * @brief An exception indicating that connecting to the database failed.
 */
@interface PGConnectionFailedException: PGException
@end

OF_ASSUME_NONNULL_END







|




|




|



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGSQLException.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class PGSQLConnectionFailedException PGSQLConnectionFailedException.h
 *	  PgSQL/PgSQL.h
 *
 * @brief An exception indicating that connecting to the database failed.
 */
@interface PGSQLConnectionFailedException: PGSQLException
@end

OF_ASSUME_NONNULL_END

Name change from src/exceptions/PGConnectionFailedException.m to src/exceptions/PGSQLConnectionFailedException.m.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGConnectionFailedException.h"

@implementation PGConnectionFailedException
- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"Establishing a PostgreSQL connection failed:\n%@\n"
	    "Parameters: %@", _errorMessage, [_connection parameters]];
}
@end







|

|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGSQLConnectionFailedException.h"

@implementation PGSQLConnectionFailedException
- (OFString *)description
{
	return [OFString stringWithFormat:
	    @"Establishing a PostgreSQL connection failed:\n%@\n"
	    "Parameters: %@", _errorMessage, [_connection parameters]];
}
@end

Name change from src/exceptions/PGException.h to src/exceptions/PGSQLException.h.

14
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
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import <ObjFW/ObjFW.h>

#import "PGConnection.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class PGException PGException.h ObjPgSQL/ObjPgSQL.h
 *
 * @brief A PostgreSQL exception.
 */
@interface PGException: OFException
{
	PGConnection *_connection;
	OFString *_errorMessage;
}

/**
 * @brief The connection for which the exception occurred.
 */
@property (readonly, nonatomic) PGConnection *connection;

/**
 * @brief An error message for the exception.
 */
@property (readonly, nonatomic) OFString *errorMessage;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new PostgreSQL exception.
 *
 * @param connection The connection for which the exception occurred
 * @return A new, autoreleased PostgreSQL exception
 */
+ (instancetype)exceptionWithConnection: (PGConnection *)connection;

- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated PostgreSQL exception.
 *
 * @param connection The connection for which the exception occurred
 * @return An initialized PostgreSQL exception
 */
- (instancetype)initWithConnection: (PGConnection *)connection
    OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END







|




|



|

|






|














|









|




14
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
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import <ObjFW/ObjFW.h>

#import "PGSQLConnection.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class PGSQLException PGSQLException.h ObjPgSQL/ObjPgSQL.h
 *
 * @brief A PostgreSQL exception.
 */
@interface PGSQLException: OFException
{
	PGSQLConnection *_connection;
	OFString *_errorMessage;
}

/**
 * @brief The connection for which the exception occurred.
 */
@property (readonly, nonatomic) PGSQLConnection *connection;

/**
 * @brief An error message for the exception.
 */
@property (readonly, nonatomic) OFString *errorMessage;

+ (instancetype)exception OF_UNAVAILABLE;

/**
 * @brief Creates a new PostgreSQL exception.
 *
 * @param connection The connection for which the exception occurred
 * @return A new, autoreleased PostgreSQL exception
 */
+ (instancetype)exceptionWithConnection: (PGSQLConnection *)connection;

- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated PostgreSQL exception.
 *
 * @param connection The connection for which the exception occurred
 * @return An initialized PostgreSQL exception
 */
- (instancetype)initWithConnection: (PGSQLConnection *)connection
    OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Name change from src/exceptions/PGException.m to src/exceptions/PGSQLException.m.

12
13
14
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
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGException.h"
#import "PGConnection+Private.h"

@implementation PGException
@synthesize connection = _connection, errorMessage = _errorMessage;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithConnection: (PGConnection *)connection
{
	return [[[self alloc] initWithConnection: connection] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithConnection: (PGConnection *)connection
{
	self = [super init];

	@try {
		_connection = [connection retain];
		_errorMessage = [[OFString alloc]
		    initWithCString: PQerrorMessage([_connection pg_connection])







|
|

|







|









|







12
13
14
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
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGSQLException.h"
#import "PGSQLConnection+Private.h"

@implementation PGSQLException
@synthesize connection = _connection, errorMessage = _errorMessage;

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithConnection: (PGSQLConnection *)connection
{
	return [[[self alloc] initWithConnection: connection] autorelease];
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithConnection: (PGSQLConnection *)connection
{
	self = [super init];

	@try {
		_connection = [connection retain];
		_errorMessage = [[OFString alloc]
		    initWithCString: PQerrorMessage([_connection pg_connection])

Name change from src/exceptions/PGExecuteCommandFailedException.h to src/exceptions/PGSQLExecuteCommandFailedException.h.

12
13
14
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
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGException.h"

OF_ASSUME_NONNULL_BEGIN

/**

 * @class PGExecuteCommandFailedException PGExecuteCommandFailedException.h
 *	  ObjPgSQL/ObjPgSQL.h
 *
 * @brief An exception indicating that executing a command failed.
 */
@interface PGExecuteCommandFailedException: PGException
{
	OFConstantString *_command;
}

/**
 * @brief The command that could not be executed.
 */
@property (readonly, nonatomic) OFConstantString *command;

+ (instancetype)exceptionWithConnection: (PGConnection *)connection
    OF_UNAVAILABLE;

/**
 * @brief Creates a new execte command failed exception.
 *
 * @param connection The connection for which the command could not be executed
 * @param command The command which could not be executed
 * @return A new, autoreleased execute command failed exception
 */
+ (instancetype)exceptionWithConnection: (PGConnection *)connection
				command: (OFConstantString *)command;

- (instancetype)initWithConnection: (PGConnection *)connection OF_UNAVAILABLE;


/**
 * @brief Initializes an already allocated execte command failed exception.
 *
 * @param connection The connection for which the command could not be executed
 * @param command The command which could not be executed
 * @return An initialized execute command failed exception
 */
- (instancetype)initWithConnection: (PGConnection *)connection
			   command: (OFConstantString *)command
    OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END







|




>
|




|









|









|


|
>








|





12
13
14
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
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGSQLException.h"

OF_ASSUME_NONNULL_BEGIN

/**
 * @class PGSQLExecuteCommandFailedException
 *	  PGSQLExecuteCommandFailedException.h
 *	  ObjPgSQL/ObjPgSQL.h
 *
 * @brief An exception indicating that executing a command failed.
 */
@interface PGSQLExecuteCommandFailedException: PGSQLException
{
	OFConstantString *_command;
}

/**
 * @brief The command that could not be executed.
 */
@property (readonly, nonatomic) OFConstantString *command;

+ (instancetype)exceptionWithConnection: (PGSQLConnection *)connection
    OF_UNAVAILABLE;

/**
 * @brief Creates a new execte command failed exception.
 *
 * @param connection The connection for which the command could not be executed
 * @param command The command which could not be executed
 * @return A new, autoreleased execute command failed exception
 */
+ (instancetype)exceptionWithConnection: (PGSQLConnection *)connection
				command: (OFConstantString *)command;

- (instancetype)initWithConnection: (PGSQLConnection *)connection
    OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated execte command failed exception.
 *
 * @param connection The connection for which the command could not be executed
 * @param command The command which could not be executed
 * @return An initialized execute command failed exception
 */
- (instancetype)initWithConnection: (PGSQLConnection *)connection
			   command: (OFConstantString *)command
    OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Name change from src/exceptions/PGExecuteCommandFailedException.m to src/exceptions/PGSQLExecuteCommandFailedException.m.

12
13
14
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
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGExecuteCommandFailedException.h"

@implementation PGExecuteCommandFailedException
@synthesize command = _command;

+ (instancetype)exceptionWithConnection: (PGConnection *)connection
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithConnection: (PGConnection *)connection
				command: (OFConstantString *)command
{
	return [[[self alloc] initWithConnection: connection
					 command: command] autorelease];
}

- (instancetype)initWithConnection: (PGConnection *)connection
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithConnection: (PGConnection *)connection
			   command: (OFConstantString *)command
{
	self = [super initWithConnection: connection];

	@try {
		_command = [command copy];
	} @catch (id e) {







|

|


|




|






|




|







12
13
14
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
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import "PGSQLExecuteCommandFailedException.h"

@implementation PGSQLExecuteCommandFailedException
@synthesize command = _command;

+ (instancetype)exceptionWithConnection: (PGSQLConnection *)connection
{
	OF_UNRECOGNIZED_SELECTOR
}

+ (instancetype)exceptionWithConnection: (PGSQLConnection *)connection
				command: (OFConstantString *)command
{
	return [[[self alloc] initWithConnection: connection
					 command: command] autorelease];
}

- (instancetype)initWithConnection: (PGSQLConnection *)connection
{
	OF_INVALID_INIT_METHOD
}

- (instancetype)initWithConnection: (PGSQLConnection *)connection
			   command: (OFConstantString *)command
{
	self = [super initWithConnection: connection];

	@try {
		_command = [command copy];
	} @catch (id e) {

Changes to src/exceptions/meson.build.

1
2
3
4
5
exceptions_sources = files(
  'PGConnectionFailedException.m',
  'PGException.m',
  'PGExecuteCommandFailedException.m',
)

|
|
|

1
2
3
4
5
exceptions_sources = files(
  'PGSQLConnectionFailedException.m',
  'PGSQLException.m',
  'PGSQLExecuteCommandFailedException.m',
)

Changes to src/meson.build.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
fs = import('fs')

subdir('exceptions')

sources = files(
  'PGConnection.m',
  'PGResult.m',
  'PGResultRow.m',
)

objpgsql = library('objpgsql',
  sources + exceptions_sources,
  include_directories: incdir,
  dependencies: [objfw_dep, libpq_dep],
  soversion: '0.0',





|
|
|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
fs = import('fs')

subdir('exceptions')

sources = files(
  'PGSQLConnection.m',
  'PGSQLResult.m',
  'PGSQLResultRow.m',
)

objpgsql = library('objpgsql',
  sources + exceptions_sources,
  include_directories: incdir,
  dependencies: [objfw_dep, libpq_dep],
  soversion: '0.0',

Changes to tests/Tests.m.

14
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
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import <ObjFW/ObjFW.h>

#import "PGConnection.h"
#import "PGConnectionFailedException.h"

@interface Test: OFObject <OFApplicationDelegate>
{
	PGConnection *_connection;
}
@end

OF_APPLICATION_DELEGATE(Test)

@implementation Test
- (void)applicationDidFinishLaunching: (OFNotification *)notification
{
	OFString *username =
	    [[OFApplication environment] objectForKey: @"USER"];
	PGResult *result;

	_connection = [[PGConnection alloc] init];
	[_connection setParameters:
	    [OFDictionary dictionaryWithKeysAndObjects: @"user", username,
							@"dbname", username,
							nil]];
	[_connection connect];

	[_connection executeCommand: @"DROP TABLE IF EXISTS test"];







|
<



|










|

|







14
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
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#import <ObjFW/ObjFW.h>

#import "ObjPgSQL.h"


@interface Test: OFObject <OFApplicationDelegate>
{
	PGSQLConnection *_connection;
}
@end

OF_APPLICATION_DELEGATE(Test)

@implementation Test
- (void)applicationDidFinishLaunching: (OFNotification *)notification
{
	OFString *username =
	    [[OFApplication environment] objectForKey: @"USER"];
	PGSQLResult *result;

	_connection = [[PGSQLConnection alloc] init];
	[_connection setParameters:
	    [OFDictionary dictionaryWithKeysAndObjects: @"user", username,
							@"dbname", username,
							nil]];
	[_connection connect];

	[_connection executeCommand: @"DROP TABLE IF EXISTS test"];