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

Commit6a0d6d0

Browse files
author
Michael Meskes
committed
Added explicit casts for date/interval/timestamp.
1 parentf1a27b1 commit6a0d6d0

File tree

3 files changed

+61
-51
lines changed

3 files changed

+61
-51
lines changed

‎src/interfaces/ecpg/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,10 @@ Fri Jul 18 16:31:10 CEST 2003
15911591
Thu Jul 24 10:33:51 CEST 2003
15921592

15931593
- Fixed mdy functions to use correct offset.
1594+
1595+
Fri Jul 25 18:08:18 CEST 2003
1596+
1597+
- Added explicit casts for date/timestamp/interval.
15941598
- Set ecpg version to 3.0.0
15951599
- Set ecpg library to 4.0.0
15961600
- Set pgtypes library to 1.0.0

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

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.19 2003/07/15 12:38:38 meskes Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.20 2003/07/25 16:10:26 meskes Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -543,12 +543,12 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
543543

544544
if (var->arrsize>1)
545545
{
546-
strcpy(mallocedval,"'{");
546+
strcpy(mallocedval,"array [");
547547

548548
for (element=0;element<var->arrsize;element++)
549549
sprintf(mallocedval+strlen(mallocedval),"%hd,", ((short*)var->value)[element]);
550550

551-
strcpy(mallocedval+strlen(mallocedval)-1,"}'");
551+
strcpy(mallocedval+strlen(mallocedval)-1,"]");
552552
}
553553
else
554554
sprintf(mallocedval,"%hd",*((short*)var->value));
@@ -563,12 +563,12 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
563563

564564
if (var->arrsize>1)
565565
{
566-
strcpy(mallocedval,"'{");
566+
strcpy(mallocedval,"array [");
567567

568568
for (element=0;element<var->arrsize;element++)
569569
sprintf(mallocedval+strlen(mallocedval),"%d,", ((int*)var->value)[element]);
570570

571-
strcpy(mallocedval+strlen(mallocedval)-1,"}'");
571+
strcpy(mallocedval+strlen(mallocedval)-1,"]");
572572
}
573573
else
574574
sprintf(mallocedval,"%d",*((int*)var->value));
@@ -583,12 +583,12 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
583583

584584
if (var->arrsize>1)
585585
{
586-
strcpy(mallocedval,"'{");
586+
strcpy(mallocedval,"array [");
587587

588588
for (element=0;element<var->arrsize;element++)
589589
sprintf(mallocedval+strlen(mallocedval),"%hu,", ((unsigned short*)var->value)[element]);
590590

591-
strcpy(mallocedval+strlen(mallocedval)-1,"}'");
591+
strcpy(mallocedval+strlen(mallocedval)-1,"]");
592592
}
593593
else
594594
sprintf(mallocedval,"%hu",*((unsigned short*)var->value));
@@ -603,12 +603,12 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
603603

604604
if (var->arrsize>1)
605605
{
606-
strcpy(mallocedval,"'{");
606+
strcpy(mallocedval,"array [");
607607

608608
for (element=0;element<var->arrsize;element++)
609609
sprintf(mallocedval+strlen(mallocedval),"%u,", ((unsignedint*)var->value)[element]);
610610

611-
strcpy(mallocedval+strlen(mallocedval)-1,"}'");
611+
strcpy(mallocedval+strlen(mallocedval)-1,"]");
612612
}
613613
else
614614
sprintf(mallocedval,"%u",*((unsignedint*)var->value));
@@ -623,12 +623,12 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
623623

624624
if (var->arrsize>1)
625625
{
626-
strcpy(mallocedval,"'{");
626+
strcpy(mallocedval,"array [");
627627

628628
for (element=0;element<var->arrsize;element++)
629629
sprintf(mallocedval+strlen(mallocedval),"%ld,", ((long*)var->value)[element]);
630630

631-
strcpy(mallocedval+strlen(mallocedval)-1,"}'");
631+
strcpy(mallocedval+strlen(mallocedval)-1,"]");
632632
}
633633
else
634634
sprintf(mallocedval,"%ld",*((long*)var->value));
@@ -643,12 +643,12 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
643643

644644
if (var->arrsize>1)
645645
{
646-
strcpy(mallocedval,"'{");
646+
strcpy(mallocedval,"array [");
647647

648648
for (element=0;element<var->arrsize;element++)
649649
sprintf(mallocedval+strlen(mallocedval),"%lu,", ((unsigned long*)var->value)[element]);
650650

651-
strcpy(mallocedval+strlen(mallocedval)-1,"}'");
651+
strcpy(mallocedval+strlen(mallocedval)-1,"]");
652652
}
653653
else
654654
sprintf(mallocedval,"%lu",*((unsigned long*)var->value));
@@ -658,17 +658,17 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
658658
break;
659659
#ifdefHAVE_LONG_LONG_INT_64
660660
caseECPGt_long_long:
661-
if (!(mallocedval=ECPGalloc(var->arrsize*25,stmt->lineno)))
661+
if (!(mallocedval=ECPGalloc(var->arrsize*30,stmt->lineno)))
662662
return false;
663663

664664
if (var->arrsize>1)
665665
{
666-
strcpy(mallocedval,"'{");
666+
strcpy(mallocedval,"array [");
667667

668668
for (element=0;element<var->arrsize;element++)
669669
sprintf(mallocedval+strlen(mallocedval),"%lld,", ((long long*)var->value)[element]);
670670

671-
strcpy(mallocedval+strlen(mallocedval)-1,"}'");
671+
strcpy(mallocedval+strlen(mallocedval)-1,"]");
672672
}
673673
else
674674
sprintf(mallocedval,"%lld",*((long long*)var->value));
@@ -678,17 +678,17 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
678678
break;
679679

680680
caseECPGt_unsigned_long_long:
681-
if (!(mallocedval=ECPGalloc(var->arrsize*25,stmt->lineno)))
681+
if (!(mallocedval=ECPGalloc(var->arrsize*30,stmt->lineno)))
682682
return false;
683683

684684
if (var->arrsize>1)
685685
{
686-
strcpy(mallocedval,"'{");
686+
strcpy(mallocedval,"array [");
687687

688688
for (element=0;element<var->arrsize;element++)
689689
sprintf(mallocedval+strlen(mallocedval),"%llu,", ((unsigned long long*)var->value)[element]);
690690

691-
strcpy(mallocedval+strlen(mallocedval)-1,"}'");
691+
strcpy(mallocedval+strlen(mallocedval)-1,"]");
692692
}
693693
else
694694
sprintf(mallocedval,"%llu",*((unsigned long long*)var->value));
@@ -698,17 +698,17 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
698698
break;
699699
#endif/* HAVE_LONG_LONG_INT_64 */
700700
caseECPGt_float:
701-
if (!(mallocedval=ECPGalloc(var->arrsize*21,stmt->lineno)))
701+
if (!(mallocedval=ECPGalloc(var->arrsize*25,stmt->lineno)))
702702
return false;
703703

704704
if (var->arrsize>1)
705705
{
706-
strcpy(mallocedval,"'{");
706+
strcpy(mallocedval,"array [");
707707

708708
for (element=0;element<var->arrsize;element++)
709709
sprintf(mallocedval+strlen(mallocedval),"%.14g,", ((float*)var->value)[element]);
710710

711-
strcpy(mallocedval+strlen(mallocedval)-1,"}'");
711+
strcpy(mallocedval+strlen(mallocedval)-1,"]");
712712
}
713713
else
714714
sprintf(mallocedval,"%.14g",*((float*)var->value));
@@ -718,17 +718,17 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
718718
break;
719719

720720
caseECPGt_double:
721-
if (!(mallocedval=ECPGalloc(var->arrsize*21,stmt->lineno)))
721+
if (!(mallocedval=ECPGalloc(var->arrsize*25,stmt->lineno)))
722722
return false;
723723

724724
if (var->arrsize>1)
725725
{
726-
strcpy(mallocedval,"'{");
726+
strcpy(mallocedval,"array [");
727727

728728
for (element=0;element<var->arrsize;element++)
729729
sprintf(mallocedval+strlen(mallocedval),"%.14g,", ((double*)var->value)[element]);
730730

731-
strcpy(mallocedval+strlen(mallocedval)-1,"}'");
731+
strcpy(mallocedval+strlen(mallocedval)-1,"]");
732732
}
733733
else
734734
sprintf(mallocedval,"%.14g",*((double*)var->value));
@@ -738,12 +738,12 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
738738
break;
739739

740740
caseECPGt_bool:
741-
if (!(mallocedval=ECPGalloc(var->arrsize*2,stmt->lineno)))
741+
if (!(mallocedval=ECPGalloc(var->arrsize+sizeof ("array []"),stmt->lineno)))
742742
return false;
743743

744744
if (var->arrsize>1)
745745
{
746-
strcpy(mallocedval,"'{");
746+
strcpy(mallocedval,"array [");
747747

748748
if (var->offset==sizeof(char))
749749
for (element=0;element<var->arrsize;element++)
@@ -759,7 +759,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
759759
else
760760
ECPGraise(stmt->lineno,ECPG_CONVERT_BOOL,"different size");
761761

762-
strcpy(mallocedval+strlen(mallocedval)-1,"}'");
762+
strcpy(mallocedval+strlen(mallocedval)-1,"]");
763763
}
764764
else
765765
{
@@ -854,16 +854,16 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
854854
PGTYPESnumeric_free(nval);
855855
slen=strlen (str);
856856

857-
if (!(mallocedval=ECPGrealloc(mallocedval,strlen(mallocedval)+slen+5,stmt->lineno)))
857+
if (!(mallocedval=ECPGrealloc(mallocedval,strlen(mallocedval)+slen+sizeof("array [] "),stmt->lineno)))
858858
return false;
859859

860860
if (!element)
861-
strcpy(mallocedval,"'{");
861+
strcpy(mallocedval,"array [");
862862

863863
strncpy(mallocedval+strlen(mallocedval),str ,slen+1);
864864
strcpy(mallocedval+strlen(mallocedval),",");
865865
}
866-
strcpy(mallocedval+strlen(mallocedval)-1,"}'");
866+
strcpy(mallocedval+strlen(mallocedval)-1,"]");
867867
}
868868
else
869869
{
@@ -902,27 +902,29 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
902902
str=quote_postgres(PGTYPESinterval_to_asc((Interval*)((var+var->offset*element)->value)),stmt->lineno);
903903
slen=strlen (str);
904904

905-
if (!(mallocedval=ECPGrealloc(mallocedval,strlen(mallocedval)+slen+5,stmt->lineno)))
905+
if (!(mallocedval=ECPGrealloc(mallocedval,strlen(mallocedval)+slen+sizeof("array [],interval "),stmt->lineno)))
906906
return false;
907907

908908
if (!element)
909-
strcpy(mallocedval,"'{");
910-
909+
strcpy(mallocedval,"array [");
910+
911+
strcpy(mallocedval+strlen(mallocedval),"interval ");
911912
strncpy(mallocedval+strlen(mallocedval),str ,slen+1);
912913
strcpy(mallocedval+strlen(mallocedval),",");
913914
}
914-
strcpy(mallocedval+strlen(mallocedval)-1,"}'");
915+
strcpy(mallocedval+strlen(mallocedval)-1,"]");
915916
}
916917
else
917918
{
918919
str=quote_postgres(PGTYPESinterval_to_asc((Interval*)(var->value)),stmt->lineno);
919920
slen=strlen (str);
920921

921-
if (!(mallocedval=ECPGalloc(slen+1,stmt->lineno)))
922+
if (!(mallocedval=ECPGalloc(slen+sizeof("interval ")+1,stmt->lineno)))
922923
return false;
923924

924-
strncpy(mallocedval,str ,slen);
925-
mallocedval[slen]='\0';
925+
strcpy(mallocedval,"interval ");
926+
/* also copy trailing '\0' */
927+
strncpy(mallocedval+strlen(mallocedval),str ,slen+1);
926928
}
927929

928930
*tobeinserted_p=mallocedval;
@@ -943,27 +945,29 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
943945
str=quote_postgres(PGTYPESdate_to_asc(*(Date*)((var+var->offset*element)->value)),stmt->lineno);
944946
slen=strlen (str);
945947

946-
if (!(mallocedval=ECPGrealloc(mallocedval,strlen(mallocedval)+slen+5,stmt->lineno)))
948+
if (!(mallocedval=ECPGrealloc(mallocedval,strlen(mallocedval)+slen+sizeof("array [],date "),stmt->lineno)))
947949
return false;
948950

949951
if (!element)
950-
strcpy(mallocedval,"'{");
952+
strcpy(mallocedval,"array [");
951953

954+
strcpy(mallocedval+strlen(mallocedval),"date ");
952955
strncpy(mallocedval+strlen(mallocedval),str ,slen+1);
953956
strcpy(mallocedval+strlen(mallocedval),",");
954957
}
955-
strcpy(mallocedval+strlen(mallocedval)-1,"}'");
958+
strcpy(mallocedval+strlen(mallocedval)-1,"]");
956959
}
957960
else
958961
{
959962
str=quote_postgres(PGTYPESdate_to_asc(*(Date*)(var->value)),stmt->lineno);
960963
slen=strlen (str);
961964

962-
if (!(mallocedval=ECPGalloc(slen+1,stmt->lineno)))
965+
if (!(mallocedval=ECPGalloc(slen+sizeof("date ")+1,stmt->lineno)))
963966
return false;
964967

965-
strncpy(mallocedval,str ,slen);
966-
mallocedval[slen]='\0';
968+
strcpy(mallocedval,"date ");
969+
/* also copy trailing '\0' */
970+
strncpy(mallocedval+strlen(mallocedval),str ,slen+1);
967971
}
968972

969973
*tobeinserted_p=mallocedval;
@@ -984,27 +988,29 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
984988
str=quote_postgres(PGTYPEStimestamp_to_asc(*(Timestamp*)((var+var->offset*element)->value)),stmt->lineno);
985989
slen=strlen (str);
986990

987-
if (!(mallocedval=ECPGrealloc(mallocedval,strlen(mallocedval)+slen+5,stmt->lineno)))
991+
if (!(mallocedval=ECPGrealloc(mallocedval,strlen(mallocedval)+slen+sizeof("array [], timestamp "),stmt->lineno)))
988992
return false;
989993

990994
if (!element)
991-
strcpy(mallocedval,"'{");
995+
strcpy(mallocedval,"array [");
992996

997+
strcpy(mallocedval+strlen(mallocedval),"timestamp ");
993998
strncpy(mallocedval+strlen(mallocedval),str ,slen+1);
994999
strcpy(mallocedval+strlen(mallocedval),",");
9951000
}
996-
strcpy(mallocedval+strlen(mallocedval)-1,"}'");
1001+
strcpy(mallocedval+strlen(mallocedval)-1,"]");
9971002
}
9981003
else
9991004
{
10001005
str=quote_postgres(PGTYPEStimestamp_to_asc(*(Timestamp*)(var->value)),stmt->lineno);
10011006
slen=strlen (str);
10021007

1003-
if (!(mallocedval=ECPGalloc(slen+1,stmt->lineno)))
1008+
if (!(mallocedval=ECPGalloc(slen+sizeof("timestamp")+1,stmt->lineno)))
10041009
return false;
10051010

1006-
strncpy(mallocedval,str ,slen);
1007-
mallocedval[slen]='\0';
1011+
strcpy(mallocedval,"timestamp ");
1012+
/* also copy trailing '\0' */
1013+
strncpy(mallocedval+strlen(mallocedval),str ,slen+1);
10081014
}
10091015

10101016
*tobeinserted_p=mallocedval;

‎src/interfaces/ecpg/test/dt_test.pgc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ main()
3434

3535
exec sql insert into date_test(d, ts, iv) values (:date1, :ts1, now()-'Mon Jan 17 1966');
3636

37-
exec sql select * into :date1, :ts1 , :iv1 from date_test;
37+
exec sql select * into :date1, :ts1 , :iv1 from date_test where d=:date1;
3838

3939
text = PGTYPESdate_to_asc(date1);
4040
printf ("Date: %s\n", text);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp