From 2890cd368e3ac70737a526dbd6e6aaeadfdbcacc Mon Sep 17 00:00:00 2001 From: Pedro Flemming Date: Wed, 8 Feb 2017 13:51:50 +0100 Subject: [PATCH] fix example for recent API changes --- example/example.cpp | 12 +++++++----- src/sqlhelper.cpp | 18 +++++++++--------- src/sqlhelper.h | 23 +++++++++++++++++------ 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/example/example.cpp b/example/example.cpp index 008c92e..f17ef7c 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -19,18 +19,20 @@ int main(int argc, char *argv[]) { hsql::SQLParserResult* result = hsql::SQLParser::parseSQLString(query); // check whether the parsing was successful - if (result->isValid) { + if (result->isValid()) { printf("Parsed successfully!\n"); printf("Number of statements: %lu\n", result->size()); - for (hsql::SQLStatement* stmt : result->statements) { - // process the statements... - hsql::printStatementInfo(stmt); + for (uint i = 0; i < result->size(); ++i) { + // Print a statement summary. + hsql::printStatementInfo(result->getStatement(i)); } + delete result; return 0; } else { printf("Invalid SQL!\n"); + delete result; return -1; } -} \ No newline at end of file +} diff --git a/src/sqlhelper.cpp b/src/sqlhelper.cpp index 1361a42..5a47df8 100644 --- a/src/sqlhelper.cpp +++ b/src/sqlhelper.cpp @@ -118,7 +118,7 @@ namespace hsql { } } - void printSelectStatementInfo(SelectStatement* stmt, uintmax_t numIndent) { + void printSelectStatementInfo(const SelectStatement* stmt, uintmax_t numIndent) { inprint("SelectStatement", numIndent); inprint("Fields:", numIndent + 1); for (Expr* expr : *stmt->selectList) printExpression(expr, numIndent + 2); @@ -152,19 +152,19 @@ namespace hsql { - void printImportStatementInfo(ImportStatement* stmt, uintmax_t numIndent) { + void printImportStatementInfo(const ImportStatement* stmt, uintmax_t numIndent) { inprint("ImportStatment", numIndent); inprint(stmt->filePath, numIndent + 1); inprint(stmt->tableName, numIndent + 1); } - void printCreateStatementInfo(CreateStatement* stmt, uintmax_t numIndent) { + void printCreateStatementInfo(const CreateStatement* stmt, uintmax_t numIndent) { inprint("CreateStatment", numIndent); inprint(stmt->tableName, numIndent + 1); inprint(stmt->filePath, numIndent + 1); } - void printInsertStatementInfo(InsertStatement* stmt, uintmax_t numIndent) { + void printInsertStatementInfo(const InsertStatement* stmt, uintmax_t numIndent) { inprint("InsertStatment", numIndent); inprint(stmt->tableName, numIndent + 1); if (stmt->columns != NULL) { @@ -186,19 +186,19 @@ namespace hsql { } } - void printStatementInfo(SQLStatement* stmt) { + void printStatementInfo(const SQLStatement* stmt) { switch (stmt->type()) { case kStmtSelect: - printSelectStatementInfo((SelectStatement*) stmt, 0); + printSelectStatementInfo((const SelectStatement*) stmt, 0); break; case kStmtInsert: - printInsertStatementInfo((InsertStatement*) stmt, 0); + printInsertStatementInfo((const InsertStatement*) stmt, 0); break; case kStmtCreate: - printCreateStatementInfo((CreateStatement*) stmt, 0); + printCreateStatementInfo((const CreateStatement*) stmt, 0); break; case kStmtImport: - printImportStatementInfo((ImportStatement*) stmt, 0); + printImportStatementInfo((const ImportStatement*) stmt, 0); break; default: break; diff --git a/src/sqlhelper.h b/src/sqlhelper.h index f76919f..ea6edd1 100644 --- a/src/sqlhelper.h +++ b/src/sqlhelper.h @@ -5,13 +5,24 @@ namespace hsql { - void printStatementInfo(SQLStatement* stmt); - void printSelectStatementInfo(SelectStatement* stmt, uintmax_t num_indent); - void printImportStatementInfo(ImportStatement* stmt, uintmax_t num_indent); - void printInsertStatementInfo(InsertStatement* stmt, uintmax_t num_indent); - void printCreateStatementInfo(CreateStatement* stmt, uintmax_t num_indent); + // Prints a summary of the given SQLStatement. + void printStatementInfo(const SQLStatement* stmt); + + // Prints a summary of the given SelectStatement with the given indentation. + void printSelectStatementInfo(const SelectStatement* stmt, uintmax_t num_indent); + + // Prints a summary of the given ImportStatement with the given indentation. + void printImportStatementInfo(const ImportStatement* stmt, uintmax_t num_indent); + + // Prints a summary of the given InsertStatement with the given indentation. + void printInsertStatementInfo(const InsertStatement* stmt, uintmax_t num_indent); + + // Prints a summary of the given CreateStatement with the given indentation. + void printCreateStatementInfo(const CreateStatement* stmt, uintmax_t num_indent); + + // Prints a summary of the given Expression with the given indentation. void printExpression(Expr* expr, uintmax_t num_indent); } // namespace hsql -#endif \ No newline at end of file +#endif