public override bool Check(string query) { var tableName = CreateUtils.GetTableNameFromQuery(query); if (!Regex.IsMatch(tableName, @"^[a-zA-Z]+$")) { throw new ForbiddenTableNameException(tableName); } if (_database.GetTableNames().Contains(tableName)) { throw new TableAlreadyExistsException(tableName); } return(this.CheckNext(query)); }
private void CreateTable(string query) { var arguments = CreateUtils.GetArgumentsFromQuery(query.Remove(query.Length - 2)); var tableName = CreateUtils.GetTableNameFromQuery(query); var columns = CreateUtils.GetColumnsFromArguments(arguments); var table = new Table(tableName); foreach (var element in columns) { var column = new Column(new Properties(element[0], element[1])); table.AddColumn(column); } this._database.AddTable(table); }
public void GetTableNameFromQuery_ShouldReturnValidTableName(string query, string expectedTableName) { var actual = CreateUtils.GetTableNameFromQuery(query); Assert.Equal(actual, expectedTableName); }