/* GDA MDB provider * Copyright (C) 1998 - 2005 The GNOME Foundation. * * AUTHORS: * Rodrigo Moya * Vivien Malerba * * This Library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This Library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this Library; see the file COPYING.LIB. If not, * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #include "gda-mdb-table.h" #include GdaDataModel * gda_mdb_table_new (GdaMdbConnection *mdb_cnc, const gchar *name) { gint i; MdbCatalogEntry *entry; MdbTableDef *mdb_table; MdbColumn *mdb_col; GdaColumn *fa; GdaDataModel *model = NULL; g_return_val_if_fail (mdb_cnc != NULL, NULL); g_return_val_if_fail (name != NULL, NULL); for (i = 0; i < mdb_cnc->mdb->num_catalog; i++) { entry = g_ptr_array_index (mdb_cnc->mdb->catalog, i); if (entry->object_type == MDB_TABLE && !strcmp (entry->object_type, name)) break; else entry = NULL; } if (!entry) { gda_connection_add_event_string (mdb_cnc->cnc, _("Table %s not found"), name); return NULL; } mdb_table = mdb_read_table (entry); mdb_read_columns (mdb_table); mdb_rewind_table (mdb_table); /* create the table and its fields */ model = gda_data_model_array_new (mdb_table->num_cols); g_object_set (G_OBJECT (model), "command_text", name, NULL); for (i = 0; i < mdb_table->num_cols; i++) { mdb_col = g_ptr_array_index (mdb_table->columns, i); fa = gda_data_model_describe_column (model, i); gda_column_set_name (fa, mdb_col->name); gda_column_set_gda_type (fa, gda_mdb_type_to_gda (mdb_col->col_type)); gda_column_set_defined_size (fa, mdb_col->col_size); } return model; }