-
Notifications
You must be signed in to change notification settings - Fork 251
Add description for quickly running/testing custom SQL statements #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,37 +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` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the library USING There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
3. *(Optional, Recommended)* Run `make install` to copy the library to `/usr/local/lib/` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not yours, but I wouldn't consider it "recommended" to install the library. I would be rather surprised if somebody installs it system-wide. |
||
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); | ||
|
||
if (statement->isType(hsql::kStmtSelect)) { | ||
const auto* select = static_cast<const hsql::SelectStatement*>(statement); | ||
/* ... */ | ||
} | ||
} | ||
} | ||
``` | ||
### Test/Parse 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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
``` | ||
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 = "..."; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To annoy people, I would use auto-to-stick here. 🫣 |
||
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<const hsql::SelectStatement*>(statement); | ||
/* ... */ | ||
} | ||
} | ||
} | ||
``` | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Last line in README: |
||
|
||
Quick Links: | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, well, well ...