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

Commitb27af0d

Browse files
committed
From: "Dr. Michael Meskes" <meskes@online-club.de>My first try at libpq. This one enables the two styles we agreed upon fordatabase descriptors.
1 parentdb921be commitb27af0d

File tree

1 file changed

+102
-1
lines changed

1 file changed

+102
-1
lines changed

‎src/interfaces/libpq/fe-connect.c

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.71 1998/07/03 04:29:04 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.72 1998/07/07 18:00:09 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -393,6 +393,101 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, cons
393393
}
394394

395395

396+
/*
397+
* update_db_info -
398+
* get all additional infos out of dbName
399+
*
400+
*/
401+
staticint
402+
update_db_info(PGconn*conn)
403+
{
404+
char*tmp,*old=conn->dbName;
405+
406+
if (strchr(conn->dbName,'@')!=NULL)
407+
{
408+
/* old style: dbname[@server][:port] */
409+
tmp=strrchr(conn->dbName,':');
410+
if (tmp!=NULL)/* port number given */
411+
{
412+
conn->pgport=strdup(tmp+1);
413+
*tmp='\0';
414+
}
415+
416+
tmp=strrchr(conn->dbName,'@');
417+
if (tmp!=NULL)/* host name given */
418+
{
419+
conn->pghost=strdup(tmp+1);
420+
*tmp='\0';
421+
}
422+
423+
conn->dbName=strdup(old);
424+
free(old);
425+
}
426+
else
427+
{
428+
intoffset;
429+
430+
/*
431+
* only allow protocols tcp and unix
432+
*/
433+
if (strncmp(conn->dbName,"tcp:",4)==0)
434+
offset=4;
435+
elseif (strncmp(conn->dbName,"unix:",5)==0)
436+
offset=5;
437+
elsereturn0;
438+
439+
if (strncmp(conn->dbName+offset,"postgresql://",strlen("postgresql://"))==0)
440+
{
441+
/* new style: <tcp|unix>:postgresql://server[:port][/dbname][?options] */
442+
offset+=strlen("postgresql://");
443+
444+
tmp=strrchr(conn->dbName+offset,'?');
445+
if (tmp!=NULL)/* options given */
446+
{
447+
conn->pgoptions=strdup(tmp+1);
448+
*tmp='\0';
449+
}
450+
451+
tmp=strrchr(conn->dbName+offset,'/');
452+
if (tmp!=NULL)/* database name given */
453+
{
454+
conn->dbName=strdup(tmp+1);
455+
*tmp='\0';
456+
}
457+
else
458+
{
459+
if ((tmp=getenv("PGDATABASE"))!=NULL)
460+
conn->dbName=strdup(tmp);
461+
elseif (conn->pguser)
462+
conn->dbName=strdup(conn->pguser);
463+
}
464+
465+
tmp=strrchr(old+offset,':');
466+
if (tmp!=NULL)/* port number given */
467+
{
468+
conn->pgport=strdup(tmp+1);
469+
*tmp='\0';
470+
}
471+
472+
if (strncmp(old,"unix:",5)==0)
473+
{
474+
conn->pghost=NULL;
475+
if (strcmp(old+offset,"localhost")!=0)
476+
{
477+
(void)sprintf(conn->errorMessage,
478+
"connectDB() -- non-tcp access only possible on localhost\n");
479+
return1;
480+
}
481+
}
482+
elseconn->pghost=strdup(old+offset);
483+
484+
free(old);
485+
}
486+
}
487+
488+
return0;
489+
}
490+
396491
/*
397492
* connectDB -
398493
* make a connection to the backend so it is ready to receive queries.
@@ -414,6 +509,12 @@ connectDB(PGconn *conn)
414509
charberesp;
415510
inton=1;
416511

512+
/*
513+
* parse dbName to get all additional info in it, if any
514+
*/
515+
if (update_db_info(conn)!=0)
516+
gotoconnect_errReturn;
517+
417518
/*
418519
* Initialize the startup packet.
419520
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp