fix example for recent API changes
This commit is contained in:
parent
2bce9cc154
commit
2890cd368e
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue