//UPDATE //columns = PK columns //condition = PK values public Command(MainStatement mainStat, String tableName, DataColumn[] columns, int [] condition, Object value, String updateColumn) { if (tableName == null || columns == null || condition == null || value == null || updateColumn == null) { throw new ArgumentException("None of Command constructor arguments can be null."); } //TODO:length check if (condition.Length == 0) { throw new ArgumentException("Condition primary keys must be provided."); } this.mainStat = mainStat; this.tableName = tableName; this.columns = new List <string>(); for (int i = 0; i < columns.Length; ++i) { this.columns.Add(columns[i].ColumnName); } this.updateColumn = updateColumn; if (columns.Length == 1) { this.condition = singularKeyConditionToString(condition); } else { this.condition = compositeKeyConditionToString(condition); } values = new List <Object>(); this.values.Add(value); }
//TODO: constructor renaming? //DELETE public Command(MainStatement mainStat, String tableName, List <String> columns, int [] condition) { if (tableName == null || columns == null || condition == null) { throw new ArgumentException("None of Command constructor arguments can be null."); } if (columns.Count > condition.Length) { throw new ArgumentException("Number of composite primary key columns cannot exceed the number of provided primary keys."); } if (columns.Count == 0 || condition.Length == 0) { throw new ArgumentException("At least one column name and condition value must be provided."); } this.mainStat = mainStat; this.tableName = tableName; this.columns = columns; if (columns.Count == 1) { this.condition = singularKeyConditionToString(condition); } else { this.condition = compositeKeyConditionToString(condition); } }
//INSERT /** * Creates insert command. Count of columns must be equal to the count of values. * @param mainStat * @param tableName * @param columns * @param values */ public Command(MainStatement mainStat, String tableName, DataColumnCollection columns, List <Object> values) { if (tableName == null || columns == null || values == null) { throw new ArgumentException("None of Command constructor arguments can be null."); } if (columns.Count != values.Count) { throw new ArgumentException("Count of columns must be equal to the count of values."); } if (columns.Count == 0 && values.Count == 0) { throw new ArgumentException("Count of columns and values must be greater than zero."); } this.mainStat = mainStat; this.tableName = tableName; this.columns = new List <string>(); for (int i = 0; i < columns.Count; ++i) { this.columns.Add(columns[i].ColumnName); } this.condition = ""; this.values = values; }
//INSERT /** * Creates insert command. Count of columns must be equal to the count of values. * @param mainStat * @param tableName * @param columns * @param values */ public Command(MainStatement mainStat, String tableName, List <String> columns, List <Object> values) { if (tableName == null || columns == null || values == null) { throw new ArgumentException("None of Command constructor arguments can be null."); } if (columns.Count != values.Count) { throw new ArgumentException("Count of columns must be equal to the count of values."); } if (columns.Count == 0 && values.Count == 0) { throw new ArgumentException("Count of columns and values must be greater than zero."); } this.mainStat = mainStat; this.tableName = tableName; this.columns = columns; this.condition = ""; this.values = values; }