Esempio n. 1
0
void 
gmdb_schema_new_cb(GtkWidget *w, gpointer data) 
{
	GList *glist = NULL;
	GtkWidget *combo;
	MdbCatalogEntry *entry;
	int i;
   
	/* load the interface */
	schemawin_xml = glade_xml_new(GMDB_GLADEDIR "gmdb-schema.glade", NULL, NULL);
	/* connect the signals in the interface */
	glade_xml_signal_autoconnect(schemawin_xml);
	/* set up capabilities call back. TODO: autoconnect should do that */
	combo = glade_xml_get_widget(schemawin_xml, "combo-list2");
	g_signal_connect( G_OBJECT (combo), "selection_changed",
		G_CALLBACK(gmdb_schema_capabilities_cb), schemawin_xml);
	
	/* set signals with user data, anyone know how to do this in glade? */
	combo = glade_xml_get_widget (schemawin_xml, "table_combo");

	glist = g_list_append(glist, ALL_TABLES);
	/* add all user tables in catalog to list */
	for (i=0; i < mdb->num_catalog; i++) {
		entry = g_ptr_array_index (mdb->catalog, i);
		if (mdb_is_user_table(entry)) {
			glist = g_list_append(glist, entry->object_name);
		}
	} /* for */
	gtk_combo_set_popdown_strings(GTK_COMBO(combo), glist);
	g_list_free(glist);

	check_default_options();
	refresh_available_options();
}
Esempio n. 2
0
void
mdb_print_schema(MdbHandle *mdb, FILE *outfile, char *tabname, char *dbnamespace, guint32 export_options)
{
	unsigned int   i;
	char		*the_relation;
	MdbCatalogEntry *entry;
	const char *charset;

	/* clear unsupported options */
	export_options &= mdb->default_backend->capabilities;

	/* Print out a little message to show that this came from mdb-tools.
	   I like to know how something is generated. DW */
	fputs("-- ----------------------------------------------------------\n"
		"-- MDB Tools - A library for reading MS Access database files\n"
		"-- Copyright (C) 2000-2011 Brian Bruns and others.\n"
		"-- Files in libmdb are licensed under LGPL and the utilities under\n"
		"-- the GPL, see COPYING.LIB and COPYING files respectively.\n"
		"-- Check out http://mdbtools.sourceforge.net\n"
		"-- ----------------------------------------------------------\n\n",
		outfile);

	charset = mdb_target_charset(mdb);
	if (charset) {
		fprintf(outfile, mdb->default_backend->charset_statement, charset);
		fputc('\n', outfile);
	}

	for (i=0; i < mdb->num_catalog; i++) {
		entry = g_ptr_array_index (mdb->catalog, i);
		if (entry->object_type == MDB_TABLE) {
			if ((tabname && !strcmp(entry->object_name, tabname))
			 || (!tabname && mdb_is_user_table(entry))) {
				generate_table_schema(outfile, entry, dbnamespace, export_options);
			}
		}
	}
	fprintf (outfile, "\n");

	if (export_options & MDB_SHEXP_RELATIONS) {
		fputs ("-- CREATE Relationships ...\n", outfile);
		while ((the_relation=mdb_get_relationships(mdb, dbnamespace, tabname)) != NULL) {
			fputs(the_relation, outfile);
			g_free(the_relation);
		}
	}
}
Esempio n. 3
0
static void 
gmdb_sql_tree_populate(MdbHandle *mdb, GladeXML *xml)
{
int   i;
MdbCatalogEntry *entry;
GtkTreeIter *iter2;

	GtkWidget *tree = glade_xml_get_widget(xml, "sql_treeview");
	GtkTreeStore *store = (GtkTreeStore *) gtk_tree_view_get_model(GTK_TREE_VIEW(tree));

	/* add all user tables in catalog to tab */
	for (i=0; i < mdb->num_catalog; i++) {
		entry = g_ptr_array_index (mdb->catalog, i);
		if (mdb_is_user_table(entry)) {
			iter2 = g_malloc(sizeof(GtkTreeIter));
			gtk_tree_store_append(store, iter2, NULL);
			gtk_tree_store_set(store, iter2, 0, entry->object_name, -1);
		}
	} /* for */
}
Esempio n. 4
0
int
main (int argc, char **argv)
{
unsigned int   i, j, k;
unsigned int unsupported = 0;
MdbHandle *mdb;
MdbCatalogEntry *entry;
MdbTableDef *table;
MdbColumn *col;
FILE *typesfile;
FILE *headerfile;
FILE *cfile;

 if (argc < 2) {
   fprintf (stderr, "Usage: %s <file>\n",argv[0]);
   exit (1);
 }

 mdb_init();

 /* open the database */

 mdb = mdb_open (argv[1], MDB_NOFLAGS);
 if (!mdb) {
 	mdb_exit();
	exit(1);
 }

 typesfile = fopen ("types.h", "w");
 headerfile = fopen ("dumptypes.h", "w");
 cfile = fopen ("dumptypes.c", "w");

 copy_header (typesfile);
 copy_header (headerfile);
 fprintf (headerfile, "#include \"types.h\"\n");
 copy_header (cfile);
 fprintf (cfile, "#include <stdio.h>\n");
 fprintf (cfile, "#include \"dumptypes.h\"\n");
 
 /* read the catalog */
 
 mdb_read_catalog (mdb, MDB_TABLE);

 /* loop over each entry in the catalog */

 for (i=0; i < mdb->num_catalog; i++) 
   {
     entry = g_ptr_array_index (mdb->catalog, i);

     if (!mdb_is_user_table(entry))
          continue;

	       fprintf (typesfile, "typedef struct _%s\n", entry->object_name);
	       fprintf (typesfile, "{\n");

	       fprintf (headerfile, "void dump_%s (%s x);\n",
			entry->object_name, entry->object_name);
	       fprintf (cfile, "void dump_%s (%s x)\n{\n",
			entry->object_name, entry->object_name);
	       fprintf (cfile, "\tfprintf (stdout, \"**************** %s ****************\\n\");\n", entry->object_name);
	       table = mdb_read_table (entry);

	       /* get the columns */
	       mdb_read_columns (table);

	       /* loop over the columns, dumping the names and types */

	       for (k = 0; k < table->num_cols; k++)
		 {
		   col = g_ptr_array_index (table->columns, k);
		   fprintf (cfile, "\tfprintf (stdout, \"x.");
		   for (j = 0; j < strlen (col->name); j++)
		     {
		       fprintf (cfile, "%c", tolower (col->name [j]));
		     }
		   fprintf (cfile, " = \");\n");
		   switch (col->col_type)
		     {
		     case MDB_INT:
		       fprintf (typesfile, "\tint\t");
		       fprintf (cfile, "\tdump_int (x.");
		       break;
		     case MDB_LONGINT:
		       fprintf (typesfile, "\tlong\t");
		       fprintf (cfile, "\tdump_long (x.");
		       break;
		     case MDB_TEXT:
		     case MDB_MEMO:
		       fprintf (typesfile, "\tchar *\t");
		       fprintf (cfile, "\tdump_string (x.");
		       break;
		     default:
		       unsupported = 1;
		       break;
		     }
		   for (j = 0; j < strlen (col->name); j++)
		     {
		       fprintf (typesfile, "%c", tolower (col->name [j]));
		       fprintf (cfile, "%c", tolower (col->name [j]));
		     }
		   fprintf (typesfile, ";\n");
		   fprintf (cfile, ");\n");
		 }

	       fprintf (typesfile, "\n} %s ;\n", entry->object_name);
	       fprintf (typesfile, "\n");
	       fprintf (cfile, "}\n\n");

	       mdb_free_tabledef(table);
   }

 fclose (headerfile);
 fclose (typesfile);
 fclose (cfile);
 
 mdb_close (mdb);
 mdb_exit();

 if (unsupported)
  fputs("ERROR: unsupported type.\n", stderr);
 exit(unsupported);
}