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

Commitf71d0cf

Browse files
committed
Attached is a patch to remove the definitions of libpq's internal
structs from libpq-fe.h, as we previously discussed.There turned out to be sloppy coding practices in more places thanI had realized :-(, but all in all I think it was a well-worth-whileexercise.I ended up adding several routines to libpq's API in order to respondto application requirements that were exposed by this work. I owe thedocs crew updates for libpq.sgml to describe these changes. I'm way tootired to work on the docs tonight, however.This is the last major change I intend to submit for 6.4. I do wantto see if I can make libpgtcl work with Tcl 8.0 before we go final,but hopefully that will be a minor bug fix.
1 parentbcc15f1 commitf71d0cf

File tree

12 files changed

+516
-430
lines changed

12 files changed

+516
-430
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
*
2323
* IDENTIFICATION
24-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.83 1998/09/01 04:33:45 momjian Exp $
24+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.84 1998/09/03 02:10:36 momjian Exp $
2525
*
2626
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2727
*
@@ -255,7 +255,7 @@ dumpClasses_nodumpData(FILE *fout, const char *classname, const bool oids)
255255
copydone= false;
256256
while (!copydone)
257257
{
258-
ret=PQgetline(res->conn,copybuf,COPYBUFSIZ);
258+
ret=PQgetline(g_conn,copybuf,COPYBUFSIZ);
259259

260260
if (copybuf[0]=='\\'&&
261261
copybuf[1]=='.'&&
@@ -281,7 +281,7 @@ dumpClasses_nodumpData(FILE *fout, const char *classname, const bool oids)
281281
}
282282
fprintf(fout,"\\.\n");
283283
}
284-
ret=PQendcopy(res->conn);
284+
ret=PQendcopy(g_conn);
285285
if (ret!=0)
286286
{
287287
fprintf(stderr,"SQL query to dump the contents of Table '%s' "

‎src/bin/psql/psql.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.158 1998/09/01 04:33:51 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.159 1998/09/03 02:10:38 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -148,7 +148,7 @@ struct winsize
148148
/* declarations for functions in this file */
149149
staticvoidusage(char*progname);
150150
staticvoidslashUsage();
151-
staticboolhandleCopyOut(PGresult*res,FILE*copystream);
151+
staticboolhandleCopyOut(PGconn*conn,FILE*copystream);
152152
staticboolhandleCopyIn(PGresult*res,constboolmustprompt,
153153
FILE*copystream);
154154
staticinttableList(PsqlSettings*pset,booldeep_tablelist,
@@ -1125,20 +1125,20 @@ SendQuery(bool *success_p, PsqlSettings *pset, const char *query,
11251125
break;
11261126
casePGRES_COPY_OUT:
11271127
if (copy_out)
1128-
*success_p=handleCopyOut(results,copystream);
1128+
*success_p=handleCopyOut(pset->db,copystream);
11291129
else
11301130
{
11311131
if (!pset->quiet)
11321132
printf("Copy command returns...\n");
11331133

1134-
*success_p=handleCopyOut(results,stdout);
1134+
*success_p=handleCopyOut(pset->db,stdout);
11351135
}
11361136
break;
11371137
casePGRES_COPY_IN:
11381138
if (copy_in)
1139-
*success_p=handleCopyIn(results, false,copystream);
1139+
*success_p=handleCopyIn(pset->db, false,copystream);
11401140
else
1141-
*success_p=handleCopyIn(results,
1141+
*success_p=handleCopyIn(pset->db,
11421142
!pset->quiet&& !pset->notty,
11431143
stdin);
11441144
break;
@@ -1437,11 +1437,8 @@ do_connect(const char *new_dbname,
14371437
else
14381438
userparam=PQuser(olddb);
14391439

1440-
/*
1441-
* libpq doesn't provide an accessor function for the password, so
1442-
* we cheat here.
1443-
*/
1444-
pwparam=olddb->pgpass;
1440+
/* FIXME: if changing user, ought to prompt for a new password? */
1441+
pwparam=PQpass(olddb);
14451442

14461443
pset->db=PQsetdbLogin(PQhost(olddb),PQport(olddb),
14471444
NULL,NULL,dbparam,userparam,pwparam);
@@ -2915,7 +2912,7 @@ main(int argc, char **argv)
29152912
#defineCOPYBUFSIZ8192
29162913

29172914
staticbool
2918-
handleCopyOut(PGresult*res,FILE*copystream)
2915+
handleCopyOut(PGconn*conn,FILE*copystream)
29192916
{
29202917
boolcopydone;
29212918
charcopybuf[COPYBUFSIZ];
@@ -2925,7 +2922,7 @@ handleCopyOut(PGresult *res, FILE *copystream)
29252922

29262923
while (!copydone)
29272924
{
2928-
ret=PQgetline(res->conn,copybuf,COPYBUFSIZ);
2925+
ret=PQgetline(conn,copybuf,COPYBUFSIZ);
29292926

29302927
if (copybuf[0]=='\\'&&
29312928
copybuf[1]=='.'&&
@@ -2950,13 +2947,13 @@ handleCopyOut(PGresult *res, FILE *copystream)
29502947
}
29512948
}
29522949
fflush(copystream);
2953-
return !PQendcopy(res->conn);
2950+
return !PQendcopy(conn);
29542951
}
29552952

29562953

29572954

29582955
staticbool
2959-
handleCopyIn(PGresult*res,constboolmustprompt,FILE*copystream)
2956+
handleCopyIn(PGconn*conn,constboolmustprompt,FILE*copystream)
29602957
{
29612958
boolcopydone= false;
29622959
boolfirstload;
@@ -2991,22 +2988,22 @@ handleCopyIn(PGresult *res, const bool mustprompt, FILE *copystream)
29912988
*s++=c;
29922989
if (c==EOF)
29932990
{
2994-
PQputline(res->conn,"\\.");
2991+
PQputline(conn,"\\.");
29952992
copydone= true;
29962993
break;
29972994
}
29982995
*s='\0';
2999-
PQputline(res->conn,copybuf);
2996+
PQputline(conn,copybuf);
30002997
if (firstload)
30012998
{
30022999
if (!strcmp(copybuf,"\\."))
30033000
copydone= true;
30043001
firstload= false;
30053002
}
30063003
}
3007-
PQputline(res->conn,"\n");
3004+
PQputline(conn,"\n");
30083005
}
3009-
return !PQendcopy(res->conn);
3006+
return !PQendcopy(conn);
30103007
}
30113008

30123009

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -814,11 +814,11 @@ ECPGexecute(struct statement * stmt)
814814
break;
815815
casePGRES_COPY_OUT:
816816
ECPGlog("ECPGexecute line %d: Got PGRES_COPY_OUT ... tossing.\n",stmt->lineno);
817-
PQendcopy(results->conn);
817+
PQendcopy(actual_connection->connection);
818818
break;
819819
casePGRES_COPY_IN:
820820
ECPGlog("ECPGexecute line %d: Got PGRES_COPY_IN ... tossing.\n",stmt->lineno);
821-
PQendcopy(results->conn);
821+
PQendcopy(actual_connection->connection);
822822
break;
823823
default:
824824
ECPGlog("ECPGexecute line %d: Got something else, postgres error.\n",
@@ -995,7 +995,7 @@ ECPGlog(const char *format,...)
995995
if (!f)
996996
return;
997997

998-
sprintf(f,"[%d]: %s",getpid(),format);
998+
sprintf(f,"[%d]: %s",(int)getpid(),format);
999999

10001000
va_start(ap,format);
10011001
vfprintf(debugstream,f,ap);

‎src/interfaces/libpgtcl/pgtclCmds.c

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.31 1998/09/01 04:39:56 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.32 1998/09/03 02:10:42 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -358,15 +358,15 @@ Pg_connect(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
358358
conn=PQsetdb(pghost,pgport,pgoptions,pgtty,dbName);
359359
}
360360

361-
if (conn->status==CONNECTION_OK)
361+
if (PQstatus(conn)==CONNECTION_OK) {
362362
{
363363
PgSetConnectionId(interp,conn);
364364
returnTCL_OK;
365365
}
366366
else
367367
{
368-
Tcl_AppendResult(interp,"Connection to database failed\n",0);
369-
Tcl_AppendResult(interp,conn->errorMessage,0);
368+
Tcl_AppendResult(interp,"Connection to database failed\n",
369+
PQerrorMessage(conn),0);
370370
PQfinish(conn);
371371
returnTCL_ERROR;
372372
}
@@ -423,7 +423,6 @@ Pg_exec(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
423423
Pg_ConnectionId*connid;
424424
PGconn*conn;
425425
PGresult*result;
426-
intconnStatus;
427426

428427
if (argc!=3)
429428
{
@@ -442,7 +441,6 @@ Pg_exec(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
442441
returnTCL_ERROR;
443442
}
444443

445-
connStatus=conn->status;
446444
result=PQexec(conn,argv[2]);
447445

448446
/* Transfer any notify events from libpq to Tcl event queue. */
@@ -452,8 +450,8 @@ Pg_exec(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
452450
{
453451
intrId=PgSetResultId(interp,argv[1],result);
454452

455-
if (result->resultStatus==PGRES_COPY_IN||
456-
result->resultStatus==PGRES_COPY_OUT)
453+
ExecStatusTyperStat=PQresultStatus(result);
454+
if (rStat==PGRES_COPY_IN||rStat==PGRES_COPY_OUT)
457455
{
458456
connid->res_copyStatus=RES_COPY_INPROGRESS;
459457
connid->res_copy=rId;
@@ -463,7 +461,7 @@ Pg_exec(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
463461
else
464462
{
465463
/* error occurred during the query */
466-
Tcl_SetResult(interp,conn->errorMessage,TCL_VOLATILE);
464+
Tcl_SetResult(interp,PQerrorMessage(conn),TCL_VOLATILE);
467465
returnTCL_ERROR;
468466
}
469467
}
@@ -481,9 +479,12 @@ Pg_exec(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
481479
-conn
482480
the connection that produced the result
483481
-assign arrayName
484-
assign the results to an array
485-
-assignbyidx arrayName
486-
assign the results to an array using the first field as a key
482+
assign the results to an array, using subscripts of the form
483+
(tupno,attributeName)
484+
-assignbyidx arrayName ?appendstr?
485+
assign the results to an array using the first field's value as a key.
486+
All but the first field of each tuple are stored, using subscripts of the form
487+
(field0value,attributeNameappendstr)
487488
-numTuples
488489
the number of tuples in the query
489490
-attributes
@@ -509,6 +510,7 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
509510
inttupno;
510511
char*arrVar;
511512
charnameBuffer[256];
513+
constchar*appendstr;
512514

513515
if (argc<3||argc>5)
514516
{
@@ -564,8 +566,9 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
564566

565567
/*
566568
* this assignment assigns the table of result tuples into a giant
567-
* array with the name given in the argument, the indices of the
568-
* array or (tupno,attrName). Note we expect field names not to
569+
* array with the name given in the argument.
570+
* The indices of the array are of the form (tupno,attrName).
571+
* Note we expect field names not to
569572
* exceed a few dozen characters, so truncating to prevent buffer
570573
* overflow shouldn't be a problem.
571574
*/
@@ -589,28 +592,32 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
589592
}
590593
elseif (strcmp(opt,"-assignbyidx")==0)
591594
{
592-
if (argc!=4)
595+
if (argc!=4&&argc!=5)
593596
{
594-
Tcl_AppendResult(interp,"-assignbyidx optionmust be followed by a variable name",0);
597+
Tcl_AppendResult(interp,"-assignbyidx optionrequires an array name and optionally an append string",0);
595598
returnTCL_ERROR;
596599
}
597600
arrVar=argv[3];
601+
appendstr= (argc==5) ? (constchar*)argv[4] :"";
598602

599603
/*
600604
* this assignment assigns the table of result tuples into a giant
601-
* array with the name given in the argument, the indices of the
602-
* array or (tupno,attrName). Here, we still assume PQfname won't
603-
* exceed 200 characters, but we dare not make the same assumption
604-
* about the data in field 0.
605+
* array with the name given in the argument. The indices of the array
606+
* are of the form (field0Value,attrNameappendstr).
607+
* Here, we still assume PQfname won't exceed 200 characters,
608+
* but we dare not make the same assumption about the data in field 0
609+
* nor the append string.
605610
*/
606611
for (tupno=0;tupno<PQntuples(result);tupno++)
607612
{
608613
constchar*field0=PQgetvalue(result,tupno,0);
609-
char*workspace=malloc(strlen(field0)+210);
614+
char*workspace=malloc(strlen(field0)+strlen(appendstr)+210);
610615

611616
for (i=1;i<PQnfields(result);i++)
612617
{
613-
sprintf(workspace,"%s,%.200s",field0,PQfname(result,i));
618+
sprintf(workspace,"%s,%.200s%s",field0,PQfname(result,i),
619+
appendstr);
620+
sprintf(workspace,"%s,%.200s",field0,PQfname(result,i));
614621
if (Tcl_SetVar2(interp,arrVar,workspace,
615622
PQgetvalue(result,tupno,i),
616623
TCL_LEAVE_ERR_MSG)==NULL)
@@ -701,7 +708,7 @@ Pg_result(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
701708
"\t-status\n",
702709
"\t-conn\n",
703710
"\t-assign arrayVarName\n",
704-
"\t-assignbyidx arrayVarName\n",
711+
"\t-assignbyidx arrayVarName ?appendstr?\n",
705712
"\t-numTuples\n",
706713
"\t-numAttrs\n"
707714
"\t-attributes\n"
@@ -1238,7 +1245,7 @@ Pg_select(ClientData cData, Tcl_Interp * interp, int argc, char **argv)
12381245
if ((result=PQexec(conn,argv[2]))==0)
12391246
{
12401247
/* error occurred during the query */
1241-
Tcl_SetResult(interp,conn->errorMessage,TCL_STATIC);
1248+
Tcl_SetResult(interp,PQerrorMessage(conn),TCL_STATIC);
12421249
returnTCL_ERROR;
12431250
}
12441251

@@ -1406,11 +1413,10 @@ Pg_listen(ClientData cData, Tcl_Interp * interp, int argc, char *argv[])
14061413
ckfree(cmd);
14071414
/* Transfer any notify events from libpq to Tcl event queue. */
14081415
PgNotifyTransferEvents(connid);
1409-
if (!result||(result->resultStatus!=PGRES_COMMAND_OK))
1416+
if (PQresultStatus(result)!=PGRES_COMMAND_OK) {
14101417
{
14111418
/* Error occurred during the execution of command */
1412-
if (result)
1413-
PQclear(result);
1419+
PQclear(result);
14141420
ckfree(callback);
14151421
ckfree(caserelname);
14161422
Tcl_DeleteHashEntry(entry);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp