From 81d34f823d7b3bf2ad18ac5ec48d9c6da5988ac7 Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 23 Dec 2015 16:47:04 +0100 Subject: [PATCH] added example of how to use the library --- Makefile | 13 +------------ example/.gitignore | 1 + example/Makefile | 7 +++++++ example/example.cpp | 24 ++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 example/.gitignore create mode 100644 example/Makefile create mode 100644 example/example.cpp diff --git a/Makefile b/Makefile index 2b8f7be..e2e166c 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,12 @@ -# -# make source (build the source code into build/) -# -# make library -# -# -# -# - # directories BIN = bin SRC = src -SRCSQL = src/lib/sql SRCPARSER = src/parser # files PARSERFILES = $(SRCPARSER)/bison_parser.cpp $(SRCPARSER)/flex_lexer.cpp LIBCPP = $(shell find $(SRC)/ -name '*.cpp' -not -path "$(SRCPARSER)/*") $(SRCPARSER)/bison_parser.cpp $(SRCPARSER)/flex_lexer.cpp LIBOBJ = $(LIBCPP:%.cpp=%.o) -LIBHEADERS = $(shell find $(SRCSQL)/ -name '*.h') $(SRC)/SQLParser.h TESTCPP = $(shell find test/lib/ -name '*.cpp') # compile & link flages @@ -70,4 +59,4 @@ $(BIN)/sql_grammar_test: library @mkdir -p $(BIN)/ $(CC) $(CTESTFLAGS) test/sql_grammar_test.cpp -o $(BIN)/sql_grammar_test -lsqlparser -FORCE: + diff --git a/example/.gitignore b/example/.gitignore new file mode 100644 index 0000000..96236f8 --- /dev/null +++ b/example/.gitignore @@ -0,0 +1 @@ +example \ No newline at end of file diff --git a/example/Makefile b/example/Makefile new file mode 100644 index 0000000..6957afc --- /dev/null +++ b/example/Makefile @@ -0,0 +1,7 @@ + +CC = g++ +CFLAGS = -std=c++11 -Wall -I../src/ -L../ + +all: + $(CC) $(CFLAGS) example.cpp -o example -lsqlparser + diff --git a/example/example.cpp b/example/example.cpp new file mode 100644 index 0000000..66ebb9d --- /dev/null +++ b/example/example.cpp @@ -0,0 +1,24 @@ + +#include "SQLParser.h" + +int main(int argc, char *argv[]) { + if (argc <= 1) { + fprintf(stderr, "Usage: ./example \"SELECT * FROM test;\"\n"); + return -1; + } + + + std::string query = argv[1]; + + hsql::SQLStatementList* stmt_list = hsql::SQLParser::parseSQLString(query); + + if (stmt_list->isValid) { + printf("Parsed successfully!\n"); + printf("Number of statements: %lu\n", stmt_list->numStatements()); + // process the statements... + } else { + printf("Invalid SQL!\n"); + } + + return 0; +} \ No newline at end of file