Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit99a5619

Browse files
author
Michael Meskes
committed
- Enabled single-quoted connection targets.
- Fixed a memory leak/segfault in unsuccessful connection.- Some changes to test files.
1 parent162e8f1 commit99a5619

File tree

11 files changed

+336
-106
lines changed

11 files changed

+336
-106
lines changed

‎src/interfaces/ecpg/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,5 +2121,10 @@ Th 24. Aug 11:53:29 CEST 2006
21212121

21222122
- Fixed of by one variable size.
21232123
- Synced parser.
2124+
2125+
Su 27. Aug 17:54:36 CEST 2006
2126+
2127+
- Enabled single-quoted connection targets.
2128+
- Fixed a memory leak/segfault in unsuccessful connection.
21242129
- Set ecpg library version to 5.2.
21252130
- Set ecpg version to 4.2.1.

‎src/interfaces/ecpg/ecpglib/connect.c

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.33 2006/08/13 10:18:29 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/connect.c,v 1.34 2006/08/27 16:15:41 meskes Exp $ */
22

33
#definePOSTGRES_ECPG_INTERNAL
44
#include"postgres_fe.h"
@@ -316,25 +316,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
316316
if (dbname!=NULL)
317317
{
318318
/* get the detail information out of dbname */
319-
if (strchr(dbname,'@')!=NULL)
320-
{
321-
/* old style: dbname[@server][:port] */
322-
tmp=strrchr(dbname,':');
323-
if (tmp!=NULL)/* port number given */
324-
{
325-
port=ECPGstrdup(tmp+1,lineno);
326-
*tmp='\0';
327-
}
328-
329-
tmp=strrchr(dbname,'@');
330-
if (tmp!=NULL)/* host name given */
331-
{
332-
host=ECPGstrdup(tmp+1,lineno);
333-
*tmp='\0';
334-
}
335-
realname=ECPGstrdup(dbname,lineno);
336-
}
337-
elseif (strncmp(dbname,"tcp:",4)==0||strncmp(dbname,"unix:",5)==0)
319+
if (strncmp(dbname,"tcp:",4)==0||strncmp(dbname,"unix:",5)==0)
338320
{
339321
intoffset=0;
340322

@@ -396,6 +378,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
396378
ECPGfree(realname);
397379
if (dbname)
398380
ECPGfree(dbname);
381+
free(this);
399382
return false;
400383
}
401384
}
@@ -419,19 +402,33 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
419402
ECPGfree(realname);
420403
if (dbname)
421404
ECPGfree(dbname);
422-
ecpg_finish(this);
405+
free(this);
423406
return false;
424407
}
425408
}
426409
else
427410
host=ECPGstrdup(dbname+offset,lineno);
428411

429412
}
430-
else
431-
realname=ECPGstrdup(dbname,lineno);
432413
}
433414
else
415+
{
416+
/* old style: dbname[@server][:port] */
417+
tmp=strrchr(dbname,':');
418+
if (tmp!=NULL)/* port number given */
419+
{
420+
port=ECPGstrdup(tmp+1,lineno);
421+
*tmp='\0';
422+
}
423+
424+
tmp=strrchr(dbname,'@');
425+
if (tmp!=NULL)/* host name given */
426+
{
427+
host=ECPGstrdup(tmp+1,lineno);
428+
*tmp='\0';
429+
}
434430
realname=ECPGstrdup(dbname,lineno);
431+
}
435432
}
436433
else
437434
realname=NULL;

‎src/interfaces/ecpg/preproc/preproc.y

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.332 2006/08/24 12:31:33 meskes Exp $*/
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.333 2006/08/27 16:15:41 meskes Exp $*/
22

33
/* Copyright comment*/
44
%{
@@ -4640,14 +4640,23 @@ connection_target: database_name opt_server opt_port
46404640
if (strncmp($1,"unix", strlen("unix")) ==0 &&
46414641
strncmp($3 + strlen("//"), "localhost", strlen("localhost")) != 0 &&
46424642
strncmp($3 + strlen("//"), "127.0.0.1", strlen("127.0.0.1")) != 0)
4643-
mmerror(PARSE_ERROR, ET_ERROR,"unix domain sockets only work on 'localhost' but not on '%9.9s'", $3 + strlen("//"));
4643+
mmerror(PARSE_ERROR, ET_ERROR,"unix domain sockets only work on 'localhost' but not on '%s'", $3 + strlen("//"));
46444644

46454645
$$ = make3_str(make3_str(make_str("\""),$1, make_str(":")),$3, make3_str(make3_str($4, make_str("/"),$6),$7, make_str("\"")));
46464646
}
46474647
|char_variable
46484648
{
46494649
$$ =$1;
46504650
}
4651+
|Sconst
4652+
{
4653+
/* We can only process double quoted strings not single quotes ones,
4654+
* so we change the quotes.
4655+
* Note, that the rule for Sconst adds these single quotes.*/
4656+
$1[0] ='\"';
4657+
$1[strlen($1)-1] ='\"';
4658+
$$ =$1;
4659+
}
46514660
;
46524661

46534662
db_prefix:identcvariable

‎src/interfaces/ecpg/test/connect/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ test1.pgc: test1.pgc.in
1414
TESTS = test1 test1.c\
1515
test2 test2.c\
1616
test3 test3.c\
17-
test4 test4.c
17+
test4 test4.c\
18+
test5 test5.c
1819

1920
all:$(TESTS)
2021

‎src/interfaces/ecpg/test/connect/test1.pgc.in

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ main(void)
1414
{
1515
exec sql begin declare section;
1616
char db[200];
17-
char id[200];
1817
char pw[200];
1918
exec sql end declare section;
2019

@@ -24,18 +23,13 @@ exec sql end declare section;
2423
exec sql alter user connectuser ENCRYPTED PASSWORD 'connectpw';
2524
exec sql disconnect; /* <-- "main" not specified */
2625

27-
strcpy(db, "connectdb");
28-
strcpy(id, "main");
29-
exec sql connect to :db as :id;
30-
exec sql disconnect :id;
31-
3226
exec sql connect to connectdb@localhost as main;
3327
exec sql disconnect main;
3428

35-
exec sql connect to connectdb@localhost as main;
29+
exec sql connect to connectdb@localhost:@TEMP_PORT@ as main;
3630
exec sql disconnect main;
3731

38-
exec sql connect to connectdb@localhost as main user connectuser/connectdb;
32+
exec sql connect to connectdb:@TEMP_PORT@ as main;
3933
exec sql disconnect main;
4034

4135
exec sql connect to tcp:postgresql://localhost:@TEMP_PORT@/connectdb user connectuser identified by connectpw;
@@ -50,6 +44,9 @@ exec sql end declare section;
5044
exec sql connect to unix:postgresql://localhost:@TEMP_PORT@/connectdb user connectuser using "connectpw";
5145
exec sql disconnect;
5246

47+
exec sql connect to unix:postgresql://localhost:@TEMP_PORT@/connectdb user connectuser;
48+
exec sql disconnect;
49+
5350
/* wrong db */
5451
exec sql connect to tcp:postgresql://localhost:@TEMP_PORT@/nonexistant user connectuser identified by connectpw;
5552
exec sql disconnect;
@@ -62,10 +59,5 @@ exec sql end declare section;
6259
exec sql connect to unix:postgresql://localhost:@TEMP_PORT@/connectdb user connectuser identified by "wrongpw";
6360
/* no disconnect necessary */
6461

65-
/* connect twice */
66-
exec sql connect to connectdb as main;
67-
exec sql connect to connectdb as main;
68-
exec sql disconnect main;
69-
7062
return (0);
7163
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* this file tests all sorts of connecting to one single database.
3+
*/
4+
5+
#include <stdlib.h>
6+
#include <string.h>
7+
#include <stdlib.h>
8+
#include <stdio.h>
9+
10+
/* do not include regression.h */
11+
12+
int
13+
main(void)
14+
{
15+
exec sql begin declare section;
16+
char db[200];
17+
char id[200];
18+
exec sql end declare section;
19+
20+
ECPGdebug(1, stderr);
21+
22+
exec sql connect to connectdb as main;
23+
exec sql alter user connectuser ENCRYPTED PASSWORD 'connectpw';
24+
exec sql disconnect; /* <-- "main" not specified */
25+
26+
strcpy(db, "connectdb");
27+
strcpy(id, "main");
28+
exec sql connect to :db as :id;
29+
exec sql disconnect :id;
30+
31+
exec sql connect to connectdb as main;
32+
exec sql disconnect main;
33+
34+
exec sql connect to "connectdb" as main;
35+
exec sql disconnect main;
36+
37+
exec sql connect to 'connectdb' as main;
38+
exec sql disconnect main;
39+
40+
exec sql connect to connectdb as main user connectuser/connectdb;
41+
exec sql disconnect main;
42+
43+
exec sql connect to unix:postgresql://localhost/connectdb as main user connectuser;
44+
exec sql disconnect main;
45+
46+
exec sql connect to "unix:postgresql://localhost/connectdb" as main user connectuser;
47+
exec sql disconnect main;
48+
49+
exec sql connect to 'unix:postgresql://localhost/connectdb' as main user connectuser;
50+
exec sql disconnect main;
51+
52+
exec sql connect to "unix:postgresql://200.46.204.71/connectdb" as main user connectuser;
53+
exec sql disconnect main;
54+
55+
exec sql disconnect nonexistant;
56+
57+
/* connect twice */
58+
exec sql connect to connectdb as main;
59+
exec sql connect to connectdb as main;
60+
exec sql disconnect main;
61+
62+
return (0);
63+
}

‎src/interfaces/ecpg/test/expected/connect-test1.c

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -27,118 +27,101 @@ main(void)
2727
/* exec sql begin declare section */
2828

2929

30-
3130

3231
#line 16 "test1.pgc"
3332
chardb [200 ] ;
3433

3534
#line 17 "test1.pgc"
36-
charid [200 ] ;
37-
38-
#line 18 "test1.pgc"
3935
charpw [200 ] ;
4036
/* exec sql end declare section */
41-
#line19 "test1.pgc"
37+
#line18 "test1.pgc"
4238

4339

4440
ECPGdebug(1,stderr);
4541

4642
{ECPGconnect(__LINE__,0,"connectdb" ,NULL,NULL ,"main",0); }
47-
#line23 "test1.pgc"
43+
#line22 "test1.pgc"
4844

4945
{ECPGdo(__LINE__,0,1,NULL,"alter user connectuser encrypted password 'connectpw'",ECPGt_EOIT,ECPGt_EORT);}
50-
#line24 "test1.pgc"
46+
#line23 "test1.pgc"
5147

5248
{ECPGdisconnect(__LINE__,"CURRENT");}
53-
#line25 "test1.pgc"
49+
#line24 "test1.pgc"
5450
/* <-- "main" not specified */
5551

56-
strcpy(db,"connectdb");
57-
strcpy(id,"main");
58-
{ECPGconnect(__LINE__,0,db ,NULL,NULL ,id,0); }
59-
#line 29 "test1.pgc"
60-
61-
{ECPGdisconnect(__LINE__,id);}
62-
#line 30 "test1.pgc"
63-
64-
6552
{ECPGconnect(__LINE__,0,"connectdb@localhost" ,NULL,NULL ,"main",0); }
66-
#line32 "test1.pgc"
53+
#line26 "test1.pgc"
6754

6855
{ECPGdisconnect(__LINE__,"main");}
69-
#line33 "test1.pgc"
56+
#line27 "test1.pgc"
7057

7158

72-
{ECPGconnect(__LINE__,0,"connectdb@localhost" ,NULL,NULL ,"main",0); }
73-
#line35 "test1.pgc"
59+
{ECPGconnect(__LINE__,0,"connectdb@localhost:55432" ,NULL,NULL ,"main",0); }
60+
#line29 "test1.pgc"
7461

7562
{ECPGdisconnect(__LINE__,"main");}
76-
#line36 "test1.pgc"
63+
#line30 "test1.pgc"
7764

7865

79-
{ECPGconnect(__LINE__,0,"connectdb@localhost" ,"connectuser" ,"connectdb" ,"main",0); }
80-
#line38 "test1.pgc"
66+
{ECPGconnect(__LINE__,0,"connectdb:55432" ,NULL,NULL ,"main",0); }
67+
#line32 "test1.pgc"
8168

8269
{ECPGdisconnect(__LINE__,"main");}
83-
#line39 "test1.pgc"
70+
#line33 "test1.pgc"
8471

8572

8673
{ECPGconnect(__LINE__,0,"tcp:postgresql://localhost:55432/connectdb" ,"connectuser" ,"connectpw" ,NULL,0); }
87-
#line41 "test1.pgc"
74+
#line35 "test1.pgc"
8875

8976
{ECPGdisconnect(__LINE__,"nonexistant");}
90-
#line42 "test1.pgc"
77+
#line36 "test1.pgc"
9178

9279
{ECPGdisconnect(__LINE__,"CURRENT");}
93-
#line43 "test1.pgc"
80+
#line37 "test1.pgc"
9481

9582

9683
strcpy(pw,"connectpw");
9784
strcpy(db,"tcp:postgresql://localhost:55432/connectdb");
9885
{ECPGconnect(__LINE__,0,db ,"connectuser" ,pw ,NULL,0); }
99-
#line47 "test1.pgc"
86+
#line41 "test1.pgc"
10087

10188
{ECPGdisconnect(__LINE__,"CURRENT");}
102-
#line48 "test1.pgc"
89+
#line42 "test1.pgc"
10390

10491

10592
{ECPGconnect(__LINE__,0,"unix:postgresql://localhost:55432/connectdb" ,"connectuser" ,"connectpw" ,NULL,0); }
106-
#line50 "test1.pgc"
93+
#line44 "test1.pgc"
10794

10895
{ECPGdisconnect(__LINE__,"CURRENT");}
109-
#line 51 "test1.pgc"
96+
#line 45 "test1.pgc"
97+
98+
99+
{ECPGconnect(__LINE__,0,"unix:postgresql://localhost:55432/connectdb" ,"connectuser" ,NULL ,NULL,0); }
100+
#line 47 "test1.pgc"
101+
102+
{ECPGdisconnect(__LINE__,"CURRENT");}
103+
#line 48 "test1.pgc"
110104

111105

112106
/* wrong db */
113107
{ECPGconnect(__LINE__,0,"tcp:postgresql://localhost:55432/nonexistant" ,"connectuser" ,"connectpw" ,NULL,0); }
114-
#line54 "test1.pgc"
108+
#line51 "test1.pgc"
115109

116110
{ECPGdisconnect(__LINE__,"CURRENT");}
117-
#line55 "test1.pgc"
111+
#line52 "test1.pgc"
118112

119113

120114
/* wrong port */
121115
{ECPGconnect(__LINE__,0,"tcp:postgresql://localhost:0/connectdb" ,"connectuser" ,"connectpw" ,NULL,0); }
122-
#line58 "test1.pgc"
116+
#line55 "test1.pgc"
123117

124118
/* no disconnect necessary */
125119

126120
/* wrong password */
127121
{ECPGconnect(__LINE__,0,"unix:postgresql://localhost:55432/connectdb" ,"connectuser" ,"wrongpw" ,NULL,0); }
128-
#line62 "test1.pgc"
122+
#line59 "test1.pgc"
129123

130124
/* no disconnect necessary */
131125

132-
/* connect twice */
133-
{ECPGconnect(__LINE__,0,"connectdb" ,NULL,NULL ,"main",0); }
134-
#line 66 "test1.pgc"
135-
136-
{ECPGconnect(__LINE__,0,"connectdb" ,NULL,NULL ,"main",0); }
137-
#line 67 "test1.pgc"
138-
139-
{ECPGdisconnect(__LINE__,"main");}
140-
#line 68 "test1.pgc"
141-
142-
143126
return (0);
144127
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp