hana-cli
Version:
HANA Developer Command Line Interface
169 lines (119 loc) • 5.62 kB
Markdown
> Command: `querySimple`
> Category: **Developer Tools**
> Status: Production Ready
Execute any single SQL statement and display or export the results. This command supports SELECT queries (returning result sets), DML statements (INSERT, UPDATE, DELETE — returning rows-affected counts), and DDL statements (CREATE, DROP, ALTER — returning success confirmation). Results can be saved to a file or displayed in the terminal.
## Syntax
```bash
hana-cli querySimple [options]
```
## Aliases
- `qs`
- `querysimple`
## Command Diagram
```mermaid
graph TD
Start([hana-cli querySimple]) --> QueryInput[Specify SQL Statement]
QueryInput --> Profile{Profile Specified?}
Profile -->|Yes| ProfileConn[Use CDS Profile Connection]
Profile -->|No| DefaultConn[Use default-env.json Connection]
ProfileConn --> Connect[Connect to Database]
DefaultConn --> Connect
Connect --> ExecuteSQL[Execute SQL Statement]
ExecuteSQL --> ResultType{Result Type?}
ResultType -->|SELECT result set| Format{Output Format}
ResultType -->|DML rows affected| DMLOutput[Display Rows Affected]
ResultType -->|DDL no result| DDLOutput[Display Success Message]
Format -->|table| TableDisplay[Display as Table<br/>in Terminal]
Format -->|json| JSONFormat[Convert to JSON]
Format -->|excel| ExcelFormat[Convert to Excel]
Format -->|csv| CSVFormat[Convert to CSV]
DMLOutput --> Complete([Complete])
DDLOutput --> Complete
TableDisplay --> Complete
JSONFormat --> Output{File Specified?}
ExcelFormat --> Output
CSVFormat --> Output
Output -->|Yes| WriteFile[Write to File<br/>in Specified Folder]
Output -->|No| DisplayConsole[Display to Console]
WriteFile --> Complete
DisplayConsole --> Complete
style Start fill:
style Complete fill:
style Profile fill:
style Format fill:
style Output fill:
style ResultType fill:
```
| Option | Alias | Type | Default | Description |
|--------|-------|------|---------|-------------|
| `--query` | `-q` | string | - | SQL statement to execute |
| `--folder` | `-f` | string | `./` | Folder path for output file (when saving to file) |
| `--filename` | `-n` | string | - | Output filename (when saving to file) |
| `--output` | `-o` | string | `table` | Output format. Choices: `table`, `json`, `excel`, `csv` |
| `--profile` | `-p` | string | - | CDS Profile for connection |
### Connection Parameters
| Option | Alias | Type | Default | Description |
|--------|-------|------|---------|-------------|
| `--admin` | `-a` | boolean | `false` | Connect via admin (default-env-admin.json) |
| `--conn` | - | string | - | Connection filename to override default-env.json |
### Troubleshooting
| Option | Alias | Type | Default | Description |
|--------|-------|------|---------|-------------|
| `--disableVerbose` | `--quiet` | boolean | `false` | Disable verbose output - removes all extra output that is only helpful to human readable interface |
| `--debug` | `-d` | boolean | `false` | Debug hana-cli itself by adding output of LOTS of intermediate details |
## Output Behavior by Statement Type
| Statement Type | Default Output | JSON Output (`--output json`) |
|---------------|----------------|-------------------------------|
| SELECT | Formatted table | `[{...}, {...}]` (array of row objects) |
| INSERT/UPDATE/DELETE | `Rows affected: N` | `{"rowsAffected": N}` |
| CREATE/DROP/ALTER | `Statement executed successfully` | `{"success": true, "message": "..."}` |
All statement types exit with code 0 on success, making this command safe for scripting and automation.
```bash
hana-cli querySimple --query "SELECT TOP 10 * FROM ORDERS"
hana-cli querySimple --query "SELECT * FROM CUSTOMERS" --output json --quiet
hana-cli querySimple --query "SELECT * FROM SALES" --output csv --folder ./exports --filename sales
hana-cli querySimple --query "SELECT * FROM PRODUCTS" --output excel --folder ./exports --filename products
```
```bash
hana-cli querySimple --query "INSERT INTO CONFIG (KEY, VALUE) VALUES ('timeout', '30')"
hana-cli querySimple --query "UPDATE CONFIG SET VALUE = '60' WHERE KEY = 'timeout'" --output json --quiet
hana-cli querySimple --query "DELETE FROM LOGS WHERE CREATED_AT < ADD_DAYS(CURRENT_DATE, -90)"
```
```bash
hana-cli querySimple --query "CREATE TABLE T1 (ID INT PRIMARY KEY, NAME NVARCHAR(100))" --output json --quiet
hana-cli querySimple --query "DROP TABLE T1"
```
```bash
hana-cli qs --query "SELECT COUNT(*) as TOTAL FROM ORDERS"
```
Same functionality using the short alias `qs`.
See the [Commands Reference](../all-commands.md) for other commands in this category.
- [Category: Developer Tools](..)
- [All Commands A-Z](../all-commands.md)
- [hdbsql](./hdbsql.md) - Launch interactive SQL client
- [callProcedure](./call-procedure.md) - Execute stored procedures