public override bool Check(string query) { var arguments = InsertUtils.GetArgumentsFromQuery(query); var tableName = InsertUtils.GetTableNameFromQuery(query); var columns = InsertUtils.GetColumnsFromArguments(arguments).ToArray(); var values = arguments[2].Split(",").Select(x => x.Trim()).ToArray(); var columnProperties = _database.GetTable(tableName).GetColumnProperties(); for (var i = 0; i < columns.Count(); i++) { if (GeneralUtils.ContainsForbiddenCharacters(values[i])) { throw new ForbiddenCharactersException(values[i]); } var type = columnProperties.First(x => x.Name == columns[i]).Type; if (!GeneralUtils.IsTypeValid(type, values[i])) { throw new InvalidColumnTypeException(columns[i], type); } } return(this.CheckNext(query)); }
public void GetValuesKeywordFromArguments_ShouldReturnValidKeyword(string query) { var actual = InsertUtils.GetValuesKeywordFromArguments(InsertUtils.GetArgumentsFromQuery(query)); var expected = "VALUES"; Assert.Equal(expected, actual); }
public void GetTableNameFromQuery_ShouldReturnValidTableName(string query) { var actual = InsertUtils.GetTableNameFromQuery(query); var expected = "users"; Assert.Equal(expected, actual); }
public void GetArgumentsFromQuery_ShouldReturnValidStringArray(string query) { var actual = InsertUtils.GetArgumentsFromQuery(query); var expected = new string[3] { "INSERT INTO users", "email, phoneNumber) VALUES", "\"[email protected]\", 703503);" }; Assert.Equal(expected, actual); }
public override bool Check(string query) { var tableName = InsertUtils.GetTableNameFromQuery(query); if (!_database.GetTableNames().Contains(tableName)) { throw new TableNotFoundException(tableName); } return(this.CheckNext(query)); }
public void GetValuesFromArguments_ShouldReturnValidValues(string query) { var actual = InsertUtils.GetValuesFromArguments(InsertUtils.GetArgumentsFromQuery(query)).ToArray(); var expected = new string[] { "\"[email protected]\"", "703503", "true" }; Assert.Equal(expected, actual); }
public void GetColumnsFromArguments_ShouldReturnValidColumns(string query) { var actual = InsertUtils.GetColumnsFromArguments(InsertUtils.GetArgumentsFromQuery(query)).ToArray(); var expected = new string[] { "email", "phoneNumber", "isAdult" }; Assert.Equal(expected, actual); }
private void InsertRow(string query) { var arguments = InsertUtils.GetArgumentsFromQuery(query.Substring(0, query.Length - 2)); var tableName = InsertUtils.GetTableNameFromQuery(query); var columnNames = InsertUtils.GetColumnsFromArguments(arguments).ToList(); var values = InsertUtils.GetValuesFromArguments(arguments).Select(x => GeneralUtils.TransformStringValueToRealValue(x)).ToList(); var record = new Record(columnNames, values); this._database.GetTable(tableName).AddRecord(record); }
public override bool Check(string query) { var arguments = InsertUtils.GetArgumentsFromQuery(query); var columns = InsertUtils.GetColumnsFromArguments(arguments); var values = InsertUtils.GetValuesFromArguments(arguments); if (columns.Count() != values.Count()) { throw new MalformedColumnsException(); } return(this.CheckNext(query)); }
public override bool Check(string query) { var arguments = InsertUtils.GetArgumentsFromQuery(query); var tableName = InsertUtils.GetTableNameFromQuery(query); var actualColumnNumber = InsertUtils.GetColumnsFromArguments(arguments).Count(); var expectedColumnNumber = _database.GetTable(tableName).GetColumnProperties().Count(); if (actualColumnNumber != expectedColumnNumber) { throw new InvalidColumnNumberException(actualColumnNumber, expectedColumnNumber); } return(this.CheckNext(query)); }
public override bool Check(string query) { var arguments = InsertUtils.GetArgumentsFromQuery(query); if (arguments.Length != 3) { throw new MalformedArgumentsException(); } var valuesKeyword = InsertUtils.GetValuesKeywordFromArguments(arguments); if (valuesKeyword != "VALUES") { throw new MalformedArgumentsException(); } return(this.CheckNext(query)); }
public override bool Check(string query) { var arguments = InsertUtils.GetArgumentsFromQuery(query); var tableName = InsertUtils.GetTableNameFromQuery(query); var queryColumns = InsertUtils.GetColumnsFromArguments(arguments); var databaseColumns = _database.GetTable(tableName).GetColumnProperties().Select(x => x.Name).ToArray(); foreach (var column in queryColumns) { if (!databaseColumns.Contains(column)) { throw new UnknownColumnNameException(column); } } return(this.CheckNext(query)); }