myTinySQL v0.2.0-2-g5000098
A tiny SQL interpreter over fixed-width text files
Loading...
Searching...
No Matches
Functions
Output.hpp File Reference

Turning statement results into console text or JSON for the browser page. More...

#include <string>
#include <string_view>
#include <vector>
#include "Catalog.hpp"
#include "Session.hpp"

Go to the source code of this file.

Functions

std::string tinysql::renderText (const StatementResult &result)
 Formats one result for the console.
 
std::string tinysql::renderJson (const std::vector< StatementResult > &results)
 Builds the JSON answer of POST /api/sql: one object per statement that has something to show.
 
std::string tinysql::renderTablesJson (const std::vector< TableSchema > &tables)
 Builds the JSON answer of GET /api/tables: every table with its columns.
 

Detailed Description

Turning statement results into console text or JSON for the browser page.

Definition in file Output.hpp.

Function Documentation

◆ renderJson()

std::string tinysql::renderJson ( const std::vector< StatementResult > &  results)

Builds the JSON answer of POST /api/sql: one object per statement that has something to show.

Example: {"results":[{"sql":"DELETE FROM EMPLOY WHERE ID = 3","ok":true,"message":"1 row deleted from EMPLOY", "table":"EMPLOY"}]}. A SELECT or DESCRIBE also has "columns" (name, width in the data file, and whether the browser may edit the cell), "rows" (arrays of strings) and "idColumn" (index of the ID, or null).

Parameters
resultsThe results of a script, in order; silent ones (COLUMN, comments) are left out.
Returns
The JSON text.

Definition at line 95 of file Output.cpp.

◆ renderTablesJson()

std::string tinysql::renderTablesJson ( const std::vector< TableSchema > &  tables)

Builds the JSON answer of GET /api/tables: every table with its columns.

Example: {"tables":[{"name":"EMPLOY","readOnly":false,"autoId":true,"columns":[{"name":"ID","width":10},...]}]}. readOnly is true for SYSTEM_TABLE, which the page must not change.

Parameters
tablesThe tables, from Catalog::tables().
Returns
The JSON text.

Definition at line 131 of file Output.cpp.

◆ renderText()

std::string tinysql::renderText ( const StatementResult &  result)

Formats one result for the console.

Parameters
resultThe result of one statement.
Returns
An echo of the statement, then a dashed header line and fixed-width rows, a message, or an error; empty for a silent result.

Definition at line 67 of file Output.cpp.