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);
|
hsql::SQLParserResult* result = hsql::SQLParser::parseSQLString(query);
|
||||||
|
|
||||||
// check whether the parsing was successful
|
// check whether the parsing was successful
|
||||||
if (result->isValid) {
|
if (result->isValid()) {
|
||||||
printf("Parsed successfully!\n");
|
printf("Parsed successfully!\n");
|
||||||
printf("Number of statements: %lu\n", result->size());
|
printf("Number of statements: %lu\n", result->size());
|
||||||
|
|
||||||
for (hsql::SQLStatement* stmt : result->statements) {
|
for (uint i = 0; i < result->size(); ++i) {
|
||||||
// process the statements...
|
// Print a statement summary.
|
||||||
hsql::printStatementInfo(stmt);
|
hsql::printStatementInfo(result->getStatement(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete result;
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
printf("Invalid SQL!\n");
|
printf("Invalid SQL!\n");
|
||||||
|
delete result;
|
||||||
return -1;
|
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("SelectStatement", numIndent);
|
||||||
inprint("Fields:", numIndent + 1);
|
inprint("Fields:", numIndent + 1);
|
||||||
for (Expr* expr : *stmt->selectList) printExpression(expr, numIndent + 2);
|
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("ImportStatment", numIndent);
|
||||||
inprint(stmt->filePath, numIndent + 1);
|
inprint(stmt->filePath, numIndent + 1);
|
||||||
inprint(stmt->tableName, 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("CreateStatment", numIndent);
|
||||||
inprint(stmt->tableName, numIndent + 1);
|
inprint(stmt->tableName, numIndent + 1);
|
||||||
inprint(stmt->filePath, 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("InsertStatment", numIndent);
|
||||||
inprint(stmt->tableName, numIndent + 1);
|
inprint(stmt->tableName, numIndent + 1);
|
||||||
if (stmt->columns != NULL) {
|
if (stmt->columns != NULL) {
|
||||||
|
@ -186,19 +186,19 @@ namespace hsql {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void printStatementInfo(SQLStatement* stmt) {
|
void printStatementInfo(const SQLStatement* stmt) {
|
||||||
switch (stmt->type()) {
|
switch (stmt->type()) {
|
||||||
case kStmtSelect:
|
case kStmtSelect:
|
||||||
printSelectStatementInfo((SelectStatement*) stmt, 0);
|
printSelectStatementInfo((const SelectStatement*) stmt, 0);
|
||||||
break;
|
break;
|
||||||
case kStmtInsert:
|
case kStmtInsert:
|
||||||
printInsertStatementInfo((InsertStatement*) stmt, 0);
|
printInsertStatementInfo((const InsertStatement*) stmt, 0);
|
||||||
break;
|
break;
|
||||||
case kStmtCreate:
|
case kStmtCreate:
|
||||||
printCreateStatementInfo((CreateStatement*) stmt, 0);
|
printCreateStatementInfo((const CreateStatement*) stmt, 0);
|
||||||
break;
|
break;
|
||||||
case kStmtImport:
|
case kStmtImport:
|
||||||
printImportStatementInfo((ImportStatement*) stmt, 0);
|
printImportStatementInfo((const ImportStatement*) stmt, 0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -5,11 +5,22 @@
|
||||||
|
|
||||||
namespace hsql {
|
namespace hsql {
|
||||||
|
|
||||||
void printStatementInfo(SQLStatement* stmt);
|
// Prints a summary of the given SQLStatement.
|
||||||
void printSelectStatementInfo(SelectStatement* stmt, uintmax_t num_indent);
|
void printStatementInfo(const SQLStatement* stmt);
|
||||||
void printImportStatementInfo(ImportStatement* stmt, uintmax_t num_indent);
|
|
||||||
void printInsertStatementInfo(InsertStatement* stmt, uintmax_t num_indent);
|
// Prints a summary of the given SelectStatement with the given indentation.
|
||||||
void printCreateStatementInfo(CreateStatement* stmt, uintmax_t num_indent);
|
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);
|
void printExpression(Expr* expr, uintmax_t num_indent);
|
||||||
|
|
||||||
} // namespace hsql
|
} // namespace hsql
|
||||||
|
|
Loading…
Reference in New Issue