#include <libgda/libgda.h>
#include <stdio.h>

int 
main(int argc, char ** argv)
{
	gda_init ("bug488860", "0.1", argc, argv);
	
	GdaQuery *query;
	GdaParameterList *plist;
	GError *error = NULL;

	query = gda_query_new_from_sql (NULL, "SELECT symbol_id FROM symbol WHERE symbol.file_defined_id = (SELECT "
					"file_defined_id FROM symbol WHERE symbol = ##thesym)", &error);
	
	if (error)
		g_print ("Parser ERROR: %s\n", error->message);

	plist = gda_query_get_parameter_list (query);
	if (plist) {
		g_print ("-Parameter(s):\n");
		GSList *params;
		for (params = plist->parameters; params; params = params->next) {
			GdaParameter *parameter = GDA_PARAMETER (params->data);
			g_print ("   - name:%s type:%s\n",
				 gda_object_get_name (GDA_OBJECT (parameter)),
				 g_type_name (gda_parameter_get_g_type (parameter)));
		}

		if (g_slist_length (plist->parameters) == 1) {
			gchar *sql;
			gda_parameter_set_value_str (GDA_PARAMETER (plist->parameters->data), "my_symbol");
			sql = gda_renderer_render_as_sql (GDA_RENDERER (query), plist, NULL, 0, NULL);
			g_print ("SQL: %s\n", sql);
			g_free (sql);
		}
		g_object_unref (plist);
	}
	else
		g_print ("-No params!-\n");
	g_object_unref (query);
	
	return EXIT_SUCCESS;
}
