00001 /* src/interfaces/ecpg/ecpglib/typename.c */ 00002 00003 #define POSTGRES_ECPG_INTERNAL 00004 #include "postgres_fe.h" 00005 00006 #include <stdlib.h> 00007 #include "ecpgtype.h" 00008 #include "ecpglib.h" 00009 #include "extern.h" 00010 #include "sqltypes.h" 00011 #include "sql3types.h" 00012 #include "pg_type.h" 00013 00014 /* 00015 * This function is used to generate the correct type names. 00016 */ 00017 const char * 00018 ecpg_type_name(enum ECPGttype typ) 00019 { 00020 switch (typ) 00021 { 00022 case ECPGt_char: 00023 case ECPGt_string: 00024 return "char"; 00025 case ECPGt_unsigned_char: 00026 return "unsigned char"; 00027 case ECPGt_short: 00028 return "short"; 00029 case ECPGt_unsigned_short: 00030 return "unsigned short"; 00031 case ECPGt_int: 00032 return "int"; 00033 case ECPGt_unsigned_int: 00034 return "unsigned int"; 00035 case ECPGt_long: 00036 return "long"; 00037 case ECPGt_unsigned_long: 00038 return "unsigned long"; 00039 case ECPGt_long_long: 00040 return "long long"; 00041 case ECPGt_unsigned_long_long: 00042 return "unsigned long long"; 00043 case ECPGt_float: 00044 return "float"; 00045 case ECPGt_double: 00046 return "double"; 00047 case ECPGt_bool: 00048 return "bool"; 00049 case ECPGt_varchar: 00050 return "varchar"; 00051 case ECPGt_char_variable: 00052 return "char"; 00053 case ECPGt_decimal: 00054 return "decimal"; 00055 case ECPGt_numeric: 00056 return "numeric"; 00057 case ECPGt_date: 00058 return "date"; 00059 case ECPGt_timestamp: 00060 return "timestamp"; 00061 case ECPGt_interval: 00062 return "interval"; 00063 case ECPGt_const: 00064 return "Const"; 00065 default: 00066 abort(); 00067 } 00068 return ""; /* keep MSC compiler happy */ 00069 } 00070 00071 int 00072 ecpg_dynamic_type(Oid type) 00073 { 00074 switch (type) 00075 { 00076 case BOOLOID: 00077 return SQL3_BOOLEAN; /* bool */ 00078 case INT2OID: 00079 return SQL3_SMALLINT; /* int2 */ 00080 case INT4OID: 00081 return SQL3_INTEGER; /* int4 */ 00082 case TEXTOID: 00083 return SQL3_CHARACTER; /* text */ 00084 case FLOAT4OID: 00085 return SQL3_REAL; /* float4 */ 00086 case FLOAT8OID: 00087 return SQL3_DOUBLE_PRECISION; /* float8 */ 00088 case BPCHAROID: 00089 return SQL3_CHARACTER; /* bpchar */ 00090 case VARCHAROID: 00091 return SQL3_CHARACTER_VARYING; /* varchar */ 00092 case DATEOID: 00093 return SQL3_DATE_TIME_TIMESTAMP; /* date */ 00094 case TIMEOID: 00095 return SQL3_DATE_TIME_TIMESTAMP; /* time */ 00096 case TIMESTAMPOID: 00097 return SQL3_DATE_TIME_TIMESTAMP; /* datetime */ 00098 case NUMERICOID: 00099 return SQL3_NUMERIC; /* numeric */ 00100 default: 00101 return 0; 00102 } 00103 } 00104 00105 int 00106 sqlda_dynamic_type(Oid type, enum COMPAT_MODE compat) 00107 { 00108 switch (type) 00109 { 00110 case CHAROID: 00111 case VARCHAROID: 00112 case BPCHAROID: 00113 case TEXTOID: 00114 return ECPGt_char; 00115 case INT2OID: 00116 return ECPGt_short; 00117 case INT4OID: 00118 return ECPGt_int; 00119 case FLOAT8OID: 00120 return ECPGt_double; 00121 case FLOAT4OID: 00122 return ECPGt_float; 00123 case NUMERICOID: 00124 return INFORMIX_MODE(compat) ? ECPGt_decimal : ECPGt_numeric; 00125 case DATEOID: 00126 return ECPGt_date; 00127 case TIMESTAMPOID: 00128 case TIMESTAMPTZOID: 00129 return ECPGt_timestamp; 00130 case INTERVALOID: 00131 return ECPGt_interval; 00132 case INT8OID: 00133 #ifdef HAVE_LONG_LONG_INT_64 00134 return ECPGt_long_long; 00135 #endif 00136 #ifdef HAVE_LONG_INT_64 00137 return ECPGt_long; 00138 #endif 00139 /* Unhandled types always return a string */ 00140 default: 00141 return ECPGt_char; 00142 } 00143 }