add astyle formatting

This commit is contained in:
Pedro 2016-02-27 15:01:06 +01:00
parent 57b8cdd31b
commit 7d1c56d0aa
27 changed files with 928 additions and 851 deletions

3
.gitignore vendored
View File

@ -31,3 +31,6 @@ lib-test/
*.exe *.exe
*.out *.out
*.app *.app
*.cpp.orig
*.h.orig

View File

@ -9,6 +9,9 @@ LIBCPP = $(shell find $(SRC) -name '*.cpp' -not -path "$(SRCPARSER)/*") $(S
LIBOBJ = $(LIBCPP:%.cpp=%.o) LIBOBJ = $(LIBCPP:%.cpp=%.o)
TESTCPP = $(shell find test/lib/ -name '*.cpp') TESTCPP = $(shell find test/lib/ -name '*.cpp')
ALLLIB = $(shell find $(SRC) -name '*.cpp' -not -path "$(SRCPARSER)/*") $(shell find $(SRC) -name '*.h' -not -path "$(SRCPARSER)/*")
ALLTEST = $(shell find test/lib/ -name '*.cpp') $(shell find test/lib/ -name '*.h')
# compile & link flages # compile & link flages
CC = g++ CC = g++
CFLAGS = -std=c++11 -Wall -fPIC CFLAGS = -std=c++11 -Wall -fPIC
@ -48,6 +51,10 @@ cleanall: clean cleanparser
install: install:
cp $(TARGET) $(INSTALL)/lib/$(TARGET) cp $(TARGET) $(INSTALL)/lib/$(TARGET)
format:
astyle --options=astyle.options $(ALLLIB)
astyle --options=astyle.options $(ALLTEST)
############ ############
### Test ### ### Test ###
############ ############
@ -63,5 +70,3 @@ $(BIN)/sql_tests: library
$(BIN)/sql_grammar_test: library $(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

8
astyle.options Normal file
View File

@ -0,0 +1,8 @@
# indentation
--indent=spaces=4
--indent-namespaces
--style=java
--style=attach
-A2

View File

@ -5,11 +5,11 @@
namespace hsql { namespace hsql {
/** /**
* @struct ColumnDefinition * @struct ColumnDefinition
* @brief Represents definition of a table column * @brief Represents definition of a table column
*/ */
struct ColumnDefinition { struct ColumnDefinition {
enum DataType { enum DataType {
TEXT, TEXT,
INT, INT,
@ -26,14 +26,14 @@ struct ColumnDefinition {
char* name; char* name;
DataType type; DataType type;
}; };
/** /**
* @struct CreateStatement * @struct CreateStatement
* @brief Represents "CREATE TABLE students (name TEXT, student_number INTEGER, city TEXT, grade DOUBLE)" * @brief Represents "CREATE TABLE students (name TEXT, student_number INTEGER, city TEXT, grade DOUBLE)"
*/ */
struct CreateStatement : SQLStatement { struct CreateStatement : SQLStatement {
enum CreateType { enum CreateType {
kTable, kTable,
kTableFromTbl, // Hyrise file format kTableFromTbl, // Hyrise file format
@ -60,7 +60,7 @@ struct CreateStatement : SQLStatement {
const char* file_path; const char* file_path;
const char* table_name; const char* table_name;
}; };

View File

@ -6,13 +6,13 @@
namespace hsql { namespace hsql {
/** /**
* @struct DeleteStatement * @struct DeleteStatement
* @brief Represents "DELETE FROM students WHERE grade > 3.0" * @brief Represents "DELETE FROM students WHERE grade > 3.0"
* *
* If expr == NULL => delete all rows (truncate) * If expr == NULL => delete all rows (truncate)
*/ */
struct DeleteStatement : SQLStatement { struct DeleteStatement : SQLStatement {
DeleteStatement() : DeleteStatement() :
SQLStatement(kStmtDelete), SQLStatement(kStmtDelete),
table_name(NULL), table_name(NULL),
@ -26,7 +26,7 @@ struct DeleteStatement : SQLStatement {
char* table_name; char* table_name;
Expr* expr; Expr* expr;
}; };

View File

@ -6,11 +6,11 @@
namespace hsql { namespace hsql {
/** /**
* @struct DropStatement * @struct DropStatement
* @brief Represents "DROP TABLE" * @brief Represents "DROP TABLE"
*/ */
struct DropStatement : SQLStatement { struct DropStatement : SQLStatement {
enum EntityType { enum EntityType {
kTable, kTable,
kSchema, kSchema,
@ -32,7 +32,7 @@ struct DropStatement : SQLStatement {
EntityType type; EntityType type;
const char* name; const char* name;
}; };

View File

@ -6,11 +6,11 @@
namespace hsql { namespace hsql {
/** /**
* @struct ExecuteStatement * @struct ExecuteStatement
* @brief Represents "EXECUTE ins_prep(100, "test", 2.3);" * @brief Represents "EXECUTE ins_prep(100, "test", 2.3);"
*/ */
struct ExecuteStatement : SQLStatement { struct ExecuteStatement : SQLStatement {
ExecuteStatement() : ExecuteStatement() :
SQLStatement(kStmtExecute), SQLStatement(kStmtExecute),
name(NULL), name(NULL),
@ -23,7 +23,7 @@ struct ExecuteStatement : SQLStatement {
const char* name; const char* name;
std::vector<Expr*>* parameters; std::vector<Expr*>* parameters;
}; };

View File

@ -5,98 +5,98 @@
namespace hsql { namespace hsql {
char* substr(const char* source, int from, int to) { char* substr(const char* source, int from, int to) {
int len = to-from; int len = to-from;
char* copy = new char[len+1]; char* copy = new char[len+1];
strncpy(copy, source+from, len); strncpy(copy, source+from, len);
copy[len] = '\0'; copy[len] = '\0';
return copy; return copy;
} }
Expr* Expr::makeOpUnary(OperatorType op, Expr* expr) { Expr* Expr::makeOpUnary(OperatorType op, Expr* expr) {
Expr* e = new Expr(kExprOperator); Expr* e = new Expr(kExprOperator);
e->op_type = op; e->op_type = op;
e->expr = expr; e->expr = expr;
e->expr2 = NULL; e->expr2 = NULL;
return e; return e;
} }
Expr* Expr::makeOpBinary(Expr* expr1, OperatorType op, Expr* expr2) { Expr* Expr::makeOpBinary(Expr* expr1, OperatorType op, Expr* expr2) {
Expr* e = new Expr(kExprOperator); Expr* e = new Expr(kExprOperator);
e->op_type = op; e->op_type = op;
e->op_char = 0; e->op_char = 0;
e->expr = expr1; e->expr = expr1;
e->expr2 = expr2; e->expr2 = expr2;
return e; return e;
} }
Expr* Expr::makeOpBinary(Expr* expr1, char op, Expr* expr2) { Expr* Expr::makeOpBinary(Expr* expr1, char op, Expr* expr2) {
Expr* e = new Expr(kExprOperator); Expr* e = new Expr(kExprOperator);
e->op_type = SIMPLE_OP; e->op_type = SIMPLE_OP;
e->op_char = op; e->op_char = op;
e->expr = expr1; e->expr = expr1;
e->expr2 = expr2; e->expr2 = expr2;
return e; return e;
} }
Expr* Expr::makeLiteral(int64_t val) { Expr* Expr::makeLiteral(int64_t val) {
Expr* e = new Expr(kExprLiteralInt); Expr* e = new Expr(kExprLiteralInt);
e->ival = val; e->ival = val;
return e; return e;
} }
Expr* Expr::makeLiteral(double value) { Expr* Expr::makeLiteral(double value) {
Expr* e = new Expr(kExprLiteralFloat); Expr* e = new Expr(kExprLiteralFloat);
e->fval = value; e->fval = value;
return e; return e;
} }
Expr* Expr::makeLiteral(char* string) { Expr* Expr::makeLiteral(char* string) {
Expr* e = new Expr(kExprLiteralString); Expr* e = new Expr(kExprLiteralString);
e->name = string; e->name = string;
return e; return e;
} }
Expr* Expr::makeColumnRef(char* name) { Expr* Expr::makeColumnRef(char* name) {
Expr* e = new Expr(kExprColumnRef); Expr* e = new Expr(kExprColumnRef);
e->name = name; e->name = name;
return e; return e;
} }
Expr* Expr::makeColumnRef(char* table, char* name) { Expr* Expr::makeColumnRef(char* table, char* name) {
Expr* e = new Expr(kExprColumnRef); Expr* e = new Expr(kExprColumnRef);
e->name = name; e->name = name;
e->table = table; e->table = table;
return e; return e;
} }
Expr* Expr::makeFunctionRef(char* func_name, Expr* expr, bool distinct) { Expr* Expr::makeFunctionRef(char* func_name, Expr* expr, bool distinct) {
Expr* e = new Expr(kExprFunctionRef); Expr* e = new Expr(kExprFunctionRef);
e->name = func_name; e->name = func_name;
e->expr = expr; e->expr = expr;
e->distinct = distinct; e->distinct = distinct;
return e; return e;
} }
Expr* Expr::makePlaceholder(int id) { Expr* Expr::makePlaceholder(int id) {
Expr* e = new Expr(kExprPlaceholder); Expr* e = new Expr(kExprPlaceholder);
e->ival = id; e->ival = id;
return e; return e;
} }
Expr::~Expr() { Expr::~Expr() {
delete expr; delete expr;
delete expr2; delete expr2;
delete name; delete name;
delete table; delete table;
} }
} // namespace hsql } // namespace hsql

View File

@ -7,11 +7,11 @@
namespace hsql { namespace hsql {
// Helper function // Helper function
char* substr(const char* source, int from, int to); char* substr(const char* source, int from, int to);
typedef enum { typedef enum {
kExprLiteralFloat, kExprLiteralFloat,
kExprLiteralString, kExprLiteralString,
kExprLiteralInt, kExprLiteralInt,
@ -20,17 +20,17 @@ typedef enum {
kExprColumnRef, kExprColumnRef,
kExprFunctionRef, kExprFunctionRef,
kExprOperator kExprOperator
} ExprType; } ExprType;
typedef struct Expr Expr; typedef struct Expr Expr;
/** /**
* Represents SQL expressions (i.e. literals, operators, column_refs) * Represents SQL expressions (i.e. literals, operators, column_refs)
* *
* TODO: When destructing a placeholder expression, we might need to alter the placeholder_list * TODO: When destructing a placeholder expression, we might need to alter the placeholder_list
*/ */
struct Expr { struct Expr {
/** /**
* Operator types. These are important for expressions of type kExprOperator * Operator types. These are important for expressions of type kExprOperator
* Trivial types are those that can be described by a single character e.g: * Trivial types are those that can be described by a single character e.g:
@ -87,16 +87,28 @@ struct Expr {
/** /**
* Convenience accessor methods * Convenience accessor methods
*/ */
inline bool isType(ExprType e_type) { return e_type == type; } inline bool isType(ExprType e_type) {
inline bool isLiteral() { return isType(kExprLiteralInt) || isType(kExprLiteralFloat) || isType(kExprLiteralString) || isType(kExprPlaceholder); } return e_type == type;
inline bool hasAlias() { return alias != NULL; } }
inline bool hasTable() { return table != NULL; } inline bool isLiteral() {
return isType(kExprLiteralInt) || isType(kExprLiteralFloat) || isType(kExprLiteralString) || isType(kExprPlaceholder);
}
inline bool hasAlias() {
return alias != NULL;
}
inline bool hasTable() {
return table != NULL;
}
inline char* getName() { inline char* getName() {
if (alias != NULL) return alias; if (alias != NULL) return alias;
else return name; else return name;
} }
inline bool isSimpleOp() { return op_type == SIMPLE_OP; } inline bool isSimpleOp() {
inline bool isSimpleOp(char op) { return isSimpleOp() && op_char == op; } return op_type == SIMPLE_OP;
}
inline bool isSimpleOp(char op) {
return isSimpleOp() && op_char == op;
}
/** /**
@ -115,7 +127,7 @@ struct Expr {
static Expr* makeFunctionRef(char* func_name, Expr* expr, bool distinct); static Expr* makeFunctionRef(char* func_name, Expr* expr, bool distinct);
static Expr* makePlaceholder(int id); static Expr* makePlaceholder(int id);
}; };
// Zero initializes an Expr object and assigns it to a space in the heap // Zero initializes an Expr object and assigns it to a space in the heap
// For Hyrise we still had to put in the explicit NULL constructor // For Hyrise we still had to put in the explicit NULL constructor

View File

@ -8,11 +8,11 @@ namespace hsql {
/** /**
* @struct ImportStatement * @struct ImportStatement
* @brief Represents "IMPORT" * @brief Represents "IMPORT"
*/ */
struct ImportStatement : SQLStatement { struct ImportStatement : SQLStatement {
enum ImportType { enum ImportType {
kImportCSV, kImportCSV,
kImportTbl, // Hyrise file format kImportTbl, // Hyrise file format
@ -34,7 +34,7 @@ struct ImportStatement : SQLStatement {
ImportType type; ImportType type;
const char* file_path; const char* file_path;
const char* table_name; const char* table_name;
}; };

View File

@ -7,11 +7,11 @@
namespace hsql { namespace hsql {
/** /**
* @struct InsertStatement * @struct InsertStatement
* @brief Represents "INSERT INTO students VALUES ('Max', 1112233, 'Musterhausen', 2.3)" * @brief Represents "INSERT INTO students VALUES ('Max', 1112233, 'Musterhausen', 2.3)"
*/ */
struct InsertStatement : SQLStatement { struct InsertStatement : SQLStatement {
enum InsertType { enum InsertType {
kInsertValues, kInsertValues,
kInsertSelect kInsertSelect
@ -37,7 +37,7 @@ struct InsertStatement : SQLStatement {
std::vector<char*>* columns; std::vector<char*>* columns;
std::vector<Expr*>* values; std::vector<Expr*>* values;
SelectStatement* select; SelectStatement* select;
}; };

View File

@ -9,11 +9,11 @@
namespace hsql { namespace hsql {
/** /**
* @struct PrepareStatement * @struct PrepareStatement
* @brief Represents "PREPARE ins_prep: SELECT * FROM t1 WHERE c1 = ? AND c2 = ?" * @brief Represents "PREPARE ins_prep: SELECT * FROM t1 WHERE c1 = ? AND c2 = ?"
*/ */
struct PrepareStatement : SQLStatement { struct PrepareStatement : SQLStatement {
PrepareStatement() : PrepareStatement() :
SQLStatement(kStmtPrepare), SQLStatement(kStmtPrepare),
name(NULL), name(NULL),
@ -45,7 +45,7 @@ struct PrepareStatement : SQLStatement {
const char* name; const char* name;
SQLParserResult* query; SQLParserResult* query;
std::vector<Expr*> placeholders; std::vector<Expr*> placeholders;
}; };

View File

@ -32,7 +32,9 @@ namespace hsql {
virtual ~SQLStatement() {} virtual ~SQLStatement() {}
virtual StatementType type() { return _type; } virtual StatementType type() {
return _type;
}
private: private:
StatementType _type; StatementType _type;

View File

@ -9,18 +9,18 @@ namespace hsql {
/** /**
* @struct OrderDescription * @struct OrderDescription
* @brief Description of the order by clause within a select statement * @brief Description of the order by clause within a select statement
* *
* TODO: hold multiple expressions to be sorted by * TODO: hold multiple expressions to be sorted by
*/ */
typedef enum { typedef enum {
kOrderAsc, kOrderAsc,
kOrderDesc kOrderDesc
} OrderType; } OrderType;
struct OrderDescription { struct OrderDescription {
OrderDescription(OrderType type, Expr* expr) : OrderDescription(OrderType type, Expr* expr) :
type(type), type(type),
expr(expr) {} expr(expr) {}
@ -31,27 +31,27 @@ struct OrderDescription {
OrderType type; OrderType type;
Expr* expr; Expr* expr;
}; };
/** /**
* @struct LimitDescription * @struct LimitDescription
* @brief Description of the limit clause within a select statement * @brief Description of the limit clause within a select statement
*/ */
const int64_t kNoLimit = -1; const int64_t kNoLimit = -1;
const int64_t kNoOffset = -1; const int64_t kNoOffset = -1;
struct LimitDescription { struct LimitDescription {
LimitDescription(int64_t limit, int64_t offset) : LimitDescription(int64_t limit, int64_t offset) :
limit(limit), limit(limit),
offset(offset) {} offset(offset) {}
int64_t limit; int64_t limit;
int64_t offset; int64_t offset;
}; };
/** /**
* @struct GroupByDescription * @struct GroupByDescription
*/ */
struct GroupByDescription { struct GroupByDescription {
GroupByDescription() : GroupByDescription() :
columns(NULL), columns(NULL),
having(NULL) {} having(NULL) {}
@ -63,15 +63,15 @@ struct GroupByDescription {
std::vector<Expr*>* columns; std::vector<Expr*>* columns;
Expr* having; Expr* having;
}; };
/** /**
* @struct SelectStatement * @struct SelectStatement
* @brief Representation of a full select statement. * @brief Representation of a full select statement.
* *
* TODO: add union_order and union_limit * TODO: add union_order and union_limit
*/ */
struct SelectStatement : SQLStatement { struct SelectStatement : SQLStatement {
SelectStatement() : SelectStatement() :
SQLStatement(kStmtSelect), SQLStatement(kStmtSelect),
from_table(NULL), from_table(NULL),
@ -100,7 +100,7 @@ struct SelectStatement : SQLStatement {
SelectStatement* union_select; SelectStatement* union_select;
OrderDescription* order; OrderDescription* order;
LimitDescription* limit; LimitDescription* limit;
}; };
} // namespace hsql } // namespace hsql

View File

@ -7,28 +7,28 @@
namespace hsql { namespace hsql {
struct SelectStatement; struct SelectStatement;
struct JoinDefinition; struct JoinDefinition;
struct TableRef; struct TableRef;
/** /**
* @enum TableRefType * @enum TableRefType
* Types table references * Types table references
*/ */
typedef enum { typedef enum {
kTableName, kTableName,
kTableSelect, kTableSelect,
kTableJoin, kTableJoin,
kTableCrossProduct kTableCrossProduct
} TableRefType; } TableRefType;
/** /**
* @struct TableRef * @struct TableRef
* @brief Holds reference to tables. Can be either table names or a select statement. * @brief Holds reference to tables. Can be either table names or a select statement.
*/ */
struct TableRef { struct TableRef {
TableRef(TableRefType type) : TableRef(TableRefType type) :
type(type), type(type),
schema(NULL), schema(NULL),
@ -54,32 +54,34 @@ struct TableRef {
/** /**
* Convenience accessor methods * Convenience accessor methods
*/ */
inline bool hasSchema() { return schema != NULL; } inline bool hasSchema() {
return schema != NULL;
}
inline char* getName() { inline char* getName() {
if (alias != NULL) return alias; if (alias != NULL) return alias;
else return name; else return name;
} }
}; };
/** /**
* @enum JoinType * @enum JoinType
* Types of joins * Types of joins
*/ */
typedef enum { typedef enum {
kJoinInner, kJoinInner,
kJoinOuter, kJoinOuter,
kJoinLeft, kJoinLeft,
kJoinRight, kJoinRight,
} JoinType; } JoinType;
/** /**
* @struct JoinDefinition * @struct JoinDefinition
* @brief Definition of a join table * @brief Definition of a join table
*/ */
struct JoinDefinition { struct JoinDefinition {
JoinDefinition() : JoinDefinition() :
left(NULL), left(NULL),
right(NULL), right(NULL),
@ -97,7 +99,7 @@ struct JoinDefinition {
Expr* condition; Expr* condition;
JoinType type; JoinType type;
}; };

View File

@ -6,21 +6,21 @@
namespace hsql { namespace hsql {
/** /**
* @struct UpdateClause * @struct UpdateClause
* @brief Represents "column = value" expressions * @brief Represents "column = value" expressions
*/ */
struct UpdateClause { struct UpdateClause {
char* column; char* column;
Expr* value; Expr* value;
}; };
/** /**
* @struct UpdateStatement * @struct UpdateStatement
* @brief Represents "UPDATE" * @brief Represents "UPDATE"
*/ */
struct UpdateStatement : SQLStatement { struct UpdateStatement : SQLStatement {
UpdateStatement() : UpdateStatement() :
SQLStatement(kStmtUpdate), SQLStatement(kStmtUpdate),
table(NULL), table(NULL),
@ -37,7 +37,7 @@ struct UpdateStatement : SQLStatement {
TableRef* table; TableRef* table;
std::vector<UpdateClause*>* updates; std::vector<UpdateClause*>* updates;
Expr* where; Expr* where;
}; };

View File

@ -5,12 +5,12 @@
namespace hsql { namespace hsql {
TableRef::~TableRef() { TableRef::~TableRef() {
delete name; delete name;
delete alias; delete alias;
delete select; delete select;
delete list; delete list;
} }
} // namespace hsql } // namespace hsql

View File

@ -5,17 +5,31 @@
namespace hsql { namespace hsql {
void printOperatorExpression(Expr* expr, uint num_indent); void printOperatorExpression(Expr* expr, uint num_indent);
std::string indent(uint num_indent) { return std::string(num_indent, '\t'); } std::string indent(uint num_indent) {
void inprint(int64_t val, uint num_indent) { printf("%s%ld \n", indent(num_indent).c_str(), val); } return std::string(num_indent, '\t');
void inprint(float val, uint num_indent) { printf("%s%f\n", indent(num_indent).c_str(), val); } }
void inprint(const char* val, uint num_indent) { printf("%s%s\n", indent(num_indent).c_str(), val); } void inprint(int64_t val, uint num_indent) {
void inprint(const char* val, const char* val2, uint num_indent) { printf("%s%s->%s\n", indent(num_indent).c_str(), val, val2); } printf("%s%ld \n", indent(num_indent).c_str(), val);
void inprintC(char val, uint num_indent) { printf("%s%c\n", indent(num_indent).c_str(), val); } }
void inprintU(uint64_t val, uint num_indent) { printf("%s%lu\n", indent(num_indent).c_str(), val); } void inprint(float val, uint num_indent) {
printf("%s%f\n", indent(num_indent).c_str(), val);
}
void inprint(const char* val, uint num_indent) {
printf("%s%s\n", indent(num_indent).c_str(), val);
}
void inprint(const char* val, const char* val2, uint num_indent) {
printf("%s%s->%s\n", indent(num_indent).c_str(), val, val2);
}
void inprintC(char val, uint num_indent) {
printf("%s%c\n", indent(num_indent).c_str(), val);
}
void inprintU(uint64_t val, uint num_indent) {
printf("%s%lu\n", indent(num_indent).c_str(), val);
}
void printTableRefInfo(TableRef* table, uint num_indent) { void printTableRefInfo(TableRef* table, uint num_indent) {
switch (table->type) { switch (table->type) {
case kTableName: case kTableName:
inprint(table->name, num_indent); inprint(table->name, num_indent);
@ -40,40 +54,71 @@ void printTableRefInfo(TableRef* table, uint num_indent) {
inprint("Alias", num_indent+1); inprint("Alias", num_indent+1);
inprint(table->alias, num_indent+2); inprint(table->alias, num_indent+2);
} }
} }
void printOperatorExpression(Expr* expr, uint num_indent) { void printOperatorExpression(Expr* expr, uint num_indent) {
if (expr == NULL) { inprint("null", num_indent); return; } if (expr == NULL) {
inprint("null", num_indent);
return;
}
switch (expr->op_type) { switch (expr->op_type) {
case Expr::SIMPLE_OP: inprintC(expr->op_char, num_indent); break; case Expr::SIMPLE_OP:
case Expr::AND: inprint("AND", num_indent); break; inprintC(expr->op_char, num_indent);
case Expr::OR: inprint("OR", num_indent); break; break;
case Expr::NOT: inprint("NOT", num_indent); break; case Expr::AND:
default: inprintU(expr->op_type, num_indent); break; inprint("AND", num_indent);
break;
case Expr::OR:
inprint("OR", num_indent);
break;
case Expr::NOT:
inprint("NOT", num_indent);
break;
default:
inprintU(expr->op_type, num_indent);
break;
} }
printExpression(expr->expr, num_indent+1); printExpression(expr->expr, num_indent+1);
if (expr->expr2 != NULL) printExpression(expr->expr2, num_indent+1); if (expr->expr2 != NULL) printExpression(expr->expr2, num_indent+1);
} }
void printExpression(Expr* expr, uint num_indent) { void printExpression(Expr* expr, uint num_indent) {
switch (expr->type) { switch (expr->type) {
case kExprStar: inprint("*", num_indent); break; case kExprStar:
case kExprColumnRef: inprint(expr->name, num_indent); break; inprint("*", num_indent);
break;
case kExprColumnRef:
inprint(expr->name, num_indent);
break;
// case kExprTableColumnRef: inprint(expr->table, expr->name, num_indent); break; // case kExprTableColumnRef: inprint(expr->table, expr->name, num_indent); break;
case kExprLiteralFloat: inprint(expr->fval, num_indent); break; case kExprLiteralFloat:
case kExprLiteralInt: inprint(expr->ival, num_indent); break; inprint(expr->fval, num_indent);
case kExprLiteralString: inprint(expr->name, num_indent); break; break;
case kExprFunctionRef: inprint(expr->name, num_indent); inprint(expr->expr->name, num_indent+1); break; case kExprLiteralInt:
case kExprOperator: printOperatorExpression(expr, num_indent); break; inprint(expr->ival, num_indent);
default: fprintf(stderr, "Unrecognized expression type %d\n", expr->type); return; break;
case kExprLiteralString:
inprint(expr->name, num_indent);
break;
case kExprFunctionRef:
inprint(expr->name, num_indent);
inprint(expr->expr->name, num_indent+1);
break;
case kExprOperator:
printOperatorExpression(expr, num_indent);
break;
default:
fprintf(stderr, "Unrecognized expression type %d\n", expr->type);
return;
} }
if (expr->alias != NULL) { if (expr->alias != NULL) {
inprint("Alias", num_indent+1); inprint(expr->alias, num_indent+2); inprint("Alias", num_indent+1);
inprint(expr->alias, num_indent+2);
}
} }
}
void printSelectStatementInfo(SelectStatement* stmt, uint num_indent) { void printSelectStatementInfo(SelectStatement* stmt, uint num_indent) {
inprint("SelectStatement", num_indent); inprint("SelectStatement", num_indent);
inprint("Fields:", num_indent+1); inprint("Fields:", num_indent+1);
for (Expr* expr : *stmt->select_list) printExpression(expr, num_indent+2); for (Expr* expr : *stmt->select_list) printExpression(expr, num_indent+2);
@ -103,23 +148,23 @@ void printSelectStatementInfo(SelectStatement* stmt, uint num_indent) {
inprint("Limit:", num_indent+1); inprint("Limit:", num_indent+1);
inprint(stmt->limit->limit, num_indent+2); inprint(stmt->limit->limit, num_indent+2);
} }
} }
void printImportStatementInfo(ImportStatement* stmt, uint num_indent) { void printImportStatementInfo(ImportStatement* stmt, uint num_indent) {
inprint("ImportStatment", num_indent); inprint("ImportStatment", num_indent);
inprint(stmt->file_path, num_indent+1); inprint(stmt->file_path, num_indent+1);
inprint(stmt->table_name, num_indent+1); inprint(stmt->table_name, num_indent+1);
} }
void printCreateStatementInfo(CreateStatement* stmt, uint num_indent) { void printCreateStatementInfo(CreateStatement* stmt, uint num_indent) {
inprint("CreateStatment", num_indent); inprint("CreateStatment", num_indent);
inprint(stmt->table_name, num_indent+1); inprint(stmt->table_name, num_indent+1);
inprint(stmt->file_path, num_indent+1); inprint(stmt->file_path, num_indent+1);
} }
void printInsertStatementInfo(InsertStatement* stmt, uint num_indent) { void printInsertStatementInfo(InsertStatement* stmt, uint num_indent) {
inprint("InsertStatment", num_indent); inprint("InsertStatment", num_indent);
inprint(stmt->table_name, num_indent+1); inprint(stmt->table_name, num_indent+1);
if (stmt->columns != NULL) { if (stmt->columns != NULL) {
@ -139,9 +184,9 @@ void printInsertStatementInfo(InsertStatement* stmt, uint num_indent) {
printSelectStatementInfo(stmt->select, num_indent+1); printSelectStatementInfo(stmt->select, num_indent+1);
break; break;
} }
} }
void printStatementInfo(SQLStatement* stmt) { void printStatementInfo(SQLStatement* stmt) {
switch (stmt->type()) { switch (stmt->type()) {
case kStmtSelect: case kStmtSelect:
printSelectStatementInfo((SelectStatement*) stmt, 0); printSelectStatementInfo((SelectStatement*) stmt, 0);
@ -158,6 +203,6 @@ void printStatementInfo(SQLStatement* stmt) {
default: default:
break; break;
} }
} }
} // namespace hsql } // namespace hsql