added example of how to use the library
This commit is contained in:
parent
8f26c45c01
commit
81d34f823d
13
Makefile
13
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:
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
example
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
CC = g++
|
||||
CFLAGS = -std=c++11 -Wall -I../src/ -L../
|
||||
|
||||
all:
|
||||
$(CC) $(CFLAGS) example.cpp -o example -lsqlparser
|
||||
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue