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

Commit9312033

Browse files
committed
Date: Sun, 16 Aug 1998 14:56:48 -0400From: Tom Lane <tgl@sss.pgh.pa.us>Attached is a patch for this weekend's work on libpq. I've dealtwith several issues: <for details: see message, in pgsql-patches archive for above data>
1 parent3fa676a commit9312033

File tree

16 files changed

+373
-363
lines changed

16 files changed

+373
-363
lines changed

‎src/backend/parser/scan.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* A lexical scanner generated by flex */
22

33
/* Scanner skeleton version:
4-
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.22 1998/06/16 07:29:25 momjian Exp $
4+
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.23 1998/08/17 03:50:15 scrappy Exp $
55
*/
66

77
#defineFLEX_SCANNER
@@ -555,7 +555,7 @@ char *yytext;
555555
*
556556
*
557557
* IDENTIFICATION
558-
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.22 1998/06/16 07:29:25 momjian Exp $
558+
* $Header: /cvsroot/pgsql/src/backend/parser/Attic/scan.c,v 1.23 1998/08/17 03:50:15 scrappy Exp $
559559
*
560560
*-------------------------------------------------------------------------
561561
*/

‎src/bin/psql/psql.c

Lines changed: 15 additions & 14 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.153 1998/08/10 20:31:38 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.154 1998/08/17 03:50:17 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -121,8 +121,8 @@ struct winsize
121121
/* declarations for functions in this file */
122122
staticvoidusage(char*progname);
123123
staticvoidslashUsage();
124-
staticvoidhandleCopyOut(PGresult*res,FILE*copystream);
125-
staticvoid
124+
staticboolhandleCopyOut(PGresult*res,FILE*copystream);
125+
staticbool
126126
handleCopyIn(PGresult*res,constboolmustprompt,
127127
FILE*copystream);
128128
staticint
@@ -1103,23 +1103,23 @@ SendQuery(bool *success_p, PsqlSettings *pset, const char *query,
11031103
printf("%s\n",PQcmdStatus(results));
11041104
break;
11051105
casePGRES_COPY_OUT:
1106-
*success_p= true;
11071106
if (copy_out)
1108-
handleCopyOut(results,copystream);
1107+
*success_p=handleCopyOut(results,copystream);
11091108
else
11101109
{
11111110
if (!pset->quiet)
11121111
printf("Copy command returns...\n");
11131112

1114-
handleCopyOut(results,stdout);
1113+
*success_p=handleCopyOut(results,stdout);
11151114
}
11161115
break;
11171116
casePGRES_COPY_IN:
1118-
*success_p= true;
11191117
if (copy_in)
1120-
handleCopyIn(results, false,copystream);
1118+
*success_p=handleCopyIn(results, false,copystream);
11211119
else
1122-
handleCopyIn(results, !pset->quiet&& !pset->notty,stdin);
1120+
*success_p=handleCopyIn(results,
1121+
!pset->quiet&& !pset->notty,
1122+
stdin);
11231123
break;
11241124
casePGRES_NONFATAL_ERROR:
11251125
casePGRES_FATAL_ERROR:
@@ -2646,7 +2646,6 @@ main(int argc, char **argv)
26462646
char*host=NULL;
26472647
char*port=NULL;
26482648
char*qfilename=NULL;
2649-
charerrbuf[ERROR_MSG_LENGTH];
26502649

26512650
PsqlSettingssettings;
26522651

@@ -2692,7 +2691,9 @@ main(int argc, char **argv)
26922691
settings.opt.align=0;
26932692
break;
26942693
case'a':
2694+
#if0/* this no longer does anything */
26952695
fe_setauthsvc(optarg,errbuf);
2696+
#endif
26962697
break;
26972698
case'c':
26982699
singleQuery=strdup(optarg);
@@ -2875,7 +2876,7 @@ main(int argc, char **argv)
28752876

28762877
#defineCOPYBUFSIZ8192
28772878

2878-
staticvoid
2879+
staticbool
28792880
handleCopyOut(PGresult*res,FILE*copystream)
28802881
{
28812882
boolcopydone;
@@ -2911,12 +2912,12 @@ handleCopyOut(PGresult *res, FILE *copystream)
29112912
}
29122913
}
29132914
fflush(copystream);
2914-
PQendcopy(res->conn);
2915+
return !PQendcopy(res->conn);
29152916
}
29162917

29172918

29182919

2919-
staticvoid
2920+
staticbool
29202921
handleCopyIn(PGresult*res,constboolmustprompt,FILE*copystream)
29212922
{
29222923
boolcopydone= false;
@@ -2967,7 +2968,7 @@ handleCopyIn(PGresult *res, const bool mustprompt, FILE *copystream)
29672968
}
29682969
PQputline(res->conn,"\n");
29692970
}
2970-
PQendcopy(res->conn);
2971+
return !PQendcopy(res->conn);
29712972
}
29722973

29732974

‎src/interfaces/Makefile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@
77
#
88
#
99
# IDENTIFICATION
10-
# $Header: /cvsroot/pgsql/src/interfaces/Makefile,v 1.10 1998/05/29 17:00:29 momjian Exp $
10+
# $Header: /cvsroot/pgsql/src/interfaces/Makefile,v 1.11 1998/08/17 03:50:19 scrappy Exp $
1111
#
1212
#-------------------------------------------------------------------------
1313

1414
SRCDIR= ..
1515
include$(SRCDIR)/Makefile.global
1616

17-
.DEFAULTall:
17+
18+
perl-makefile-dep :=
19+
ifeq ($(USE_PERL), true)
20+
perl-makefile-dep := perl5/Makefile
21+
endif
22+
23+
24+
.DEFAULTall:$(perl-makefile-dep)
1825
$(MAKE) -C libpq$@
1926
#$(MAKE) -C ecpg $@
2027
ifeq ($(HAVE_Cplusplus), true)
@@ -26,6 +33,8 @@ ifeq ($(USE_TCL), true)
2633
$(MAKE) -C libpgtcl $@
2734
endif
2835
ifeq ($(USE_PERL), true)
29-
cd perl5 && perl Makefile.PL
3036
$(MAKE) -C perl5 $@
3137
endif
38+
39+
perl5/Makefile: perl5/Makefile.PL
40+
cd perl5&& perl Makefile.PL

‎src/interfaces/libpgtcl/pgtclCmds.c

Lines changed: 51 additions & 47 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.28 1998/07/09 03:32:09 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.29 1998/08/17 03:50:22 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -485,9 +485,8 @@ Pg_result(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
485485
char*opt;
486486
inti;
487487
inttupno;
488-
charprearrayInd[MAX_MESSAGE_LEN];
489-
chararrayInd[MAX_MESSAGE_LEN];
490488
char*arrVar;
489+
charnameBuffer[256];
491490

492491
if (argc<3||argc>5) {
493492
Tcl_AppendResult(interp,"Wrong # of arguments\n",0);
@@ -522,6 +521,10 @@ Pg_result(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
522521
sprintf(interp->result,"%d",PQntuples(result));
523522
returnTCL_OK;
524523
}
524+
elseif (strcmp(opt,"-numAttrs")==0) {
525+
sprintf(interp->result,"%d",PQnfields(result));
526+
returnTCL_OK;
527+
}
525528
elseif (strcmp(opt,"-assign")==0) {
526529
if (argc!=4) {
527530
Tcl_AppendResult(interp,"-assign option must be followed by a variable name",0);
@@ -530,17 +533,21 @@ Pg_result(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
530533
arrVar=argv[3];
531534
/* this assignment assigns the table of result tuples into a giant
532535
array with the name given in the argument,
533-
the indices of the array or (tupno,attrName)*/
536+
the indices of the array or (tupno,attrName).
537+
Note we expect field names not to exceed a few dozen characters,
538+
so truncating to prevent buffer overflow shouldn't be a problem.
539+
*/
534540
for (tupno=0;tupno<PQntuples(result);tupno++) {
535541
for (i=0;i<PQnfields(result);i++) {
536-
sprintf(arrayInd,"%d,%s",tupno,PQfname(result,i));
537-
Tcl_SetVar2(interp,arrVar,arrayInd,
542+
sprintf(nameBuffer,"%d,%.200s",tupno,PQfname(result,i));
543+
if (Tcl_SetVar2(interp,arrVar,nameBuffer,
538544
#ifdefTCL_ARRAYS
539-
tcl_value(PQgetvalue(result,tupno,i)),
545+
tcl_value(PQgetvalue(result,tupno,i)),
540546
#else
541-
PQgetvalue(result,tupno,i),
547+
PQgetvalue(result,tupno,i),
542548
#endif
543-
TCL_LEAVE_ERR_MSG);
549+
TCL_LEAVE_ERR_MSG)==NULL)
550+
returnTCL_ERROR;
544551
}
545552
}
546553
Tcl_AppendResult(interp,arrVar,0);
@@ -554,15 +561,23 @@ Pg_result(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
554561
arrVar=argv[3];
555562
/* this assignment assigns the table of result tuples into a giant
556563
array with the name given in the argument,
557-
the indices of the array or (tupno,attrName)*/
564+
the indices of the array or (tupno,attrName).
565+
Here, we still assume PQfname won't exceed 200 characters,
566+
but we dare not make the same assumption about the data in field 0.
567+
*/
558568
for (tupno=0;tupno<PQntuples(result);tupno++) {
559-
sprintf(prearrayInd,"%s",PQgetvalue(result,tupno,0));
569+
constchar*field0=PQgetvalue(result,tupno,0);
570+
char*workspace=malloc(strlen(field0)+210);
560571
for (i=1;i<PQnfields(result);i++) {
561-
sprintf(arrayInd,"%s,%s",prearrayInd,PQfname(result,i));
562-
Tcl_SetVar2(interp,arrVar,arrayInd,
563-
PQgetvalue(result,tupno,i),
564-
TCL_LEAVE_ERR_MSG);
572+
sprintf(workspace,"%s,%.200s",field0,PQfname(result,i));
573+
if (Tcl_SetVar2(interp,arrVar,workspace,
574+
PQgetvalue(result,tupno,i),
575+
TCL_LEAVE_ERR_MSG)==NULL) {
576+
free(workspace);
577+
returnTCL_ERROR;
578+
}
565579
}
580+
free(workspace);
566581
}
567582
Tcl_AppendResult(interp,arrVar,0);
568583
returnTCL_OK;
@@ -573,25 +588,13 @@ Pg_result(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
573588
returnTCL_ERROR;
574589
}
575590
tupno=atoi(argv[3]);
576-
577-
if (tupno >=PQntuples(result)) {
591+
if (tupno<0||tupno >=PQntuples(result)) {
578592
Tcl_AppendResult(interp,"argument to getTuple cannot exceed number of tuples - 1",0);
579593
returnTCL_ERROR;
580594
}
581-
582-
#ifdefTCL_ARRAYS
583595
for (i=0;i<PQnfields(result);i++) {
584-
Tcl_AppendElement(interp,tcl_value(PQgetvalue(result,tupno,i)));
585-
}
586-
#else
587-
/*Tcl_AppendResult(interp, PQgetvalue(result,tupno,0),NULL); */
588-
Tcl_AppendElement(interp,PQgetvalue(result,tupno,0));
589-
for (i=1;i<PQnfields(result);i++) {
590-
/* Tcl_AppendResult(interp, " ", PQgetvalue(result,tupno,i),NULL);*/
591-
Tcl_AppendElement(interp,PQgetvalue(result,tupno,i));
596+
Tcl_AppendElement(interp,PQgetvalue(result,tupno,i));
592597
}
593-
#endif
594-
595598
returnTCL_OK;
596599
}
597600
elseif (strcmp(opt,"-tupleArray")==0) {
@@ -600,41 +603,42 @@ Pg_result(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
600603
returnTCL_ERROR;
601604
}
602605
tupno=atoi(argv[3]);
603-
604-
if (tupno >=PQntuples(result)) {
606+
if (tupno<0||tupno >=PQntuples(result)) {
605607
Tcl_AppendResult(interp,"argument to tupleArray cannot exceed number of tuples - 1",0);
606608
returnTCL_ERROR;
607609
}
608-
609610
for (i=0;i<PQnfields(result);i++) {
610-
if (Tcl_SetVar2(interp,argv[4],PQfname(result,i),PQgetvalue(result,tupno,i),TCL_LEAVE_ERR_MSG)==NULL) {
611+
if (Tcl_SetVar2(interp,argv[4],PQfname(result,i),
612+
PQgetvalue(result,tupno,i),
613+
TCL_LEAVE_ERR_MSG)==NULL) {
611614
returnTCL_ERROR;
612615
}
613616
}
614617
returnTCL_OK;
615618
}
616619
elseif (strcmp(opt,"-attributes")==0) {
617-
Tcl_AppendResult(interp,PQfname(result,0),NULL);
618-
for (i=1;i<PQnfields(result);i++) {
619-
Tcl_AppendResult(interp," ",PQfname(result,i),NULL);
620+
for (i=0;i<PQnfields(result);i++) {
621+
Tcl_AppendElement(interp,PQfname(result,i));
620622
}
621623
returnTCL_OK;
622624
}
623625
elseif (strcmp(opt,"-lAttributes")==0) {
624-
charbuf[512];
625-
Tcl_ResetResult(interp);
626626
for (i=0;i<PQnfields(result);i++) {
627-
sprintf(buf,"{%s} %ld %d",PQfname(result,i),
628-
(long)PQftype(result,i),
629-
PQfsize(result,i));
630-
Tcl_AppendElement(interp,buf);
627+
/* start a sublist */
628+
if (i>0)
629+
Tcl_AppendResult(interp," {",0);
630+
else
631+
Tcl_AppendResult(interp,"{",0);
632+
Tcl_AppendElement(interp,PQfname(result,i));
633+
sprintf(nameBuffer,"%ld", (long)PQftype(result,i));
634+
Tcl_AppendElement(interp,nameBuffer);
635+
sprintf(nameBuffer,"%ld", (long)PQfsize(result,i));
636+
Tcl_AppendElement(interp,nameBuffer);
637+
/* end the sublist */
638+
Tcl_AppendResult(interp,"}",0);
631639
}
632640
returnTCL_OK;
633641
}
634-
elseif (strcmp(opt,"-numAttrs")==0) {
635-
sprintf(interp->result,"%d",PQnfields(result));
636-
returnTCL_OK;
637-
}
638642
else {
639643
Tcl_AppendResult(interp,"Invalid option",0);
640644
gotoPg_result_errReturn;
@@ -649,9 +653,9 @@ Pg_result(ClientData cData, Tcl_Interp *interp, int argc, char* argv[])
649653
"\t-assign arrayVarName\n",
650654
"\t-assignbyidx arrayVarName\n",
651655
"\t-numTuples\n",
656+
"\t-numAttrs\n"
652657
"\t-attributes\n"
653658
"\t-lAttributes\n"
654-
"\t-numAttrs\n"
655659
"\t-getTuple tupleNumber\n",
656660
"\t-tupleArray tupleNumber arrayVarName\n",
657661
"\t-clear\n",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp