Running a query with sql¶
Running a query with sql¶
1def input_box(prompt, title=None, default=None):
2 """VBScript InputBox equivalent: single-field modal Impact dialog."""
3 dlg = impact.gui.make_dialog(title if title else "Input")
4 field = dlg.fields.add_text(default if default else "", prompt)
5 dlg.add_button(ipDialogButtonType.dbtOk)
6 dlg.add_button(ipDialogButtonType.dbtCancel)
7 if dlg.show_modal(None) == ipDialogButtonType.dbtOk:
8 return field.value
9 return ""
10
11# This example prompts the user for some SQL to search by, opens the browser
12# and performs a query using the specified SQL
13
14# Create a local variable for the impact.gui
15g = impact.gui
16
17# Create a local variable for the output toolbox
18ot = g.output_toolbox
19
20# Clear the output toolbox
21ot.clear()
22
23# Create a local variable for the default SQL to perform
24sql = "D_NAME like 'FEFCO%'"
25
26# Display an input box allowing the user to modify the SQL or cancel the
27# operation
28sql = input_box("Enter SQL to search by:", "SQL Project Search", sql)
29
30# If the user cancelled the operation then the length of 'sql' will be zero
31if len(sql):
32
33 # Add a message to the output toolbox
34 ot.add("Opening browser using sql '" + str(sql) + "'")
35
36 # Open the browser and run the specified query, specify True for the
37 # ExitIfEmpty method parameter so that the browser does not open for queries
38 # that do not return any results
39 g.open_browser_run_query_sql(sql, True)
40
41else:
42
43 # Add a message to the output toolbox
44 ot.add("User cancelled search")