public string GetSQLRepresentation() { Dictionary <string, string> attributes; List <string> keys; string query = ""; switch (_statement) { case Statement.Insert: attributes = _insertModel.GetAttributes(); query += Statement.Insert.GetSQLRepresentation() + Helper.Space.GetSQLRepresentation() + _insertModel.GetTableName(); query += Helper.LParanthesis.GetSQLRepresentation(); foreach (string key in attributes.Keys) { if (!ReferenceEquals(key, attributes.Keys.First())) { query += Helper.Comma.GetSQLRepresentation(); } query += key; } query += Helper.RParanthesis.GetSQLRepresentation(); query += Helper.Space.GetSQLRepresentation() + Helper.Values.GetSQLRepresentation(); query += Helper.LParanthesis.GetSQLRepresentation(); foreach (string val in attributes.Values) { if (!ReferenceEquals(val, attributes.Values.First())) { query += Helper.Comma.GetSQLRepresentation(); } query += val; } query += Helper.RParanthesis.GetSQLRepresentation(); query += Helper.Semicolon.GetSQLRepresentation(); break; case Statement.Update: attributes = _setModel.GetAttributes(); query += Statement.Update.GetSQLRepresentation() + Helper.Space.GetSQLRepresentation() + _setModel.GetTableName() + Helper.Space.GetSQLRepresentation() + Helper.Set.GetSQLRepresentation() + Helper.Space.GetSQLRepresentation(); for (int i = 0; i < attributes.Count; i++) { if (i != 0) { query += Helper.Comma.GetSQLRepresentation(); } query += attributes.ElementAt(i).Key; switch (_setters.ElementAt(i)) { case Helper.Equal: query += Helper.Equal.GetSQLRepresentation(); break; case Helper.Add: query += Helper.Add.GetSQLRepresentation() + Helper.Equal.GetSQLRepresentation(); break; case Helper.Subtract: query += Helper.Subtract.GetSQLRepresentation() + Helper.Equal.GetSQLRepresentation(); break; case Helper.Multiply: query += Helper.Multiply.GetSQLRepresentation() + Helper.Equal.GetSQLRepresentation(); break; case Helper.Divide: query += Helper.Divide.GetSQLRepresentation() + Helper.Equal.GetSQLRepresentation(); break; default: throw new InvalidDBQSetterException(); } query += attributes.ElementAt(i).Value; } if (GetConditionStatus()) { query += Helper.Space.GetSQLRepresentation() + GetConditionSQLRepresentation(); } query += Helper.Semicolon.GetSQLRepresentation(); break; case Statement.Select: keys = _selectModel.GetAttributes().Keys.ToList(); query += Statement.Select.GetSQLRepresentation() + Helper.Space.GetSQLRepresentation(); foreach (string key in keys) { if (!ReferenceEquals(key, keys.First())) { query += Helper.Comma.GetSQLRepresentation(); } query += key; } query += Helper.Space.GetSQLRepresentation() + Clause.From.GetSQLRepresentation() + Helper.Space.GetSQLRepresentation() + _selectModel.GetTableName(); if (GetConditionStatus()) { query += Helper.Space.GetSQLRepresentation() + GetConditionSQLRepresentation(); } query += Helper.Semicolon.GetSQLRepresentation(); break; case Statement.Delete: query += Statement.Delete.GetSQLRepresentation() + Helper.Space.GetSQLRepresentation() + Clause.From.GetSQLRepresentation() + Helper.Space.GetSQLRepresentation() + _deleteModel.GetTableName(); if (GetConditionStatus()) { query += Helper.Space.GetSQLRepresentation() + GetConditionSQLRepresentation(); } query += Helper.Semicolon.GetSQLRepresentation(); break; case Statement.None: default: break; } return(query); }
private bool GetConditionStatus() { return(_conditionModel.GetAttributes().Count > 0); }