|
1 |
| -/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.3 2003/03/19 16:05:41 petere Exp $ */ |
| 1 | +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.4 2003/03/20 15:56:50 meskes Exp $ */ |
2 | 2 |
|
3 | 3 | /*
|
4 | 4 | * The aim is to get a simpler inteface to the database routines.
|
|
27 | 27 | #include"sqlca.h"
|
28 | 28 | #include"sql3types.h"
|
29 | 29 | #include"pgtypes_numeric.h"
|
| 30 | +#include"pgtypes_date.h" |
| 31 | +#include"pgtypes_timestamp.h" |
30 | 32 |
|
31 | 33 | /* variables visible to the programs */
|
32 | 34 | structsqlcasqlca=
|
@@ -59,8 +61,7 @@ struct sqlca sqlca =
|
59 | 61 | /* This function returns a newly malloced string that has the \
|
60 | 62 | in the argument quoted with \ and the ' quoted with ' as SQL92 says.
|
61 | 63 | */
|
62 |
| -static |
63 |
| -char* |
| 64 | +staticchar* |
64 | 65 | quote_postgres(char*arg,intlineno)
|
65 | 66 | {
|
66 | 67 | char*res= (char*)ECPGalloc(2*strlen(arg)+3,lineno);
|
@@ -876,6 +877,89 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
|
876 | 877 | free(str);
|
877 | 878 | }
|
878 | 879 | break;
|
| 880 | + |
| 881 | +caseECPGt_date: |
| 882 | +{ |
| 883 | +char*str=NULL; |
| 884 | +intslen; |
| 885 | + |
| 886 | +if (var->arrsize>1) |
| 887 | +{ |
| 888 | +for (element=0;element<var->arrsize;element++) |
| 889 | +{ |
| 890 | +str=PGTYPESdate_dtoa(*(Date*)((var+var->offset*element)->value)); |
| 891 | +slen=strlen (str); |
| 892 | + |
| 893 | +if (!(mallocedval=ECPGrealloc(mallocedval,strlen(mallocedval)+slen+5,stmt->lineno))) |
| 894 | +return false; |
| 895 | + |
| 896 | +if (!element) |
| 897 | +strcpy(mallocedval,"'{"); |
| 898 | + |
| 899 | +strncpy(mallocedval+strlen(mallocedval),str ,slen+1); |
| 900 | +strcpy(mallocedval+strlen(mallocedval),","); |
| 901 | +} |
| 902 | +strcpy(mallocedval+strlen(mallocedval)-1,"}'"); |
| 903 | +} |
| 904 | +else |
| 905 | +{ |
| 906 | +str=PGTYPESdate_dtoa(*(Date*)(var->value)); |
| 907 | +slen=strlen (str); |
| 908 | + |
| 909 | +if (!(mallocedval=ECPGalloc(slen+1,stmt->lineno))) |
| 910 | +return false; |
| 911 | + |
| 912 | +strncpy(mallocedval,str ,slen); |
| 913 | +mallocedval[slen]='\0'; |
| 914 | +} |
| 915 | + |
| 916 | +*tobeinserted_p=mallocedval; |
| 917 | +*malloced_p= true; |
| 918 | +free(str); |
| 919 | +} |
| 920 | +break; |
| 921 | + |
| 922 | +caseECPGt_timestamp: |
| 923 | +{ |
| 924 | +char*str=NULL; |
| 925 | +intslen; |
| 926 | + |
| 927 | +if (var->arrsize>1) |
| 928 | +{ |
| 929 | +for (element=0;element<var->arrsize;element++) |
| 930 | +{ |
| 931 | +str=PGTYPEStimestamp_ttoa(*(Timestamp*)((var+var->offset*element)->value)); |
| 932 | +slen=strlen (str); |
| 933 | + |
| 934 | +if (!(mallocedval=ECPGrealloc(mallocedval,strlen(mallocedval)+slen+5,stmt->lineno))) |
| 935 | +return false; |
| 936 | + |
| 937 | +if (!element) |
| 938 | +strcpy(mallocedval,"'{"); |
| 939 | + |
| 940 | +strncpy(mallocedval+strlen(mallocedval),str ,slen+1); |
| 941 | +strcpy(mallocedval+strlen(mallocedval),","); |
| 942 | +} |
| 943 | +strcpy(mallocedval+strlen(mallocedval)-1,"}'"); |
| 944 | +} |
| 945 | +else |
| 946 | +{ |
| 947 | +str=PGTYPEStimestamp_ttoa(*(Timestamp*)(var->value)); |
| 948 | +slen=strlen (str); |
| 949 | + |
| 950 | +if (!(mallocedval=ECPGalloc(slen+1,stmt->lineno))) |
| 951 | +return false; |
| 952 | + |
| 953 | +strncpy(mallocedval,str ,slen); |
| 954 | +mallocedval[slen]='\0'; |
| 955 | +} |
| 956 | + |
| 957 | +*tobeinserted_p=mallocedval; |
| 958 | +*malloced_p= true; |
| 959 | +free(str); |
| 960 | +} |
| 961 | +break; |
| 962 | + |
879 | 963 | default:
|
880 | 964 | /* Not implemented yet */
|
881 | 965 | ECPGraise(stmt->lineno,ECPG_UNSUPPORTED, (char*)ECPGtype_name(var->type));
|
|