Skip to content

Commit 4d40870

Browse files
committed
Merge branch 'FranciscoDA-queryParams'
2 parents 5454d8d + be5c1a4 commit 4d40870

File tree

7 files changed

+329
-28
lines changed

7 files changed

+329
-28
lines changed

src/Layouts/Views/Query.vala

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class Sequeler.Layouts.Views.Query : Gtk.Grid {
4545

4646
public Gtk.Paned panels;
4747
public Sequeler.Partials.TreeBuilder result_data;
48+
public Sequeler.Widgets.QueryParamsDialog? params_dialog { get; set; default = null; }
4849

4950
public signal void update_tab_indicator (bool status);
5051

@@ -292,17 +293,9 @@ public class Sequeler.Layouts.Views.Query : Gtk.Grid {
292293
}
293294

294295
public Gtk.Button build_run_button () {
295-
run_button = new Gtk.Button.with_label (_("Run Query"));
296-
run_button.get_style_context ().add_class ("suggested-action");
297-
run_button.get_style_context ().add_class ("notebook-temp-fix");
298-
run_button.always_show_image = true;
299-
run_button.image = new Gtk.Image.from_icon_name ("media-playback-start-symbolic", Gtk.IconSize.BUTTON);
300-
run_button.image.valign = Gtk.Align.CENTER;
301-
run_button.can_focus = false;
302-
run_button.margin = 10;
303-
run_button.sensitive = false;
304-
run_button.tooltip_markup = Granite.markup_accel_tooltip ({"<Control>Return"}, _("Run Query"));
305-
run_button.action_name = Services.ActionManager.ACTION_PREFIX + Services.ActionManager.ACTION_RUN_QUERY;
296+
run_button = new Sequeler.Partials.RunQueryButton ();
297+
run_button.action_name = Services.ActionManager.ACTION_PREFIX
298+
+ Services.ActionManager.ACTION_RUN_QUERY;
306299

307300
return run_button;
308301
}
@@ -396,6 +389,38 @@ public class Sequeler.Layouts.Views.Query : Gtk.Grid {
396389
}
397390

398391
public void run_query (string query) {
392+
Gda.Statement statement;
393+
Gda.Set params;
394+
try {
395+
statement = window.main.connection_manager.parse_sql_string (query, out params);
396+
} catch (GLib.Error ex) {
397+
on_query_error (ex.message);
398+
return;
399+
}
400+
401+
if (statement == null || params == null) {
402+
run_query_statement (query, statement, null);
403+
return;
404+
}
405+
406+
for (int i = 0; ; i++) {
407+
var holder = params.get_nth_holder (i);
408+
if (holder == null) {
409+
break;
410+
}
411+
debug ("holder #%d is %s type: %s", i, holder.get_id (), holder.get_g_type ().name ());
412+
}
413+
414+
params_dialog = new Sequeler.Widgets.QueryParamsDialog (window, this, query, statement, params);
415+
params_dialog.set_modal (true);
416+
params_dialog.show_all ();
417+
418+
params_dialog.destroy.connect (() => {
419+
params_dialog = null;
420+
});
421+
}
422+
423+
public void run_query_statement (string query, Gda.Statement statement, Gda.Set? params) {
399424
toggle_loading_msg (true);
400425
spinner.start ();
401426

@@ -405,22 +430,22 @@ public class Sequeler.Layouts.Views.Query : Gtk.Grid {
405430
var explain_pos = query.down ().index_of ("explain", 0);
406431

407432
if (select_pos == 0 || show_pos == 0 || pragma_pos == 0 || explain_pos == 0) {
408-
select_statement.begin (query, (obj, res) => {
433+
select_statement.begin (statement, params, (obj, res) => {
409434
handle_select_response (select_statement.end (res));
410435
});
411436
} else {
412-
non_select_statement.begin (query, (obj, res) => {
437+
non_select_statement.begin (statement, params, (obj, res) => {
413438
handle_query_response (non_select_statement.end (res));
414439
});
415440
}
416441
}
417442

418-
private async Gee.HashMap<Gda.DataModel?, string> select_statement (string query) {
419-
return yield window.main.connection_manager.init_silent_select_query (query);
443+
private async Gee.HashMap<Gda.DataModel?, string> select_statement (Gda.Statement statement, Gda.Set? params) {
444+
return yield window.main.connection_manager.init_silent_select_statement (statement, params);
420445
}
421446

422-
public async Gee.HashMap<string?, string> non_select_statement (string query) {
423-
return yield window.main.connection_manager.init_silent_query (query);
447+
public async Gee.HashMap<string?, string> non_select_statement (Gda.Statement statement, Gda.Set? params) {
448+
return yield window.main.connection_manager.init_silent_statement (statement, params);
424449
}
425450

426451
public void handle_select_response (Gee.HashMap<Gda.DataModel?, string> response) {

src/Partials/Helpers.vala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,30 @@ namespace Sequeler.Partials {
124124
});
125125
}
126126
}
127+
128+
public class RunQueryButton : Gtk.Button {
129+
public RunQueryButton () {
130+
set_label (_("Run Query"));
131+
get_style_context ().add_class ("suggested-action");
132+
get_style_context ().add_class ("notebook-temp-fix");
133+
always_show_image = true;
134+
image = new Gtk.Image.from_icon_name ("media-playback-start-symbolic", Gtk.IconSize.BUTTON);
135+
image.valign = Gtk.Align.CENTER;
136+
tooltip_markup = Granite.markup_accel_tooltip ({"<Control>Return"}, _("Run Query"));
137+
}
138+
}
139+
140+
public class ParamEntry : Gtk.Entry {
141+
public ParamEntry (Widgets.QueryParamsDialog dialog, Gtk.InputPurpose? purpose = null) {
142+
hexpand = true;
143+
144+
if (purpose != null) {
145+
set_input_purpose (purpose);
146+
}
147+
148+
activate.connect (() => {
149+
dialog.run_query ();
150+
});
151+
}
152+
}
127153
}

src/Services/ActionManager.vala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,14 @@ public class Sequeler.Services.ActionManager : Object {
145145
return;
146146
}
147147

148-
var query = (window.main.database_view.query.current.page as Layouts.Views.Query).get_text ().strip ();
148+
var page = (window.main.database_view.query.current.page as Layouts.Views.Query);
149+
var query = page.get_text ().strip ();
149150

150151
if (query == "") {
151152
return;
152153
}
153154

154-
(window.main.database_view.query.current.page as Layouts.Views.Query).run_query (query);
155+
page.run_query (query);
155156
}
156157

157158
public static void action_from_group (string action_name, ActionGroup? action_group) {

src/Services/ConnectionManager.vala

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,13 @@ public class Sequeler.Services.ConnectionManager : Object {
438438
return connection.execute_non_select_command (query);
439439
}
440440

441-
public async string run_silent_query (string query) throws Error requires (connection.is_opened ()) {
442-
var result = connection.execute_non_select_command (query);
441+
public async string run_silent_statement (Gda.Statement statement, Gda.Set? params) throws Error requires (connection.is_opened ()) {
442+
var result = connection.statement_execute_non_select (statement, params, null);
443443
return result.to_string ();
444444
}
445+
public Gda.DataModel? run_silent_select_statement (Gda.Statement statement, Gda.Set? params) throws Error requires (connection.is_opened ()) {
446+
return connection.statement_execute_select (statement, params);
447+
}
445448

446449
public Gda.DataModel? run_select (string query) throws Error {
447450
return connection.execute_select_command (query);
@@ -477,6 +480,10 @@ public class Sequeler.Services.ConnectionManager : Object {
477480
return output;
478481
}
479482

483+
public Gda.Statement parse_sql_string (string sql, out Gda.Set @params) throws Error {
484+
return connection.parse_sql_string (sql, out params);
485+
}
486+
480487
public async Gda.DataModel? init_select_query (string query) {
481488
Gda.DataModel? result = null;
482489
var error = "";
@@ -505,15 +512,15 @@ public class Sequeler.Services.ConnectionManager : Object {
505512
return result;
506513
}
507514

508-
public async Gee.HashMap<Gda.DataModel?, string> init_silent_select_query (string query) {
515+
public async Gee.HashMap<Gda.DataModel?, string> init_silent_select_statement (Gda.Statement statement, Gda.Set? params) {
509516
var result = new Gee.HashMap<Gda.DataModel?, string> ();
510517
Gda.DataModel? data = null;
511518
var error = "";
512519

513-
SourceFunc callback = init_silent_select_query.callback;
520+
SourceFunc callback = init_silent_select_statement.callback;
514521
new Thread <void*> (null, () => {
515522
try {
516-
data = run_select (query);
523+
data = run_silent_select_statement (statement, params);
517524
} catch (Error e) {
518525
error = e.message;
519526
data = null;
@@ -548,13 +555,13 @@ public class Sequeler.Services.ConnectionManager : Object {
548555
return result;
549556
}
550557

551-
public async Gee.HashMap<string?, string> init_silent_query (string query) {
558+
public async Gee.HashMap<string?, string> init_silent_statement (Gda.Statement statement, Gda.Set? params) {
552559
var result = new Gee.HashMap<string?, string> ();
553560
string? data = null;
554561
var error = "";
555562

556563
try {
557-
data = yield run_silent_query (query);
564+
data = yield run_silent_statement (statement, params);
558565
} catch (Error e) {
559566
error = e.message;
560567
}

src/Widgets/ConnectionDialog.vala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2018 Alecaddd (http://alecaddd.com)
2+
* Copyright (c) 2017-2020 Alecaddd (https://alecaddd.com)
33
*
44
* This program is free software; you can redistribute it and/or
55
* modify it under the terms of the GNU General Public
@@ -8,7 +8,7 @@
88
*
99
* This program is distributed in the hope that it will be useful,
1010
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1212
* General Public License for more details.
1313
*
1414
* You should have received a copy of the GNU General Public

0 commit comments

Comments
 (0)