From 9aef6dc264b75a60ac6f22b2c855f710358ce369 Mon Sep 17 00:00:00 2001 From: Stefan Halfpap Date: Fri, 21 Jun 2024 13:09:04 +0200 Subject: [PATCH 1/2] Update README.md Add a description for quickly running/testing custom SQL statements --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 25a55d29..e2081f3e 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,18 @@ To use the SQL parser in your own projects you simply have to follow these few s } } ``` + 7. The corresponding `example` executable can be used to test/parse specific custom SQL statements: + + Running, for example, `./example/example "SELECT * FROM test;"` produces: +``` +Parsed successfully! +Number of statements: 1 +SelectStatement + Fields: + * + Sources: + test +``` Quick Links: From 86a8469dcc0f9b09171f2d0afcec5567e488117d Mon Sep 17 00:00:00 2001 From: Stefan Halfpap Date: Wed, 26 Jun 2024 14:25:11 +0200 Subject: [PATCH 2/2] Update README.md Separate build and usage documentation --- README.md | 77 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index e2081f3e..d69483ae 100644 --- a/README.md +++ b/README.md @@ -13,49 +13,58 @@ In March 2015 we've also written a short paper outlining discussing some develop **Note:** You can also find a detailed usage description [here](docs/basic-usage.md). -To use the SQL parser in your own projects you simply have to follow these few steps. + +### Build and Test 1. Download the [latest release here](https://github.com/hyrise/sql-parser/releases) 2. Compile the library `make` to create `libsqlparser.so` 3. *(Optional, Recommended)* Run `make install` to copy the library to `/usr/local/lib/` 4. Run the tests `make test` to make sure everything worked - 5. Include the `SQLParser.h` from `src/` (or from `/usr/local/lib/hsql/` if you installed it) and link the library in your project - 6. Take a look at the [example project here](https://github.com/hyrise/sql-parser/tree/master/example) - -```cpp -#include "hsql/SQLParser.h" - -/* ... */ - -{ - // Basic Usage Example - - const std::string query = "..."; - hsql::SQLParserResult result; - hsql::SQLParser::parse(query, &result); - if (result.isValid() && result.size() > 0) { - const hsql::SQLStatement* statement = result.getStatement(0); +### Test/Parse Custom SQL Statements - if (statement->isType(hsql::kStmtSelect)) { - const auto* select = static_cast(statement); - /* ... */ - } - } -} -``` - 7. The corresponding `example` executable can be used to test/parse specific custom SQL statements: +5. The build `example` executable can be used to test/parse specific custom SQL statements: Running, for example, `./example/example "SELECT * FROM test;"` produces: -``` -Parsed successfully! -Number of statements: 1 -SelectStatement - Fields: - * - Sources: - test -``` + ``` + Parsed successfully! + Number of statements: 1 + SelectStatement + Fields: + * + Sources: + test + ``` + +### Using the SQL Parser in Projects + +5. To use the SQL parser in your own projects, you must include the `SQLParser.h` from `src/` (or from `/usr/local/lib/hsql/` if you installed it) and link the library in your project: + + Take a look at the [example project here](https://github.com/hyrise/sql-parser/tree/master/example) + + ```cpp + #include "hsql/SQLParser.h" + + /* ... */ + + { + // Basic Usage Example + + const std::string query = "..."; + hsql::SQLParserResult result; + hsql::SQLParser::parse(query, &result); + + if (result.isValid() && result.size() > 0) { + const hsql::SQLStatement* statement = result.getStatement(0); + + if (statement->isType(hsql::kStmtSelect)) { + const auto* select = static_cast(statement); + /* ... */ + } + } + } + ``` + Quick Links: