Skip to content

Commit a51e599

Browse files
committed
fixed select, where still wip
1 parent 875c145 commit a51e599

File tree

4 files changed

+48
-146
lines changed

4 files changed

+48
-146
lines changed

.idea/uiDesigner.xml

Lines changed: 0 additions & 124 deletions
This file was deleted.

ExceptionFramework/src/main/java/edu/upvictoria/poo/Analyzer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ public Analyzer(){
3333
keywords.add("FROM");
3434
keywords.add("WHERE");
3535

36-
dataModifiers.add("NULL");
3736
dataModifiers.add("AND");
3837
dataModifiers.add("OR");
39-
dataModifiers.add("NOT");
4038
dataModifiers.add("AS");
4139

4240
constraints.add("NOT NULL");
@@ -186,6 +184,10 @@ public ArrayList<String> getConstraints() {
186184
return constraints;
187185
}
188186

187+
public ArrayList<String> getDataModifiers() {
188+
return dataModifiers;
189+
}
190+
189191
public void refreshDB(File file) throws FileSystemException{
190192
this.database = new Database();
191193
this.database.setDbFile(file);

ExceptionFramework/src/main/java/edu/upvictoria/poo/SQL.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,14 @@ public ArrayList<String> splitInsertionColumns (String line, boolean splittingCo
279279
throw new StringIndexOutOfBoundsException();
280280
}
281281

282-
line = line.substring(line.indexOf("(") + 1,line.indexOf(")"));
282+
line = line.substring(line.indexOf("(") + 1,line.indexOf(")")).trim();
283283

284284
String[] values = line.split(",");
285+
286+
for(int i = 0; i < values.length; i++){
287+
values[i] = values[i].trim();
288+
}
289+
285290
columns.addAll(Arrays.asList(values));
286291

287292
return columns;
@@ -370,7 +375,7 @@ public void handleSelect(String line, String keyword, Database database) throws
370375
selectedColumns = cleanedLine.substring(0,cleanedLine.indexOf("FROM")-1).trim();
371376

372377
if(cleanedLine.contains("WHERE")){
373-
selectedTable = cleanedLine.substring(cleanedLine.indexOf("FROM ") + "FROM".length() + 1, cleanedLine.indexOf(" WHERE"));
378+
selectedTable = cleanedLine.substring(cleanedLine.indexOf("FROM ") + "FROM".length() + 1, cleanedLine.indexOf(" WHERE")).trim();
374379
} else {
375380
selectedTable = cleanedLine.substring(cleanedLine.indexOf("FROM ") + "FROM".length() + 1).trim();
376381
}
@@ -390,10 +395,10 @@ public void handleSelect(String line, String keyword, Database database) throws
390395
tableExists = true;
391396

392397
if(!selectedColumns.equals("*")){
393-
for(String tableCol : table.getColumnsName()){
394-
for(String selecCol : columns) {
395-
if(tableCol.equals(selecCol)){
396-
showingCol.add(tableCol);
398+
for(String tableColName : table.getColumnsName()){
399+
for(String selectColName : columns) {
400+
if(tableColName.equals(selectColName)){
401+
showingCol.add(tableColName);
397402
}
398403
}
399404
}
@@ -415,8 +420,12 @@ public void handleSelect(String line, String keyword, Database database) throws
415420
throw new NoSuchFileException("TABLE DOES NOT EXISTS");
416421
}
417422
}
418-
}
419423

424+
public void handleWhere(Analyzer analyzer){
425+
ArrayList<String> dataModifiers = analyzer.getDataModifiers();
426+
}
427+
}
420428

421-
// TODO: CREAR EL WHERE
422-
// TODO: CHECAR EL SELECT
429+
// TODO: COMPROBRAR QUE SE INGRESA UN TIPO DE DATO CORRECTO AL CREAR UN REGISTRO
430+
// TODO: COMPROBRAR QUE NO SE ELIGEN DOS COLUMNAS IGUALES A LAS QUE INGRESAR UN REGISTRO
431+
// TODO: CREAR EL WHERE

ExceptionFramework/src/main/java/edu/upvictoria/poo/Table.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public void writeDataToFile(ArrayList<String> rowData) throws IOException {
185185
public void printData(){
186186
for (ArrayList<Object> datum : data) {
187187
for (Object object : datum) {
188-
System.out.print("| " + object + "\t");
188+
System.out.print("| " + object.toString() + "\t");
189189
}
190190
System.out.println("|");
191191
for (int i = 0; i < datum.size(); i++) {
@@ -196,19 +196,34 @@ public void printData(){
196196
}
197197

198198
public void printData(ArrayList<String> columns) {
199-
ArrayList<Integer> columnIndexes = new ArrayList<>();
200-
for(String column : columns){
201-
int i = data.get(0).indexOf(column);
202-
if (i != -1) {
203-
columnIndexes.add(i);
204-
}
199+
for(String colName : columns){
200+
System.out.print("| " + colName + "\t");
201+
}
202+
System.out.println("|");
203+
for (int i = 0; i < columns.size(); i++) {
204+
System.out.print("+------------");
205205
}
206+
System.out.println("+");
207+
208+
// imprimirmos datos
209+
for (ArrayList<Object> datum : data) {
210+
int j = 0;
211+
for (int i = 0; i < datum.size(); i++) {
212+
if(this.columns.get(i).getName().equals(columns.get(j))){
213+
Object object = datum.get(i);
214+
System.out.print("| " + object.toString() + "\t");
215+
j++;
206216

207-
for(ArrayList<Object> datum : data){
208-
for(int columnIndex : columnIndexes){
209-
System.out.print(datum.get(columnIndex) + " | ");
217+
if(j == columns.size()){
218+
break;
219+
}
220+
}
221+
}
222+
System.out.println("|");
223+
for (int i = 0; i < columns.size(); i++) {
224+
System.out.print("+------------");
210225
}
211-
System.out.println();
226+
System.out.println("+");
212227
}
213228
}
214229

0 commit comments

Comments
 (0)