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 on 2024-08-11 18:00:52
Other Links: manifest | tags
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

Modified Doxyfile from [d63473eed3] to [0f2e505861].

9
10
11
12
13
14
15
16

17
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
IGNORE_PREFIX = PGSQL
EXTRACT_STATIC = yes

Modified src/ObjPgSQL.h from [b8af5df6b9] to [c4c0222ebd].

12
13
14
15
16
17
18
19
20
21



22
23
24
25



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

Renamed and modified src/PGConnection+Private.h [0e21f3b90a] to src/PGSQLConnection+Private.h [9702597a7d].

12
13
14
15
16
17
18
19

20
21
22
23

24
25
26
27
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"
#import "PGSQLConnection.h"

OF_ASSUME_NONNULL_BEGIN

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

OF_ASSUME_NONNULL_END

Renamed and modified src/PGConnection.h [4e80eb06d8] to src/PGSQLConnection.h [a79bf6e7f3].

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
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"
#import "PGSQLResult.h"

OF_ASSUME_NONNULL_BEGIN

/** @file */

/**
 * @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;
}

/**
 * @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
 * @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 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.
 *
 * @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

Renamed and modified src/PGConnection.m [5e7a8f6854] to src/PGSQLConnection.m [40b1a4989d].

12
13
14
15
16
17
18
19
20
21
22




23
24
25


26
27

28
29
30
31
32
33
34
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 "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
{
	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
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
		@throw [PGSQLConnectionFailedException
		    exceptionWithConnection: self];

	objc_autoreleasePoolPop(pool);
}

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

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

	_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;
	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
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];
		return [PGSQLResult pg_resultWithResult: result];
	case PGRES_COMMAND_OK:
		PQclear(result);
		return nil;
	default:
		PQclear(result);
		@throw [PGExecuteCommandFailedException
		@throw [PGSQLExecuteCommandFailedException
		    exceptionWithConnection: self
				    command: command];
	}
}
@end

Renamed and modified src/PGResult+Private.h [c69e339278] to src/PGSQLResult+Private.h [d2e2dec6a6].

12
13
14
15
16
17
18
19

20
21
22
23

24
25
26
27
28
29
30
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"
#import "PGSQLResult.h"

OF_ASSUME_NONNULL_BEGIN

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

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

OF_ASSUME_NONNULL_END

Renamed and modified src/PGResult.h [2046b4f6dd] to src/PGSQLResult.h [62553c259f].

18
19
20
21
22
23
24
25

26
27
28

29
30
31
32
33
34
35

36
37
38
39
40
41
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 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;
}
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/PGResult.m [6f8b3390f2] to src/PGSQLResult.m [dd60e56bcb].

12
13
14
15
16
17
18
19
20
21
22




23
24

25
26
27
28
29
30
31
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"
#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
{
	return [[[self alloc] pg_initWithResult: result] autorelease];
}

52
53
54
55
56
57
58
59

60
61
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];
	return [PGSQLResultRow pg_rowWithResult: self row: (int)index];
}
@end

Renamed and modified src/PGResultRow+Private.h [4b3ecb6d0a] to src/PGSQLResultRow+Private.h [06b5a69ed1].

12
13
14
15
16
17
18
19

20
21
22
23
24
25



26
27
28
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"
#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

Renamed and modified src/PGResultRow.h [1a14dcc36a] to src/PGSQLResultRow.h [cf19613225].

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
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"
#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;
}
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/PGResultRow.m [942a6e30f4] to src/PGSQLResultRow.m [459d0b869b].

12
13
14
15
16
17
18
19
20


21
22
23
24
25
26
27
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"
#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
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
@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];

	_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
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]
	return [[[PGSQLResultRowKeyEnumerator alloc]
	    initWithResult: _result
		       row: _row] autorelease];
}

- (OFEnumerator *)objectEnumerator
{
	return [[[PGResultRowObjectEnumerator alloc]
	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
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
@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
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
@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 PGResultRowObjectEnumerator
@implementation PGSQLResultRowObjectEnumerator
- (id)nextObject
{
	id object;

	if (_pos >= _count)
		return nil;

Renamed and modified src/exceptions/PGConnectionFailedException.h [1a9ea18919] to src/exceptions/PGSQLConnectionFailedException.h [92ce2ef6dd].

12
13
14
15
16
17
18
19

20
21
22
23
24

25
26
27
28
29

30
31
32
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"
#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

Renamed and modified src/exceptions/PGConnectionFailedException.m [eaac13221d] to src/exceptions/PGSQLConnectionFailedException.m [41cc2e2ed3].

12
13
14
15
16
17
18
19

20
21

22
23
24
25
26
27
28
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"
#import "PGSQLConnectionFailedException.h"

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

Renamed and modified src/exceptions/PGException.h [6863b5251d] to src/exceptions/PGSQLException.h [84e9f655dc].

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
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"
#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.
 */
@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)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: (PGConnection *)connection
- (instancetype)initWithConnection: (PGSQLConnection *)connection
    OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/exceptions/PGException.m [abab265e43] to src/exceptions/PGSQLException.m [17f11a3e00].

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

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

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

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

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

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

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

Renamed and modified src/exceptions/PGExecuteCommandFailedException.h [675f91afaf] to src/exceptions/PGSQLExecuteCommandFailedException.h [7a760a9f51].

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
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 "PGException.h"
#import "PGSQLException.h"

OF_ASSUME_NONNULL_BEGIN

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

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

+ (instancetype)exceptionWithConnection: (PGConnection *)connection
+ (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: (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.
 *
 * @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
- (instancetype)initWithConnection: (PGSQLConnection *)connection
			   command: (OFConstantString *)command
    OF_DESIGNATED_INITIALIZER;
@end

OF_ASSUME_NONNULL_END

Renamed and modified src/exceptions/PGExecuteCommandFailedException.m [f4ea4c984b] to src/exceptions/PGSQLExecuteCommandFailedException.m [0f00327522].

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
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"
#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];

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

Modified src/exceptions/meson.build from [674dc69ba9] to [ae614258d9].

1
2
3
4



5
1



2
3
4
5

-
-
-
+
+
+

exceptions_sources = files(
  'PGConnectionFailedException.m',
  'PGException.m',
  'PGExecuteCommandFailedException.m',
  'PGSQLConnectionFailedException.m',
  'PGSQLException.m',
  'PGSQLExecuteCommandFailedException.m',
)

Modified src/meson.build from [8256687f74] to [c0c95e2704].

1
2
3
4
5
6
7
8



9
10
11
12
13
14
15
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',
  'PGSQLConnection.m',
  'PGSQLResult.m',
  'PGSQLResultRow.m',
)

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

Modified tests/Tests.m from [be5bedb02c] to [4eb664efe8].

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
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 "PGConnection.h"
#import "ObjPgSQL.h"
#import "PGConnectionFailedException.h"

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

OF_APPLICATION_DELEGATE(Test)

@implementation Test
- (void)applicationDidFinishLaunching: (OFNotification *)notification
{
	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,
							nil]];
	[_connection connect];

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