/* * Copyright (c) 1995 Gunther Schadow. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "t2c.h" #include #include #include "Table.h" #ifdef BOOTSTRAP #include "bootstrap.h" #else #include "All_Tab_Columns.h" #endif type_rec types[NOTYPES] = { { T_UNDEFINED,"UNDEFINED","STRING", "char", TRUE }, { T_VARCHAR2, "VARCHAR2", "STRING", "char", TRUE }, { T_NUMBER, "NUMBER", "INT", "long", FALSE }, { T_NUMBER, "NUMBER", "DOUBLE", "double", FALSE }, { T_LONG, "LONG", "LSTRING","char", TRUE }, { T_ROWID, "ROWID", "STRING", "ora_rowid",TRUE }, { T_DATE, "DATE", "DATE", "ora_date", FALSE }, { T_RAW, "RAW", "STRING", "char", TRUE }, { T_LONG_RAW, "LONG RAW", "LSTRING","char", TRUE }, { T_CHAR, "CHAR", "STRING", "char", TRUE }, { T_MLSLABEL, "MLSLABEL", "STRING", "char", TRUE }, { T_INTEGER, "INTEGER", "INT", "long", FALSE }, { T_FLOAT, "FLOAT", "DOUBLE", "double", FALSE }, { T_STRING, "STRING", "STRING", "char", TRUE }, { T_VARNUM, "VARNUM", "INT", "long", FALSE }, { T_VARCHAR, "VARCHAR", "STRING", "char", TRUE }, { T_VARRAW, "VARRAW", "STRING", "char", TRUE }, { T_DISPLAY, "DISPLAY", "STRING", "char", TRUE }, { T_CHARZ, "CHARZ", "STRING", "char", TRUE }, { T_LONG_VARCHAR, "LONG_VARCHAR", "LSTRING", "char", TRUE }, { T_LONG_VARRAW, "LONG_VARRAW", "LSTRING", "char", TRUE }, { T_PACKED_DECIMAL, "PACKED_DECIMAL", "STRING", "char", TRUE }, { T_UNSIGNED_INT, "UNSIGNED_INT", "UINT", "unsigned long", FALSE }, }; type_rec* type_lookup(const char* data_type) { for(u_int i = 0; iname; q = p->next; delete p; p = q; } } #define CMDBUFSIZE 1024 decl_rec * make_decl(const char *owner, const char* name) { All_Tab_Columns atc; struct decl_rec *declp = NULL, **link = &declp; char cmd_buf[CMDBUFSIZE]; strncpy(cmd_buf, "WHERE table_name = '", CMDBUFSIZE); strncat(cmd_buf, name, CMDBUFSIZE); strncat(cmd_buf, "' AND owner = '", CMDBUFSIZE); strncat(cmd_buf, owner, CMDBUFSIZE); strncat(cmd_buf, "' ", CMDBUFSIZE); for(result r = atc.retrieve(cmd_buf); r == SUCCESS; r = atc.next()) { resetnames(); struct decl_rec *p = new decl_rec; p->type = type_lookup(atc.get_data_type()); /* check for floating point numbers */ if(p->type->t_id == T_NUMBER && !atc.data_precision_is_null()) p->type++; if( ! atc.data_length_is_null() && p->type->has_size ) p->size = atc.get_data_length(); else p->size = 0; if( ! atc.column_name_is_null() ) { p->name = strdup(varname(atc.get_column_name())); *link = p; link = &p->next; } else delete p; } *link = NULL; return declp; }