Exemplo n.º 1
0
static void
sql_favorite_modify_mitem_cb (G_GNUC_UNUSED GtkMenuItem *mitem, QueryConsolePage *tconsole)
{
	TFavorites *tfav;
	TFavoritesAttributes fav;
	GError *error = NULL;

	memset (&fav, 0, sizeof (fav));
	fav.id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (mitem), "favid"));
	fav.type = T_FAVORITES_QUERIES;
	fav.contents = query_editor_get_all_text (tconsole->priv->editor);
	fav.name = g_object_get_data (G_OBJECT (mitem), "favname");

	tfav = t_connection_get_favorites (tconsole->priv->tcnc);

	if (! t_favorites_add (tfav, 0, &fav, ORDER_KEY_QUERIES, G_MAXINT, &error)) {
		ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tconsole),
			       _("Could not add favorite: %s"),
			       error && error->message ? error->message : _("No detail"));
                if (error)
                        g_error_free (error);
	}
	g_free (fav.contents);
}
Exemplo n.º 2
0
static gboolean
prop_save_timeout (QueryFavoriteSelector *tsel)
{
	TFavorites *bfav;
	TFavoritesAttributes fav;
	GError *error = NULL;
	gboolean allok, actiondel = TRUE;

	bfav = t_connection_get_favorites (tsel->priv->tcnc);

	memset (&fav, 0, sizeof (TFavoritesAttributes));
	fav.id = tsel->priv->properties_id;
	fav.type = T_FAVORITES_QUERIES;
	fav.name = (gchar*) gtk_entry_get_text (GTK_ENTRY (tsel->priv->properties_name));
	fav.descr = NULL;
	fav.contents = query_editor_get_all_text (QUERY_EDITOR (tsel->priv->properties_text));

	allok = t_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES,
				 tsel->priv->properties_position, &error);
	if (! allok) {
		ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
			       _("Could not add favorite: %s"),
			       error && error->message ? error->message : _("No detail"));
		if (error)
			g_error_free (error);
	}
	g_free (fav.contents);

	if (allok && (fav.id >= 0)) {
		gboolean is_action;
		gint qid = fav.id;
		is_action = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tsel->priv->properties_action));
		if (is_action) {
			fav.id = -1;
			fav.type = T_FAVORITES_ACTIONS;
			fav.name = (gchar*) gtk_entry_get_text (GTK_ENTRY (tsel->priv->properties_name));
			fav.descr = NULL;
			fav.contents = g_strdup_printf ("QUERY%d", qid);
			allok = t_favorites_add (bfav, 0, &fav, -1,
						 tsel->priv->properties_position, &error);
			if (! allok) {
				ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
					       _("Could not add action: %s"),
					       error && error->message ? error->message : _("No detail"));
				if (error)
					g_error_free (error);
			}
			else
				actiondel = FALSE;
			/*g_print ("ACTION_ADDED %d: %s\n", fav.id, fav.contents);*/
			g_free (fav.contents);
		}
	}

	if (actiondel && (tsel->priv->properties_id >= 0)) {
		/* remove action */
		gint id;
		gchar *tmp;
		tmp = g_strdup_printf ("QUERY%d", tsel->priv->properties_id);
		id = t_favorites_find (bfav, 0, tmp, &fav, NULL);
		if (id >= 0) {
			t_favorites_delete (bfav, 0, &fav, NULL);
			/*g_print ("ACTION_DELETED %d: %s\n", fav.id, tmp);*/
		}
		g_free (tmp);
	}

	tsel->priv->prop_save_timeout = 0;
	return FALSE; /* remove timeout */
}
Exemplo n.º 3
0
static void
execute_action_mitem_cb (GtkMenuItem *menuitem, UiFormGrid *formgrid)
{
	TFavoritesAction *act;
	GtkWidget *dlg;
	gchar *tmp;
	gint response;
	GtkWidget *toplevel;

	act = (TFavoritesAction*) g_object_get_data (G_OBJECT (menuitem), "action");
	toplevel = gtk_widget_get_toplevel ((GtkWidget*) formgrid);
	tmp = g_strdup_printf (_("Set or confirm the parameters to execute\n"
				 "action '%s'"), act->name);
	dlg = gdaui_basic_form_new_in_dialog (act->params,
					      (GtkWindow*) toplevel,
					      _("Execution of action"), tmp);
	g_free (tmp);
	response = gtk_dialog_run (GTK_DIALOG (dlg));
	gtk_widget_destroy (dlg);
	if (response == GTK_RESPONSE_ACCEPT) {
                GError *lerror = NULL;
		TConnection *tcnc;
		
		tcnc = get_t_connection (formgrid);
		g_assert (tcnc);

		GObject *result;
		result = t_connection_execute_statement (tcnc, act->stmt, act->params,
                                                               GDA_STATEMENT_MODEL_RANDOM_ACCESS, NULL,
							       &lerror);
		if (result && GDA_IS_DATA_MODEL (result)) {
			GtkWidget *dialog, *label, *fg;
			GtkWidget *dcontents;
			gchar *tmp;
			dialog = gtk_dialog_new_with_buttons (act->name, NULL, 0,
							      _("_Close"), GTK_RESPONSE_CLOSE, NULL);
			dcontents = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
			gtk_box_set_spacing (GTK_BOX (dcontents), 5);
			gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE, TRUE);

			tmp = g_markup_printf_escaped ("<b>%s:</b>", act->name);
			label = gtk_label_new ("");
			gtk_label_set_markup (GTK_LABEL (label), tmp);
			g_free (tmp);
			gtk_widget_set_halign (label, GTK_ALIGN_START);
			gtk_box_pack_start (GTK_BOX (dcontents), label, FALSE, FALSE, 5);

			fg = ui_formgrid_new (GDA_DATA_MODEL (result), TRUE,
					      GDAUI_DATA_PROXY_INFO_CURRENT_ROW);
			ui_formgrid_set_connection (UI_FORMGRID (fg), tcnc);

			ActionExecutedData *aed;
			aed = g_new0 (ActionExecutedData, 1);
			aed->formgrid = g_object_ref (formgrid);
			aed->tcnc = g_object_ref (tcnc);
			if (act->name)
				aed->name = g_strdup (act->name);
			aed->stmt = g_object_ref (act->stmt);
			aed->params = g_object_ref (act->params);

			if (GDA_IS_DATA_SELECT (result)) {
				GdaStatement *stmt;
				g_object_get (G_OBJECT (result), "select-stmt", &stmt, NULL);
				if (stmt) {
					ui_formgrid_handle_user_prefs (UI_FORMGRID (fg), NULL, stmt);
					g_object_unref (stmt);
				}
				aed->model = g_object_ref (result);
				g_signal_connect (aed->params, "holder-changed",
						  G_CALLBACK (action_executed_holder_changed_cb), aed);

				aed->formgrid = g_object_ref (fg);
				aed->formgrid->priv->autoupdate_possible = TRUE;
				gtk_widget_show (aed->formgrid->priv->autoupdate_toggle);
			}
			gtk_box_pack_start (GTK_BOX (dcontents), fg, TRUE, TRUE, 0);

			gtk_window_set_default_size (GTK_WINDOW (dialog), 400, 600);
			gtk_widget_show_all (dialog);

			g_signal_connect (dialog, "response",
					  G_CALLBACK (gtk_widget_destroy), NULL);
			g_signal_connect (dialog, "close",
					  G_CALLBACK (gtk_widget_destroy), NULL);
			g_object_set_data_full (G_OBJECT (dialog), "aed", aed,
						(GDestroyNotify) action_executed_data_free);
		}
		else if (result) {
			if (BROWSER_IS_WINDOW (toplevel)) {
				browser_window_show_notice_printf (BROWSER_WINDOW (toplevel),
								   GTK_MESSAGE_INFO,
								   "ActionExecution",
								   "%s", _("Action successfully executed"));
			}
			else
				ui_show_message (GTK_WINDOW (toplevel),
						 "%s", _("Action successfully executed"));
			g_object_unref (result);
		}
		else {
                        ui_show_error (GTK_WINDOW (toplevel),
				       _("Error executing query: %s"),
				       lerror && lerror->message ? lerror->message : _("No detail"));
                        g_clear_error (&lerror);
                }
	}
}
Exemplo n.º 4
0
static void
actually_execute (QueryConsolePage *tconsole, const gchar *sql, GdaSet *params,
		  gboolean add_editor_history)
{
	GdaBatch *batch;
	GError *error = NULL;
	const gchar *remain;

	/* if a query is being executed, then show an error */
	if (tconsole->priv->currently_executing) {
		ui_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
			       _("A query is already being executed, "
				 "to execute another query, open a new connection."));
		return;
	}
	tconsole->priv->currently_executing = TRUE;

	if (!tconsole->priv->parser)
		tconsole->priv->parser = t_connection_create_parser (tconsole->priv->tcnc);

	batch = gda_sql_parser_parse_string_as_batch (tconsole->priv->parser, sql, &remain, &error);
	if (!batch) {
		ui_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
			       _("Error while parsing code: %s"),
			       error && error->message ? error->message : _("No detail"));
		g_clear_error (&error);
		return;
	}

	if (add_editor_history) {
		/* mark the current SQL to be kept by the editor as an internal history */
		query_editor_keep_current_state (tconsole->priv->editor);
	}

	/* actual Execution */
	const GSList *stmt_list, *list;
	GTimeVal start_time;
	g_get_current_time (&start_time);

	QueryEditorHistoryBatch *hist_batch;
	hist_batch = query_editor_history_batch_new (start_time, params);
	query_editor_start_history_batch (tconsole->priv->history, hist_batch);
	query_editor_history_batch_unref (hist_batch);

	gboolean within_transaction;
	stmt_list = gda_batch_get_statements (batch);
	for (list = stmt_list; list; list = list->next) {
		GdaStatement *stmt;
		GObject *result;
		GError *lerror = NULL;
		within_transaction = t_connection_get_transaction_status (tconsole->priv->tcnc) ? TRUE : FALSE;
		stmt = GDA_STATEMENT (list->data);
		result = t_connection_execute_statement (tconsole->priv->tcnc, stmt, params,
							 GDA_STATEMENT_MODEL_RANDOM_ACCESS,
							 NULL, &lerror);
		if (result) {
			QueryEditorHistoryItem *history;
			GdaSqlStatement *sqlst;
			g_object_get (G_OBJECT (stmt), "structure", &sqlst, NULL);
			if (!sqlst->sql) {
				gchar *sql;
				sql = gda_statement_to_sql (stmt, NULL, NULL);
				history = query_editor_history_item_new (sql, result, lerror);
				g_free (sql);
			}
			else
				history = query_editor_history_item_new (sqlst->sql, result, lerror);
			g_object_unref (result);
			gda_sql_statement_free (sqlst);
			
			history->within_transaction = within_transaction;

			/* display a message if a transaction has been started */
			if (! history->within_transaction &&
			    t_connection_get_transaction_status (tconsole->priv->tcnc) &&
			    gda_statement_get_statement_type (stmt) != GDA_SQL_STATEMENT_BEGIN) {
				browser_window_show_notice_printf (BROWSER_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
								   GTK_MESSAGE_INFO,
								   "QueryExecTransactionStarted",
								   "%s", _("A transaction has automatically been started\n"
									   "during this statement's execution, this usually\n"
									   "happens when blobs are selected (and the transaction\n"
									   "will have to remain opened while the blobs are still\n"
									   "accessible, clear the corresponding history item before\n"
									   "closing the transaction)."));
			}

			query_editor_add_history_item (tconsole->priv->history, history);
			query_editor_history_item_unref (history);

			browser_window_push_status (BROWSER_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
						    "QueryConsolePage", _("Statement executed"), TRUE);			
		}
		else {
			ui_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
				       _("Error executing query:\n%s"),
				       lerror && lerror->message ? lerror->message : _("No detail"));
			g_clear_error (&lerror);
			break;
		}
	}
	g_object_unref (batch);
	tconsole->priv->currently_executing = FALSE;
}