Skip to content

Commit

Permalink
select * from table;
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwyanxin committed Nov 6, 2017
1 parent fc469b9 commit cf5fe47
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,12 @@ public List<Map<String, String>> readDatas(File dataFile) {
return dataMapList;
}

public List<Map<String, String>> read() {
//索引文件#########

return readDatas(dataFile);
}


private void writeDatas(File dataFile, List<Map<String, String>> datas) {
if (dataFile.exists()) {
Expand Down
25 changes: 23 additions & 2 deletions src/test.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ public static void main(String[] args) {
Pattern patternUpdate=Pattern.compile("update\\s(\\w+)\\sset\\s(\\w+\\s?=\\s?[^,\\s]+(?:\\s?,\\s?\\w+\\s?=\\s?[^,\\s]+)*)(?:\\swhere\\s(\\w+\\s?[<=>]\\s?[^\\s\\;]+(?:\\sand\\s(?:\\w+)\\s?(?:[<=>])\\s?(?:[^\\s\\;]+))*))?\\s?;");
Matcher matcherUpdate = patternUpdate.matcher(cmd);



Pattern patternDropTable=Pattern.compile("drop\\stable\\s(\\w+);");
Matcher matcherDropTable = patternDropTable.matcher(cmd);

Pattern patternSelect=Pattern.compile("select\\s(\\*|(?:(?:\\w+(?:\\.\\w+)?)+(?:\\s?,\\s?\\w+)*))\\sfrom\\s(\\w+(?:\\s?,\\s?\\w+)*)(?:\\swhere\\s([^\\;]+))?\\s?;");
Matcher matcherSelect = patternSelect.matcher(cmd);

while (matcherAlterTable_add.find()) {
String tableName = matcherAlterTable_add.group(1);
String propertys = matcherAlterTable_add.group(2);
Expand Down Expand Up @@ -215,6 +216,26 @@ public static void main(String[] args) {
}
table.insert(data);
}

while (matcherSelect.find()) {
if ("*".equals(matcherSelect.group(1))&&null==matcherSelect.group(3)) {
//暂定一个表并且没有条件,之后重写
String tableName = matcherSelect.group(2);
Table table = Table.getTable(tableName);
List<Map<String, String>> datas = table.read();
Map<String, Field> fieldMap = table.getFieldMap();
for (String fieldName : fieldMap.keySet()) {
System.out.printf("\t|\t%s", fieldName);
}
System.out.println();
for (Map<String, String> data : datas) {
for (String fieldValue : data.values()) {
System.out.printf("\t|\t%s",fieldValue);
}
System.out.println();
}
}
}
}

/*Table table1 = Table.getTable("table1");
Expand Down

0 comments on commit cf5fe47

Please sign in to comment.