Skip to content

Commit ced08a4

Browse files
committed
Tidied and added some logging capability
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/sqlclient/trunk@19252 72102866-910b-0410-8b05-ffd578937521
1 parent f62f928 commit ced08a4

File tree

10 files changed

+223
-115
lines changed

10 files changed

+223
-115
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Fri May 07 09:15:00 2004 Richard Frith-Macdonald <[email protected]>
2+
3+
Add methods to log duration of any statements over a certain
4+
limit.
5+
Tidy instance variables ... prefix mprivate ones with underscore.
6+
17
Thu Apr 29 15:20:00 2004 Richard Frith-Macdonald <[email protected]>
28

39
* SQLClient.h: Fix URLs in documentation as suggested by Adam.

ECPG.pgm

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ static NSDate *future = nil;
142142
{
143143
if (connected == NO)
144144
{
145-
if (database != nil && user != nil && password != nil)
145+
if ([self database] != nil
146+
&& [self user] != nil
147+
&& [self password] != nil)
146148
{
147149
Class c = NSClassFromString(@"CmdClient");
148150

@@ -157,10 +159,10 @@ static NSDate *future = nil;
157159
const char *client_c;
158160
EXEC SQL END DECLARE SECTION;
159161

160-
database_c = [database UTF8String];
161-
user_c = [user UTF8String];
162-
password_c = [password UTF8String];
163-
client_c = [client UTF8String];
162+
database_c = [[self database] UTF8String];
163+
user_c = [[self user] UTF8String];
164+
password_c = [[self password] UTF8String];
165+
client_c = [[self clientName] UTF8String];
164166

165167
if (c != 0)
166168
{
@@ -216,27 +218,27 @@ static NSDate *future = nil;
216218
const char *client_c;
217219
EXEC SQL END DECLARE SECTION;
218220

219-
if (inTransaction == YES)
221+
if ([self isInTransaction] == YES)
220222
{
221223
[self rollback];
222224
}
223225

224-
client_c = [client UTF8String];
226+
client_c = [[self clientName] UTF8String];
225227

226228
if ([self debugging] > 0)
227229
{
228-
[self debug: @"Disconnecting client %@", client];
230+
[self debug: @"Disconnecting client %@", [self clientName]];
229231
}
230232
EXEC SQL DISCONNECT :client_c;
231233
if ([self debugging] > 0)
232234
{
233-
[self debug: @"Disconnected client %@", client];
235+
[self debug: @"Disconnected client %@", [self clientName]];
234236
}
235237
}
236238
NS_HANDLER
237239
{
238240
[self debug: @"Error disconnecting from database (%@): %@",
239-
client, localException];
241+
[self clientName], localException];
240242
}
241243
NS_ENDHANDLER
242244
connected = NO;
@@ -407,7 +409,7 @@ static unsigned int trim(char *str)
407409
{
408410
EXEC SQL ALLOCATE DESCRIPTOR myDesc;
409411
EXEC SQL PREPARE myQuery from :query;
410-
if (inTransaction == NO)
412+
if ([self isInTransaction] == NO)
411413
{
412414
EXEC SQL AT :handle BEGIN;
413415
localTransaction = YES;

MySQL.m

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ - (BOOL) backendConnect
7171
{
7272
if (connected == NO)
7373
{
74-
if (database != nil && user != nil && password != nil)
74+
if ([self database] != nil
75+
&& [self user] != nil
76+
&& [self password] != nil)
7577
{
7678
NSString *host = nil;
7779
NSString *port = nil;
78-
NSString *dbase = database;
80+
NSString *dbase = [self database];
7981
NSRange r;
8082

8183
[[self class] purgeConnections: nil];
@@ -95,29 +97,29 @@ - (BOOL) backendConnect
9597

9698
if ([self debugging] > 0)
9799
{
98-
[self debug: @"Connect to '%@' as %@", database, [self name]];
100+
[self debug: @"Connect to '%@' as %@", [self database], [self name]];
99101
}
100102
extra = mysql_init(0);
101103
if (mysql_real_connect(connection,
102104
[host UTF8String],
103-
[user UTF8String],
104-
[password UTF8String],
105+
[[self user] UTF8String],
106+
[[self password] UTF8String],
105107
[dbase UTF8String],
106108
[port intValue],
107109
NULL,
108110
0
109111
) == 0)
110112
{
111113
[self debug: @"Error connecting to '%@' (%@) - %s",
112-
[self name], database, mysql_error(connection)];
114+
[self name], [self database], mysql_error(connection)];
113115
mysql_close(connection);
114116
extra = 0;
115117
}
116118
#if 0
117119
else if (mysql_query(connection, "SET CHARACTER SET utf8") != 0)
118120
{
119121
[self debug: @"Error setting utf8 support for '%@' (%@) - %s",
120-
[self name], database, mysql_error(connection)];
122+
[self name], [self database], mysql_error(connection)];
121123
mysql_close(connection);
122124
extra = 0;
123125
}
@@ -148,26 +150,26 @@ - (void) backendDisconnect
148150
{
149151
NS_DURING
150152
{
151-
if (inTransaction == YES)
153+
if ([self isInTransaction] == YES)
152154
{
153155
[self rollback];
154156
}
155157

156158
if ([self debugging] > 0)
157159
{
158-
[self debug: @"Disconnecting client %@", client];
160+
[self debug: @"Disconnecting client %@", [self clientName]];
159161
}
160162
mysql_close(connection);
161163
extra = 0;
162164
if ([self debugging] > 0)
163165
{
164-
[self debug: @"Disconnected client %@", client];
166+
[self debug: @"Disconnected client %@", [self clientName]];
165167
}
166168
}
167169
NS_HANDLER
168170
{
169171
[self debug: @"Error disconnecting from database (%@): %@",
170-
client, localException];
172+
[self clientName], localException];
171173
}
172174
NS_ENDHANDLER
173175
connected = NO;

Oracle.pm

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ void SQLClientOracleErrorHandler()
119119
{
120120
if (connected == NO)
121121
{
122-
if (database != nil && user != nil && password != nil)
122+
if ([self database] != nil
123+
&& [self user] != nil
124+
&& [self password] != nil)
123125
{
124126
Class c = NSClassFromString(@"CmdClient");
125127

@@ -135,16 +137,16 @@ void SQLClientOracleErrorHandler()
135137
EXEC SQL END DECLARE SECTION;
136138

137139
/* Database is the Oracle Net identifier for the database. */
138-
database_c = [database UTF8String];
140+
database_c = [[self database] UTF8String];
139141

140142
/* User and password are used to connect to the database. */
141-
user_c = [user UTF8String];
142-
password_c = [password UTF8String];
143+
user_c = [[self user] UTF8String];
144+
password_c = [[self password] UTF8String];
143145

144146
/* Client is only used to give this connection a name
145147
* and distinguish it from other connections.
146148
*/
147-
client_c = [client UTF8String];
149+
client_c = [[self clientName] UTF8String];
148150

149151
if (c != 0)
150152
{
@@ -187,27 +189,27 @@ void SQLClientOracleErrorHandler()
187189
const char *client_c;
188190
EXEC SQL END DECLARE SECTION;
189191

190-
if (inTransaction == YES)
192+
if ([self isInTransaction] == YES)
191193
{
192194
[self rollback];
193195
}
194196

195-
client_c = [client UTF8String];
197+
client_c = [[self clientName] UTF8String];
196198

197-
[self debug: @"(Oracle) Disconnecting client %@", client];
199+
[self debug: @"(Oracle) Disconnecting client %@", [self clientName]];
198200

199201
/* To disconnect from the database, we issuse a COMMIT
200202
* statement with the RELEASE option. The RELEASE option
201203
* causes it to disconnect after the COMMIT.
202204
*/
203205
EXEC SQL AT :client_c COMMIT WORK RELEASE;
204206

205-
[self debug: @"(Oracle) Disconnected client %@", client];
207+
[self debug: @"(Oracle) Disconnected client %@", [self clientName]];
206208
}
207209
NS_HANDLER
208210
{
209211
[self error: @"(Oracle) Error disconnecting from database (%@): %@",
210-
client, localException];
212+
[self clientName], localException];
211213
}
212214
NS_ENDHANDLER
213215
connected = NO;
@@ -246,7 +248,7 @@ void SQLClientOracleErrorHandler()
246248

247249
NS_DURING
248250
{
249-
if (inTransaction == NO)
251+
if ([self isInTransaction] == NO)
250252
{
251253
manuallyAutoCommit = YES;
252254
}
@@ -349,7 +351,7 @@ static unsigned int trim(char *str)
349351
CREATE_AUTORELEASE_POOL(arp);
350352
NSMutableArray *records;
351353
BOOL isOpen = NO;
352-
BOOL wasInTransaction = inTransaction;
354+
BOOL wasInTransaction = [self isInTransaction];
353355
BOOL allocatedDescriptor = NO;
354356

355357
length = [stmt length];
@@ -381,10 +383,10 @@ static unsigned int trim(char *str)
381383
allocatedDescriptor = YES;
382384

383385
EXEC SQL AT :handle PREPARE myQuery from :query;
384-
if (inTransaction == NO)
386+
if ([self isInTransaction] == NO)
385387
{
386388
/* EXEC SQL AT :handle BEGIN; */
387-
inTransaction = YES;
389+
_inTransaction = YES;
388390
}
389391
EXEC SQL AT :handle DECLARE myCursor CURSOR FOR myQuery;
390392
EXEC SQL AT :handle OPEN myCursor;
@@ -605,10 +607,10 @@ static unsigned int trim(char *str)
605607

606608
isOpen = NO;
607609
EXEC SQL AT :handle CLOSE myCursor;
608-
if (wasInTransaction == NO && inTransaction == YES)
610+
if (wasInTransaction == NO && [self isInTransaction] == YES)
609611
{
610612
EXEC SQL AT :handle COMMIT;
611-
inTransaction = NO;
613+
_inTransaction = NO;
612614
}
613615
EXEC SQL DEALLOCATE DESCRIPTOR 'myDesc';
614616
allocatedDescriptor = NO;
@@ -626,19 +628,19 @@ static unsigned int trim(char *str)
626628
{
627629
EXEC SQL AT :handle CLOSE myCursor;
628630
}
629-
if (wasInTransaction == NO && inTransaction == YES)
631+
if (wasInTransaction == NO && [self isInTransaction] == YES)
630632
{
631633
EXEC SQL AT :handle ROLLBACK;
632-
inTransaction = NO;
634+
_inTransaction = NO;
633635
}
634636
}
635637
NS_HANDLER
636638
{
637639
NSString *e = [localException name];
638640

639-
if (wasInTransaction == NO && inTransaction == YES)
641+
if (wasInTransaction == NO && [self isInTransaction] == YES)
640642
{
641-
inTransaction = NO;
643+
_inTransaction = NO;
642644
}
643645
if ([e isEqual: SQLConnectionException] == YES)
644646
{
@@ -664,7 +666,7 @@ static unsigned int trim(char *str)
664666

665667
if ([n isEqual: SQLConnectionException] == YES)
666668
{
667-
inTransaction = NO;
669+
_inTransaction = NO;
668670
[self backendDisconnect];
669671
}
670672

Postgres.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ - (BOOL) backendConnect
9090
if (connection == 0)
9191
{
9292
connected = YES;
93-
if (database != nil)
93+
if ([self database] != nil)
9494
{
9595
NSString *host = nil;
9696
NSString *port = nil;
97-
NSString *dbase = database;
97+
NSString *dbase = [self database];
9898
NSString *str;
9999
NSRange r;
100100
NSMutableString *m;
@@ -138,13 +138,13 @@ - (BOOL) backendConnect
138138
[m appendString: @" port="];
139139
[m appendString: str];
140140
}
141-
str = connectQuote(user);
141+
str = connectQuote([self user]);
142142
if (str != nil)
143143
{
144144
[m appendString: @" user="];
145145
[m appendString: str];
146146
}
147-
str = connectQuote(password);
147+
str = connectQuote([self password]);
148148
if (str != nil)
149149
{
150150
[m appendString: @" password="];
@@ -188,26 +188,26 @@ - (void) backendDisconnect
188188
{
189189
NS_DURING
190190
{
191-
if (inTransaction == YES)
191+
if ([self isInTransaction] == YES)
192192
{
193193
[self rollback];
194194
}
195195

196196
if ([self debugging] > 0)
197197
{
198-
[self debug: @"Disconnecting client %@", client];
198+
[self debug: @"Disconnecting client %@", [self clientName]];
199199
}
200200
PQfinish(connection);
201201
extra = 0;
202202
if ([self debugging] > 0)
203203
{
204-
[self debug: @"Disconnected client %@", client];
204+
[self debug: @"Disconnected client %@", [self clientName]];
205205
}
206206
}
207207
NS_HANDLER
208208
{
209209
[self debug: @"Error disconnecting from database (%@): %@",
210-
client, localException];
210+
[self clientName], localException];
211211
}
212212
NS_ENDHANDLER
213213
connected = NO;

0 commit comments

Comments
 (0)