Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 46 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, well, well ...

image

2. Compile the library `make` to create `libsqlparser.so`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the library USING make ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.so is linux-only. Just say "to create the library?

3. *(Optional, Recommended)* Run `make install` to copy the library to `/usr/local/lib/`
Copy link
Contributor

Choose a reason for hiding this comment

The 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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse_simple_statement as the binary name? Any ideas?

```
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 = "...";
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
/* ... */
}
}
}
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last line in README: HYRISE > Hyrise


Quick Links:

Expand Down
Loading