added example of how to use the library

This commit is contained in:
Pedro 2015-12-23 16:47:04 +01:00
parent 8f26c45c01
commit 81d34f823d
4 changed files with 33 additions and 12 deletions

View File

@ -1,23 +1,12 @@
#
# make source (build the source code into build/)
#
# make library
#
#
#
#
# directories # directories
BIN = bin BIN = bin
SRC = src SRC = src
SRCSQL = src/lib/sql
SRCPARSER = src/parser SRCPARSER = src/parser
# files # files
PARSERFILES = $(SRCPARSER)/bison_parser.cpp $(SRCPARSER)/flex_lexer.cpp 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 LIBCPP = $(shell find $(SRC)/ -name '*.cpp' -not -path "$(SRCPARSER)/*") $(SRCPARSER)/bison_parser.cpp $(SRCPARSER)/flex_lexer.cpp
LIBOBJ = $(LIBCPP:%.cpp=%.o) LIBOBJ = $(LIBCPP:%.cpp=%.o)
LIBHEADERS = $(shell find $(SRCSQL)/ -name '*.h') $(SRC)/SQLParser.h
TESTCPP = $(shell find test/lib/ -name '*.cpp') TESTCPP = $(shell find test/lib/ -name '*.cpp')
# compile & link flages # compile & link flages
@ -70,4 +59,4 @@ $(BIN)/sql_grammar_test: library
@mkdir -p $(BIN)/ @mkdir -p $(BIN)/
$(CC) $(CTESTFLAGS) test/sql_grammar_test.cpp -o $(BIN)/sql_grammar_test -lsqlparser $(CC) $(CTESTFLAGS) test/sql_grammar_test.cpp -o $(BIN)/sql_grammar_test -lsqlparser
FORCE:

1
example/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
example

7
example/Makefile Normal file
View File

@ -0,0 +1,7 @@
CC = g++
CFLAGS = -std=c++11 -Wall -I../src/ -L../
all:
$(CC) $(CFLAGS) example.cpp -o example -lsqlparser

24
example/example.cpp Normal file
View File

@ -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;
}