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

The parsed form of every statement, and the functions that build it from text. More...

#include <cstddef>
#include <optional>
#include <string>
#include <string_view>
#include <variant>
#include <vector>

Go to the source code of this file.

Classes

struct  tinysql::SelectItem
 One entry of a SELECT list: *, a column name, or a 'quoted literal' printed on every row. More...
 
struct  tinysql::Condition
 A WHERE <column> <op> <value> test. More...
 
struct  tinysql::SelectStmt
 SELECT <items> FROM <table> [WHERE <condition>]. More...
 
struct  tinysql::InsertStmt
 INSERT INTO <table> VALUES (<values>). More...
 
struct  tinysql::DeleteStmt
 DELETE FROM <table> WHERE <condition>. The WHERE is required, so a table is never emptied by accident. More...
 
struct  tinysql::Assignment
 One <column> = <value> of an UPDATE's SET list. More...
 
struct  tinysql::UpdateStmt
 UPDATE <table> SET <col> = <value>[, ...] WHERE <condition>. The WHERE is required, as for DELETE. More...
 
struct  tinysql::ColumnFormatStmt
 COLUMN <name> FORMAT A<width>: the console display width of a column. More...
 
struct  tinysql::ColumnDefinition
 One column of a CREATE TABLE: <name> CHAR(<width>) or <name> NUMBER(<width>). More...
 
struct  tinysql::CreateTableStmt
 CREATE TABLE <table> (<column> <type>(<width>)[, ...]): adds a table to SYSTEM_TABLE. More...
 
struct  tinysql::DescribeStmt
 DESCRIBE lists the tables; DESCRIBE <table> lists that table's columns. More...
 
struct  tinysql::CommentStmt
 REM ..., -- ..., or an empty line: nothing to run. More...
 

Typedefs

using tinysql::Statement = std::variant< SelectStmt, InsertStmt, UpdateStmt, DeleteStmt, CreateTableStmt, ColumnFormatStmt, DescribeStmt, CommentStmt >
 Any parsed statement: exactly one of the statement types above.
 

Functions

Statement tinysql::parseStatement (std::string_view sql)
 Parses one statement.
 
std::vector< std::string > tinysql::splitStatements (std::string_view script)
 Splits a script into statements.
 

Detailed Description

The parsed form of every statement, and the functions that build it from text.

Definition in file Statement.hpp.

Typedef Documentation

◆ Statement

using tinysql::Statement = typedef std::variant<SelectStmt, InsertStmt, UpdateStmt, DeleteStmt, CreateTableStmt, ColumnFormatStmt, DescribeStmt, CommentStmt>

Any parsed statement: exactly one of the statement types above.

Session::execute() uses std::visit to call the matching run() overload.

Definition at line 96 of file Statement.hpp.

Function Documentation

◆ parseStatement()

Statement tinysql::parseStatement ( std::string_view  sql)

Parses one statement.

Parameters
sqlThe text of one statement; a trailing ; is allowed.
Returns
The parsed statement.
Exceptions
SqlErrorOn a syntax error; the message says what was expected and what was found.

Definition at line 509 of file Parser.cpp.

◆ splitStatements()

std::vector< std::string > tinysql::splitStatements ( std::string_view  script)

Splits a script into statements.

Parameters
scriptAny number of statements: one per line, and ; outside quotes also ends one.
Returns
The statements in order, trimmed; comment lines and empty pieces are left out.

Definition at line 517 of file Parser.cpp.