Ejemplo n.º 1
0
/**
 * gda_server_provider_internal_get_parser:
 * @prov: a #GdaServerProvider
 *
 * This is a factory method to get a unique instance of a #GdaSqlParser object
 * for each #GdaServerProvider object
 * Don't unref it.
 *
 * Returns: (transfer none): a #GdaSqlParser
 */
GdaSqlParser *
gda_server_provider_internal_get_parser (GdaServerProvider *prov)
{
	g_return_val_if_fail (GDA_IS_SERVER_PROVIDER (prov), NULL);
	if (prov->priv->parser)
		return prov->priv->parser;
	prov->priv->parser = gda_server_provider_create_parser (prov, NULL);
	if (!prov->priv->parser)
		prov->priv->parser = gda_sql_parser_new ();
	return prov->priv->parser;
}
Ejemplo n.º 2
0
int
main (int argc, char** argv)
{
	gchar *file;
	GError *error = NULL;
	GdaDataModel *model;
	guint i, nrows;
	guint nfailed = 0;
	gda_init ();

	/* generic parser */
	GdaSqlParser *parser;
	parser = gda_sql_parser_new ();
	nfailed += do_a_test (NULL, parser);
	g_object_unref (parser);

	/* test other parsers only if generic one is Ok */
	if (nfailed == 0) {
		model = gda_config_list_providers ();
		nrows = gda_data_model_get_n_rows (model);
		for (i = 0; i < nrows; i++) {
			const GValue *cvalue;
			cvalue = gda_data_model_get_value_at (model, 0, i, NULL);
			g_assert (cvalue && (G_VALUE_TYPE (cvalue) == G_TYPE_STRING));
			if (!g_ascii_strcasecmp (g_value_get_string (cvalue), "Oracle"))
				continue; /* ignore Oracle for now */
			g_print ("Testing database provider '%s'\n", g_value_get_string (cvalue));

			GdaServerProvider *prov;
			prov = gda_config_get_provider (g_value_get_string (cvalue), NULL);
			g_assert (prov);

			GdaSqlParser *parser;
			parser = gda_server_provider_create_parser (prov, NULL);
			if (!parser)
				parser = gda_sql_parser_new ();

			nfailed += do_a_test (prov, parser);
			g_object_unref (parser);
		}
		g_object_unref (model);
	}

	if (nfailed == 0) {
		g_print ("Ok\n");
		return EXIT_SUCCESS;
	}
	else {
		g_print ("%u failed\n", nfailed);
		return EXIT_FAILURE;
	}
}
Ejemplo n.º 3
0
static VALUE parser(VALUE self)
{
    GdaSqlParser * parser;
    GdaServerProvider * pr;

    Data_Get_Struct(self, GdaServerProvider, pr);

    parser = gda_server_provider_create_parser(pr, NULL);

    if (!parser)
	rb_raise(rb_eRuntimeError, "zomglol");

    return Data_Wrap_Struct(cParser, NULL, g_object_unref, parser);
}
Ejemplo n.º 4
0
static GdaSqlParser *
create_parser_for_provider (const gchar *prov_name)
{
	GdaServerProvider *prov;
	GdaSqlParser *parser;
	GError *error = NULL;

	prov = gda_config_get_provider (prov_name, &error);
	if (!prov) 
		g_error ("Could not create provider for '%s': %s\n", prov_name,
			 error && error->message ? error->message : "No detail");

	parser = gda_server_provider_create_parser (prov, NULL);
	if (!parser)
		parser = gda_sql_parser_new ();

	return parser;
}
Ejemplo n.º 5
0
/*
 * Creates an SQLite .db file from the definitions in @sqlfile
 */
gboolean
create_sqlite_db (const gchar *dir, const gchar *dbname, const gchar *sqlfile, GError **error)
{
	GdaBatch *batch;
	GdaSqlParser *parser;
	GdaServerProvider *prov;
	GdaConnection *cnc;

	/* create batch */
	prov = gda_config_get_provider ("SQLite", NULL);
	if (!prov) {
		g_set_error (error, TEST_ERROR, TEST_ERROR_GENERIC, "%s", 
			     "Cannot find the SQLite provider");
		return FALSE;
	}
	parser = gda_server_provider_create_parser (prov, NULL);
	if (!parser)
		parser = gda_sql_parser_new ();
	
	batch = gda_sql_parser_parse_file_as_batch (parser, sqlfile, error);
	g_object_unref (parser);
	if (!batch)
		return FALSE;

	/* clean any previous DB file */
	gchar *fname, *tmp;
	tmp = g_strdup_printf ("%s.db", dbname);
	fname = g_build_filename (dir, tmp, NULL);
	g_free (tmp);
	g_unlink (fname);
	g_free (fname);

	/* open a connection */
	gchar *cnc_string;
	gchar *edir, *edbname;

	edir = gda_rfc1738_encode (dir);
	edbname = gda_rfc1738_encode (dbname);
	cnc_string = g_strdup_printf ("DB_DIR=%s;DB_NAME=%s", edir, edbname);
	g_free (edir);
	g_free (edbname);
	cnc = gda_connection_open_from_string ("SQLite", cnc_string, NULL, 
					       GDA_CONNECTION_OPTIONS_NONE, error);
	g_free (cnc_string);
	if (!cnc) {
		g_object_unref (batch);
		return FALSE;
	}

	/* execute batch */
	GSList *list;
	const GSList *stmt_list;
	gboolean retval = TRUE;
	list = gda_connection_batch_execute (cnc, batch, NULL, GDA_STATEMENT_MODEL_RANDOM_ACCESS, error);
	stmt_list = gda_batch_get_statements (batch);
	if (g_slist_length (list) != g_slist_length ((GSList *) stmt_list))
		retval = FALSE;

	g_slist_foreach (list, (GFunc) g_object_unref, NULL);
	g_slist_free (list);

	g_assert (gda_connection_close (cnc, NULL));
	g_object_unref (cnc);
	g_object_unref (batch);
	return retval;
}
Ejemplo n.º 6
0
static gboolean
report_provider_status (GdaServerProvider *prov, GdaConnection *cnc)
{
	gchar *header_str;
	HtmlFile *file = config->index;
	gboolean is_virt;

	typedef void (*AFunc) (void);
	typedef struct {
		const gchar *name;
		gboolean     should_be;
		void       (*func) (void);
	} ProvFunc;
	GdaServerProviderClass *pclass;

	if (prov && cnc && (prov != gda_connection_get_provider (cnc)))
		/* ignoring connection as it has a different provider */
		return TRUE;
	g_assert (prov || cnc);

	/* section */
	if (cnc)
		header_str = g_strdup_printf ("Report for connection '%s'", gda_connection_get_cnc_string (cnc));
	else
		header_str = g_strdup_printf ("Report for '%s' provider", gda_server_provider_get_name (prov));

	/* provider info */
	if (!prov)
		prov = gda_connection_get_provider (cnc);
	is_virt = GDA_IS_VIRTUAL_PROVIDER (prov);
	pclass = (GdaServerProviderClass*) G_OBJECT_GET_CLASS (prov);
	ProvFunc fa[] = {
		{"get_name", TRUE, (AFunc) pclass->get_name},
		{"get_version", TRUE, (AFunc) pclass->get_version},
		{"get_server_version", TRUE, (AFunc) pclass->get_server_version},
		{"supports_feature", TRUE, (AFunc) pclass->supports_feature},
		{"get_data_handler", TRUE, (AFunc) pclass->get_data_handler},
		{"get_def_dbms_type", TRUE, (AFunc) pclass->get_def_dbms_type},
		{"escape_string", TRUE, (AFunc) pclass->escape_string},
		{"unescape_string", TRUE, (AFunc) pclass->unescape_string},
		{"open_connection", TRUE, (AFunc) pclass->open_connection},
		{"close_connection", TRUE, (AFunc) pclass->close_connection},
		{"supports_operation", is_virt ? FALSE : TRUE, (AFunc) pclass->supports_operation},
		{"create_operation", FALSE, (AFunc) pclass->create_operation},
		{"render_operation", FALSE, (AFunc) pclass->render_operation},
		{"perform_operation", FALSE, (AFunc) pclass->perform_operation},
		{"begin_transaction", FALSE, (AFunc) pclass->begin_transaction},
		{"commit_transaction", FALSE, (AFunc) pclass->commit_transaction},
		{"rollback_transaction", FALSE, (AFunc) pclass->rollback_transaction},
		{"add_savepoint", FALSE, (AFunc) pclass->add_savepoint},
		{"rollback_savepoint", FALSE, (AFunc) pclass->rollback_savepoint},
		{"delete_savepoint", FALSE, (AFunc) pclass->delete_savepoint},
		{"create_parser", FALSE, (AFunc) pclass->create_parser},
		{"statement_to_sql", TRUE, (AFunc) pclass->statement_to_sql},
		{"statement_prepare", TRUE, (AFunc) pclass->statement_prepare},
		{"statement_execute", TRUE, (AFunc) pclass->statement_execute},
		{"identifier_quote", TRUE, (AFunc) pclass->identifier_quote}
	};

	ProvFunc md[] = {
		{"_info", TRUE, (AFunc) pclass->meta_funcs._info},
		{"_btypes", TRUE, (AFunc) pclass->meta_funcs._btypes},
		{"_udt", TRUE, (AFunc) pclass->meta_funcs._udt},
		{"udt", TRUE, (AFunc) pclass->meta_funcs.udt},
		{"_udt_cols", TRUE, (AFunc) pclass->meta_funcs._udt_cols},
		{"udt_cols", TRUE, (AFunc) pclass->meta_funcs.udt_cols},
		{"_enums", TRUE, (AFunc) pclass->meta_funcs._enums},
		{"enums", TRUE, (AFunc) pclass->meta_funcs.enums},
		{"_domains", TRUE, (AFunc) pclass->meta_funcs._domains},
		{"domains", TRUE, (AFunc) pclass->meta_funcs.domains},
		{"_constraints_dom", TRUE, (AFunc) pclass->meta_funcs._constraints_dom},
		{"constraints_dom", TRUE, (AFunc) pclass->meta_funcs.constraints_dom},
		{"_el_types", TRUE, (AFunc) pclass->meta_funcs._el_types},
		{"el_types", TRUE, (AFunc) pclass->meta_funcs.el_types},
		{"_collations", TRUE, (AFunc) pclass->meta_funcs._collations},
		{"collations", TRUE, (AFunc) pclass->meta_funcs.collations},
		{"_character_sets", TRUE, (AFunc) pclass->meta_funcs._character_sets},
		{"character_sets", TRUE, (AFunc) pclass->meta_funcs.character_sets},
		{"_schemata", TRUE, (AFunc) pclass->meta_funcs._schemata},
		{"schemata", TRUE, (AFunc) pclass->meta_funcs.schemata},
		{"_tables_views", TRUE, (AFunc) pclass->meta_funcs._tables_views},
		{"tables_views", TRUE, (AFunc) pclass->meta_funcs.tables_views},
		{"_columns", TRUE, (AFunc) pclass->meta_funcs._columns},
		{"columns", TRUE, (AFunc) pclass->meta_funcs.columns},
		{"_view_cols", TRUE, (AFunc) pclass->meta_funcs._view_cols},
		{"view_cols", TRUE, (AFunc) pclass->meta_funcs.view_cols},
		{"_constraints_tab", TRUE, (AFunc) pclass->meta_funcs._constraints_tab},
		{"constraints_tab", TRUE, (AFunc) pclass->meta_funcs.constraints_tab},
		{"_constraints_ref", TRUE, (AFunc) pclass->meta_funcs._constraints_ref},
		{"constraints_ref", TRUE, (AFunc) pclass->meta_funcs.constraints_ref},
		{"_key_columns", TRUE, (AFunc) pclass->meta_funcs._key_columns},
		{"key_columns", TRUE, (AFunc) pclass->meta_funcs.key_columns},
		{"_check_columns", TRUE, (AFunc) pclass->meta_funcs._check_columns},
		{"check_columns", TRUE, (AFunc) pclass->meta_funcs.check_columns},
		{"_triggers", TRUE, (AFunc) pclass->meta_funcs._triggers},
		{"triggers", TRUE, (AFunc) pclass->meta_funcs.triggers},
		{"_routines", TRUE, (AFunc) pclass->meta_funcs._routines},
		{"routines", TRUE, (AFunc) pclass->meta_funcs.routines},
		{"_routine_col", TRUE, (AFunc) pclass->meta_funcs._routine_col},
		{"routine_col", TRUE, (AFunc) pclass->meta_funcs.routine_col},
		{"_routine_par", TRUE, (AFunc) pclass->meta_funcs._routine_par},
		{"routine_par", TRUE, (AFunc) pclass->meta_funcs.routine_par},
	};
	gboolean has_xa = gda_server_provider_supports_feature (prov, cnc, 
								GDA_CONNECTION_FEATURE_XA_TRANSACTIONS);


	xmlNodePtr table, tr, td, span;
	GdaSqlParser *parser;
	GString *string;
	gsize i;
	GdaProviderInfo *pinfo;

	pinfo = gda_config_get_provider_info (gda_server_provider_get_name (prov));
	g_assert (pinfo);

	table = xmlNewChild (file->body, NULL, BAD_CAST "table", NULL);
	xmlSetProp (table, BAD_CAST "width", BAD_CAST "100%");
	tr = xmlNewChild (table, NULL, BAD_CAST "tr", NULL);
	td = xmlNewTextChild (tr, NULL, BAD_CAST "th", BAD_CAST header_str);
	xmlSetProp (td, BAD_CAST "colspan", BAD_CAST  "4");

	/* line 1 */
	tr = xmlNewChild (table, NULL, BAD_CAST "tr", NULL);
	xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "Provider's name:");
	td = xmlNewTextChild (tr, NULL, BAD_CAST "td", BAD_CAST gda_server_provider_get_name (prov));
	xmlSetProp (td, BAD_CAST "width", (xmlChar*) "35%");
	xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "Provider is virtual:");
	td = xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST (is_virt ? "Yes (uses the SQLite engine)" : "No"));
	xmlSetProp (td, BAD_CAST "width", (xmlChar*) "35%");

	/* line 2 */
	tr = xmlNewChild (table, NULL, BAD_CAST "tr", NULL);
	xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "Provider's version:");
	xmlNewTextChild (tr, NULL, BAD_CAST "td", BAD_CAST gda_server_provider_get_version (prov));
	xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "Provider's server version:");
	xmlNewTextChild (tr, NULL, BAD_CAST "td",
			 BAD_CAST (cnc ? gda_server_provider_get_server_version (prov, cnc) : "(non connected)"));

	/* line 3 */
	tr = xmlNewChild (table, NULL, BAD_CAST "tr", NULL);
	xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "Provider's description:");
	xmlNewTextChild (tr, NULL, BAD_CAST "td", BAD_CAST pinfo->description);
	xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "Filename:");
	xmlNewTextChild (tr, NULL, BAD_CAST "td", BAD_CAST pinfo->location);

	/* line 4 */
	parser = gda_server_provider_create_parser (prov, cnc);
	tr = xmlNewChild (table, NULL, BAD_CAST "tr", NULL);
	xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "Creates its own SQL parser:");
	xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST (parser ? "Yes" : "No"));
	if (parser)
		g_object_unref (parser);
	xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "Non implemented base methods:");
	span = NULL;
	td = xmlNewChild (tr, NULL, BAD_CAST "td", NULL);
	for (i = 0; i < sizeof (fa) / sizeof (ProvFunc); i++) {
		gchar *str;
		ProvFunc *pf = &(fa[i]);

		if (pf->func)
			continue;

		if (span)
			str = g_strdup_printf (", %s()", pf->name);
		else
			str = g_strdup_printf ("%s()", pf->name);
		span = xmlNewTextChild (td, NULL, BAD_CAST "span", BAD_CAST str);
		g_free (str);
		if (pf->should_be)
			xmlSetProp (span, BAD_CAST "class", BAD_CAST "error");
	}
	if (!span)
		xmlNodeSetContent (td, BAD_CAST "---");

	/* line 5 */
	tr = xmlNewChild (table, NULL, BAD_CAST "tr", NULL);
	xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "Non implemented meta data methods:");
	span = NULL;
	td = xmlNewChild (tr, NULL, BAD_CAST "td", NULL);
	for (i = 0; i < sizeof (md) / sizeof (ProvFunc); i++) {
		gchar *str;
		ProvFunc *pf = &(md[i]);

		if (pf->func)
			continue;

		if (span)
			str = g_strdup_printf (", %s()", pf->name);
		else
			str = g_strdup_printf ("%s()", pf->name);
		span = xmlNewTextChild (td, NULL, BAD_CAST "span", BAD_CAST str);
		g_free (str);
		if (pf->should_be)
			xmlSetProp (span, BAD_CAST "class", BAD_CAST "error");
	}
	if (!span)
		xmlNodeSetContent (td, BAD_CAST "---");

	xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "Non implemented XA transactions:");
	if (pclass->xa_funcs) {
		if (!has_xa) {
			td = xmlNewChild (tr, NULL, BAD_CAST "td", 
					  BAD_CAST "The provider has the 'xa_funcs' part but "
					  "reports that distributed transactions are "
					  "not supported.");
			xmlSetProp (td, BAD_CAST "class", BAD_CAST "warning");
		}
		else {
			ProvFunc dt[] = {
				{"xa_start", TRUE, (AFunc) pclass->xa_funcs->xa_start},
				{"xa_end", FALSE, (AFunc) pclass->xa_funcs->xa_end},
				{"xa_prepare", TRUE, (AFunc) pclass->xa_funcs->xa_prepare},
				{"xa_commit", TRUE, (AFunc) pclass->xa_funcs->xa_commit},
				{"xa_rollback", TRUE, (AFunc) pclass->xa_funcs->xa_rollback},
				{"xa_recover", TRUE, (AFunc) pclass->xa_funcs->xa_recover},
			};
			span = NULL;
			td = xmlNewChild (tr, NULL, BAD_CAST "td", NULL);
			for (i = 0; i < sizeof (dt) / sizeof (ProvFunc); i++) {
				gchar *str;
				ProvFunc *pf = &(dt[i]);
					
				if (pf->func)
					continue;
					
				if (span)
					str = g_strdup_printf (", %s()", pf->name);
				else
					str = g_strdup_printf ("%s()", pf->name);
				span = xmlNewTextChild (td, NULL, BAD_CAST "span", BAD_CAST str);
				g_free (str);
				if (pf->should_be)
					xmlSetProp (span, BAD_CAST "class", BAD_CAST "error");
			}
			if (!span)
				xmlNodeSetContent (td, BAD_CAST "---");
		}
	}
	else {
		if (has_xa) {
			td = xmlNewTextChild (tr, NULL, BAD_CAST "td",
					   BAD_CAST "The provider does not have the 'xa_funcs' part but "
					  "reports that distributed transactions are "
					  "supported.");
			xmlSetProp (td, BAD_CAST "class", BAD_CAST "warning");
		}
		else
			xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "---");
	}	

	/* line 6 */
	tr = xmlNewChild (table, NULL, BAD_CAST "tr", NULL);
	xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "Connection's parameters:");
	if (pinfo->dsn_params && pinfo->dsn_params->holders) {
		GSList *list;
		td = xmlNewChild (tr, NULL, BAD_CAST "td", NULL);
		for (list = pinfo->dsn_params->holders; list; list = list->next) {
			gchar *str, *descr;
			GdaHolder *holder = GDA_HOLDER (list->data);
			g_object_get (G_OBJECT (holder), "description", &descr, NULL);
			if (descr)
				str = g_strdup_printf ("%s: %s", gda_holder_get_id (holder), descr);
			else
				str = g_strdup (gda_holder_get_id (holder));
			g_free (descr);
			xmlNewTextChild (td, NULL, BAD_CAST "div", BAD_CAST str);
			g_free (str);
		}
	}
	else {
		td = xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "None provided");
		xmlSetProp (td, BAD_CAST "class", BAD_CAST "error");
	}
	xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "Authentication's parameters:");
	if (pinfo->auth_params) {
		GSList *list;
		if (pinfo->auth_params->holders) {
			td = xmlNewChild (tr, NULL, BAD_CAST "td", NULL);
			for (list = pinfo->auth_params->holders; list; list = list->next) {
				gchar *str, *descr;
				GdaHolder *holder = GDA_HOLDER (list->data);
				g_object_get (G_OBJECT (holder), "description", &descr, NULL);
				if (descr)
					str = g_strdup_printf ("%s: %s", gda_holder_get_id (holder), descr);
				else
					str = g_strdup (gda_holder_get_id (holder));
				g_free (descr);
				xmlNewTextChild (td, NULL, BAD_CAST "div", BAD_CAST str);
				g_free (str);
			}
		}
		else
			td = xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "None required");
	}
	else {
		td = xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "None provided");
		xmlSetProp (td, BAD_CAST "class", BAD_CAST "error");
	}

	/* line 7 */
	GdaConnectionFeature f;
	string = NULL;
	tr = xmlNewChild (table, NULL, BAD_CAST "tr", NULL);
	xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "Supported features:");
	for (f = 0; f < GDA_CONNECTION_FEATURE_LAST; f++) {
		if (gda_server_provider_supports_feature (prov, cnc, f)) {
			GEnumValue *ev;
			
			ev = g_enum_get_value ((GEnumClass *) g_type_class_ref (GDA_TYPE_CONNECTION_FEATURE), f);
			if (!string)
				string = g_string_new (ev->value_name);
			else
				g_string_append_printf (string, ", %s", ev->value_name);
		}
	}
	if (string) {
		xmlNewTextChild (tr, NULL, BAD_CAST "td", BAD_CAST string->str);
		g_string_free (string, TRUE);
	}
	else
		xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "---");

	string = NULL;
	xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "Unsupported features:");
	for (f = 0; f < GDA_CONNECTION_FEATURE_LAST; f++) {
		if (!gda_server_provider_supports_feature (prov, cnc, f)) {
			GEnumValue *ev;
			
			ev = g_enum_get_value ((GEnumClass *) g_type_class_ref (GDA_TYPE_CONNECTION_FEATURE), f);
			if (!string)
				string = g_string_new (ev->value_name);
			else
				g_string_append_printf (string, ", %s", ev->value_name);
		}
	}
	if (string) {
		xmlNewTextChild (tr, NULL, BAD_CAST "td", BAD_CAST string->str);
		g_string_free (string, TRUE);
	}
	else
		xmlNewChild (tr, NULL, BAD_CAST "td", BAD_CAST "---");
		
	g_free (header_str);

	return TRUE;
}