# QueryRunnerBS5

A plugin for the php-webapp-framework project for creating a responsive interface for T-SQL queries.

---

### Query Options

Query options can be specified in the comments of your SQL queries, e.g.

```
-- Title: Report A
-- Description: This is a SQL query that returns the data for Report A.

```

List of options:


* `NoSorting` — Specify this option to disable Datatables sorting
* `Allow` — Specify a list of UserAuth usernames and groups allowed to use and run the report
* `Title` — A title for the query
* `Scale` — Specify the default scale for the text
* `Description` — A brief description of the query
* `Danger` —
* `Warning` —
* `Info` —
* `ButtonLabel` — Change the text of the execute button, e.g. `Delete`
* `ButtonClass` — Change the Bootstrap 5 class of the execute button, e.g. `btn-outline-danger`
* `ButtonIcon` — Change the FontAwesone icon of the execute button, e.g. `fa-trash`

---

### Query Inputs

Designed with Microsoft SQL Server in mind. Here is a typical declare statement:

```
declare @BeginDate datetime = ?;
declare @EndDate datetime = ?;
```

The above creates two date inputs on the page for the user to provide when the query is selected. The question marks tell the PDO prepared statement where to place the user input values. This is done in the order they are provided.

For other languages like MySQL, write the declare statements in a comment like the following:

```
-- declare @BeginDate datetime = ?;
-- declare @EndDate datetime = ?;
```

Other SQL languages will not interpret those lines, but they are read by the software to create input fields for the end user. To use the values, place question marks where each value is needed in the query itself, e.g.:

```
select *
from event_log
where
    begin_date >= ?
and end_date < ?
```

Just be sure that the order of the declare statements (in comments) matches the order of the appearances of the question marks in the query.

---

### Query Input Options

To create a dropdown input for the user to select from a list of values, you can specify the options like the following:

```
declare @Fruit varchar(100) = ?; -- Options: Apple,Orange,Banana
```

The above will allow the user to select from either Apple, Orange, or Banana. The chosen string will be passed as the value. To associate a hidden value with a label, do the following:

```
declare @Fruit varchar(100) = ?; -- Options: Apple=0,Orange=1,Banana=2
```

The above will still allow a user to select a fruit's name from the dropdown, but only one of the corresponding values 0, 1, or 2 will be sent to the query as a `varchar(100)`.
