// 	
//	 void mdb_list_queries(MdbHandle *mdb, int line_break, char *delimiter);
//	 char * mdb_get_query_id(MdbHandle *mdb,char *query);
//	 
//	 int main (int argc, char **argv) {
//	 	int i;
//	 	MdbHandle *mdb;
//	 	MdbCatalogEntry *entry,*sys_queries,*temp;
//	 	MdbTableDef *table;
//	 	char *jet_version;
//	 	char *delimiter = NULL;
//	 	int list_only=0;
//	 	int found_match=0;
//	 	int line_break=0;
//	 	int opt;	
//	 	int newline=0;
//	 	char *query_id;
//	 	
//	 	// variables for the msysqueries table. hopefully 256 is big enough
//	 	char *attribute = (char *) malloc(MDB_BIND_SIZE);
//	 	char *expression = (char *) malloc(MDB_BIND_SIZE);
//	 	char *flag = (char *) malloc(MDB_BIND_SIZE);
//	 	char *lvextra = (char *) malloc(MDB_BIND_SIZE);
//	 	char *name1 = (char *) malloc(MDB_BIND_SIZE);
//	 	char *name2 = (char *) malloc(MDB_BIND_SIZE);
//	 	char *objectid = (char *) malloc(MDB_BIND_SIZE);
//	 	char *order = (char *) malloc(MDB_BIND_SIZE);
//	 	
//	 	//variables for the generation of sql
//	 	char *sql_tables = (char *) malloc(MDB_BIND_SIZE);
//	 	char *sql_columns = (char *) malloc(MDB_BIND_SIZE);
//	 	char *sql_where = (char *) malloc(MDB_BIND_SIZE);
//	 	char *sql_join = (char *) malloc(MDB_BIND_SIZE);
//	 	char *sql_sorting = (char *) malloc(MDB_BIND_SIZE);
//	 	
//	 	/* see getopt(3) for more information on getopt and this will become clear */
//	 	while ((opt=getopt(argc, argv, "L1d:"))!=-1) {
//	         switch (opt) {
//	 			case "L":
//	 				list_only = 1;
//	 				break;
//	 			case "1":
//	 				line_break = 1;
//	 				break;
//	 			case "d":
//	             	delimiter = (char *) malloc(strlen(optarg)+1);
//	 				strcpy(delimiter, optarg);
//	 				break;
//	 		}
//	 	}
//	 
//	 	/* we"ve parsed all the options and we should at least have a database name left */
//	 	if ((argc - optind) < 1) {
//	 		fprintf (stderr, "Usage: %s [options] <database filename> <query name>\n",argv[0]);
//	 		fprintf (stderr, "where options are:\n");
//	 		fprintf (stderr, "  -L\t\t\tList queries in the database (default if no query name is
//	passed)\n");
//	 		fprintf (stderr, "  -1\t\t\tUse newline as the delimiter (used in conjuction with
//	listing)\n");
//	 		fprintf (stderr, "  -d <delimiter>\tSpecify delimiter to use\n");
//	 		exit (1);
//	 	}
//	 	
//	 	/* let"s turn list_only on if only a database filename was passed */
//	 	if((argc-optind) < 2)
//	 		list_only=1;
//	 	
//	  	/* initialize the library */
//	  	mdb_init();
//	 
//	  	/* open the database */
//	  	if (!(mdb = mdb_open(argv[optind],MDB_NOFLAGS))) {
//	 		fprintf(stderr,"Couldn"t open database.\n");
//	 		exit(1);
//	 	}
//	 
//	  	/* read the catalog */
//	  	if (!mdb_read_catalog (mdb, MDB_ANY)) {
//	 		fprintf(stderr,"File does not appear to be an Access database\n");
//	 		exit(1);
//	 	}
//	 	
//	 	/* figure out what version we are working with */
//	 	if (IS_JET3(mdb)) {
//	 		strncpy(jet_version,"JET3",4);
//	 	} else if (IS_JET4(mdb)) {
//	 		strncpy(jet_version,"JET4",4);
//	 	} else {
//	 		strncpy(jet_version,"Unknown Version",15);
//	 	}
//	 		
//	 	if(list_only) { 
//	 		mdb_list_queries(mdb,line_break,delimiter);
//	 	} else {
//	 		/* let"s get the entry for the user specified query
//	 			 we also want to get the catalog for the MSysQueries table
//	 			 while we are here */
//	 		for (i=0; i < mdb->num_catalog; i++) {
//	 			temp = g_ptr_array_index(mdb->catalog, i);
//	 			
//	 			if(strcmp(temp->object_name,argv[optind+1]) == 0) {
//	 				entry = g_ptr_array_index(mdb->catalog,i);
//	 				found_match=1;
//	 			} else if(strcmp(temp->object_name,"MSysQueries") == 0) {
//	 				sys_queries = g_ptr_array_index(mdb->catalog,i);
//	 			} 
//	 		}
//	 		
//	 		if(found_match) {
//	 			/* Let"s get the id for the query */
//	 			query_id = mdb_get_query_id(mdb,entry->object_name);
//	 			
//	 			table = mdb_read_table(sys_queries);
//	 
//	 			if(table) {
//	 				mdb_read_columns(table);
//	 
//	 				/* There is a slight difference in the makeup of the MSysQueries table
//	 					 across jet versions.  As far as I can tell, the lvextra column is
//	 					 missing from the JET3 table.  I am assuming that if the database
//	 					 version is unknown, then it follows the JET3 structure, but realistically
//	 					 this will probably cause a segfault for an unknown version */ 
//	 				if(strcmp(jet_version,"JET4") == 0) {
//	 					mdb_bind_column(table, 1, attribute);
//	 					mdb_bind_column(table, 2, expression);
//	 					mdb_bind_column(table, 3, flag);
//	 					mdb_bind_column(table, 4, lvextra);
//	 					mdb_bind_column(table, 5, name1);
//	 					mdb_bind_column(table, 6, name2);
//	 					mdb_bind_column(table, 7, objectid);
//	 					mdb_bind_column(table, 8, order);
//	 				} else {
//	 					mdb_bind_column(table, 1, objectid);
//	 					mdb_bind_column(table, 2, attribute);
//	 					mdb_bind_column(table, 3, order);
//	 					mdb_bind_column(table, 4, name1);
//	 					mdb_bind_column(table, 5, name2);
//	 					mdb_bind_column(table, 6, expression);
//	 					mdb_bind_column(table, 7, flag);
//	 				}
//	 
//	 				mdb_rewind_table(table);
//	 
//	 				while (mdb_fetch_row(table)) {
//	 					if(strcmp(query_id,objectid) == 0) {
//	 						//we have a row for our query
//	 						switch(atoi(attribute)) {
//	 							case 5:		// table name
//	 								if(strcmp(sql_tables,"") == 0) {
//	 									strcpy(sql_tables,name1);
//	 								} else {
//	 									strcat(sql_tables,",");
//	 									strcat(sql_tables,name1);
//	 								}
//	 								break;
//	 							case 6:		// column name
//	 								if(strcmp(sql_columns,"") == 0) {
//	 									strcpy(sql_columns,expression);
//	 								} else {
//	 									strcat(sql_columns,",");
//	 									strcat(sql_columns,expression);
//	 								}
//	 								break;
//	 							case 7:		// join/relationship where clause
//	 								//fprintf(stdout,"join tables: %s - %s\n",name1,name2);
//	 								//fprintf(stdout,"join clause: %s\n",expression);
//	 								break;
//	 							case 8:		// where clause
//	 								strcpy(sql_where,expression);
//	 								break;
//	 							case 11:		// sorting
//	 								if(strcmp(sql_sorting,"") == 0) {
//	 									strcpy(sql_sorting,"ORDER BY ");
//	 									strcat(sql_sorting,expression);
//	 									if(strcmp(name1,"D") == 0) {
//	 										strcat(sql_sorting," DESCENDING");
//	 									}
//	 								}
//	 								break;
//	 						}
//	 					}
//	 				}
//	 				
//	 				/*fprintf(stdout,"sql_tables: %s\n",sql_tables);
//	 				fprintf(stdout,"sql_columns: %s\n",sql_columns);
//	 				fprintf(stdout,"sql_where: %s\n",sql_where);
//	 				fprintf(stdout,"sql_sorting: %s\n",sql_sorting);*/
//	 				
//	 				/* print out the sql statement */
//	 				if(strcmp(sql_where,"") == 0) {
//	 					fprintf(stdout,"SELECT %s FROM %s %s\n",sql_columns,sql_tables,sql_sorting);
//	 				} else {
//	 					fprintf(stdout,"SELECT %s FROM %s WHERE %s
//	%s\n",sql_columns,sql_tables,sql_where,sql_sorting);
//	 				}
//	 						
//	 				mdb_free_tabledef(table);
//	 			}
//	 		} else {
//	 			fprintf(stderr,"Couldn"t locate the specified query: %s\n",argv[optind+1]);
//	 		}
//	 	}
//	 
//	 	mdb_close(mdb);
//	 	mdb_free_handle(mdb);
//	 	mdb_exit();
//	 	
//	 	if(delimiter) free(delimiter);
//	 
//	 	exit(0);
//	 }
//	 
//	 /**************************************************** 	
//	 		mdb_list_queries
//	 		Description: 	This function prints the list of queries to stdout
//	 		Parameters:	MdbHandle *mdb (handle for the current database)
//	 								int line_break (whether or not to place a line break between each query)
//	 								char *delimiter (delimiter when not using a line break)
//	 		Returns:			nothing
//	 ****************************************************/
//	 void mdb_list_queries(MdbHandle *mdb, int line_break, char *delimiter) {
//	 	int i;
//	 	MdbCatalogEntry *entry;
//	 	
//	  	/* loop over each entry in the catalog */
//	  	for (i=0; i < mdb->num_catalog; i++) {
//	 		entry = g_ptr_array_index(mdb->catalog, i);
//	 
//	      	/* if it"s a query */
//	      	if (entry->object_type == MDB_QUERY) {
//	        		if (line_break) 
//	 				fprintf (stdout, "%s\n", entry->object_name);
//	 			else if (delimiter) 
//	 				fprintf (stdout, "%s%s", entry->object_name, delimiter);
//	 			else 
//	 				fprintf (stdout, "%s ", entry->object_name);
//	 		}
//	 	}
//	 	if (!line_break) 
//	 		fprintf (stdout, "\n");
//	 }
//	 
//	 /**************************************************** 	
//	 		mdb_get_query_id
//	 		Description: 	This function returns the id of the passed query
//	 		Parameters:	MdbHandle *mdb (handle for the current database)
//	 								char *query (name of the desired query to retrieve)
//	 		Returns:			char * (id of the current query)
//	 ****************************************************/
//	 char * mdb_get_query_id(MdbHandle *mdb, char *query) {
//	 	int i;
//	 	MdbCatalogEntry *entry;
//	 	MdbTableDef *table;
//	 	static char id[256];
//	 	char name[256];
//	 	
//	  	/* loop over each entry in the catalog */
//	  	for (i=0; i < mdb->num_catalog; i++) {
//	 		entry = g_ptr_array_index(mdb->catalog, i);
//	 
//	 		if(strcmp(entry->object_name,"MSysObjects") == 0) {
//	 			break;
//	 		}
//	 	}
//	 	
//	 	table = mdb_read_table(entry);
//	 
//	 	if(table) {
//	 		mdb_read_columns(table);
//	 
//	 		mdb_bind_column(table, 1, id);
//	 		mdb_bind_column(table, 3, name);
//	 
//	 		mdb_rewind_table(table);
//	 
//	 		while (mdb_fetch_row(table)) {
//	 			if(strcmp(query,name) == 0) {
//	 				break;
//	 			}
//	 		}
//	 		mdb_free_tabledef(table);
//	 	}
//	 	
//	 	return(id);
//	 }
//	 
//	 
//	 
