diff --git a/dist/Databases/x/yahia.xml b/dist/Databases/a/y.xml similarity index 68% rename from dist/Databases/x/yahia.xml rename to dist/Databases/a/y.xml index 99b148a..937c286 100644 --- a/dist/Databases/x/yahia.xml +++ b/dist/Databases/a/y.xml @@ -1,5 +1,4 @@ - yahia-15
diff --git a/dist/Databases/x/yahia.xsd b/dist/Databases/a/y.xsd similarity index 65% rename from dist/Databases/x/yahia.xsd rename to dist/Databases/a/y.xsd index 9ab453a..4d08528 100644 --- a/dist/Databases/x/yahia.xsd +++ b/dist/Databases/a/y.xsd @@ -1,12 +1,5 @@ - - - - - - - @@ -16,7 +9,6 @@ - diff --git a/dist/JDBC-API.jar b/dist/JDBC-API.jar index 3a5c7be..b149347 100644 Binary files a/dist/JDBC-API.jar and b/dist/JDBC-API.jar differ diff --git a/dist/JDBCLibrary.jar b/dist/Library/JDBC-API.jar similarity index 90% rename from dist/JDBCLibrary.jar rename to dist/Library/JDBC-API.jar index aae3d78..4ad1a9a 100644 Binary files a/dist/JDBCLibrary.jar and b/dist/Library/JDBC-API.jar differ diff --git a/dist/Log.txt b/dist/Log.txt index a6ad46e..f57b340 100644 --- a/dist/Log.txt +++ b/dist/Log.txt @@ -1,94 +1,27 @@ -[ FINER ] 12\07\2019 , 15:20 : Connection Initiated -[ FINER ] 12\07\2019 , 15:20 : Statement Created -[ SEVERE ] 12\07\2019 , 15:20 : Use Query failed! -[ FINE ] 12\07\2019 , 15:20 : Connection Closed -[ FINE ] 12\07\2019 , 15:20 : Statement Closed -[ FINER ] 12\07\2019 , 15:20 : Connection Initiated -[ FINER ] 12\07\2019 , 15:20 : Statement Created -[ FINE ] 12\07\2019 , 15:20 : Connection Closed -[ FINE ] 12\07\2019 , 15:20 : Statement Closed -[ FINER ] 12\07\2019 , 15:20 : Connection Initiated -[ FINER ] 12\07\2019 , 15:20 : Statement Created -[ FINE ] 12\07\2019 , 15:20 : Connection Closed -[ FINE ] 12\07\2019 , 15:20 : Statement Closed -[ FINER ] 12\07\2019 , 15:20 : Connection Initiated -[ FINER ] 12\07\2019 , 15:20 : Statement Created -[ FINE ] 12\07\2019 , 15:20 : Connection Closed -[ FINE ] 12\07\2019 , 15:20 : Statement Closed -[ FINER ] 12\07\2019 , 15:20 : Connection Initiated -[ FINER ] 12\07\2019 , 15:20 : Statement Created -[ FINE ] 12\07\2019 , 15:20 : Select Query executed -[ FINE ] 12\07\2019 , 15:20 : Connection Closed -[ FINE ] 12\07\2019 , 15:20 : Statement Closed -[ FINER ] 12\07\2019 , 15:20 : Connection Initiated -[ FINER ] 12\07\2019 , 15:20 : Statement Created -[ FINE ] 12\07\2019 , 15:21 : Select Query executed -[ FINE ] 12\07\2019 , 15:21 : Connection Closed -[ FINE ] 12\07\2019 , 15:21 : Statement Closed -[ FINER ] 12\07\2019 , 15:21 : Connection Initiated -[ FINER ] 12\07\2019 , 15:21 : Statement Created -[ FINE ] 12\07\2019 , 15:21 : Connection Closed -[ FINE ] 12\07\2019 , 15:21 : Statement Closed -[ FINER ] 12\07\2019 , 15:21 : Connection Initiated -[ FINER ] 12\07\2019 , 15:21 : Statement Created -[ FINE ] 12\07\2019 , 15:21 : Select Query executed -[ FINE ] 12\07\2019 , 15:21 : Connection Closed -[ FINE ] 12\07\2019 , 15:21 : Statement Closed -[ FINER ] 12\07\2019 , 15:21 : Connection Initiated -[ FINER ] 12\07\2019 , 15:21 : Statement Created -[ FINE ] 12\07\2019 , 15:21 : Connection Closed -[ FINE ] 12\07\2019 , 15:21 : Statement Closed -[ FINER ] 12\07\2019 , 15:21 : Connection Initiated -[ FINER ] 12\07\2019 , 15:21 : Statement Created -[ SEVERE ] 12\07\2019 , 15:21 : Select Query failed -[ FINE ] 12\07\2019 , 15:21 : Connection Closed -[ FINE ] 12\07\2019 , 15:21 : Statement Closed -[ FINER ] 12\07\2019 , 15:21 : Connection Initiated -[ FINER ] 12\07\2019 , 15:21 : Statement Created -[ FINE ] 12\07\2019 , 15:21 : Select Query executed -[ FINE ] 12\07\2019 , 15:21 : Connection Closed -[ FINE ] 12\07\2019 , 15:21 : Statement Closed -[ FINER ] 12\07\2019 , 15:21 : Connection Initiated -[ FINER ] 12\07\2019 , 15:21 : Statement Created -[ SEVERE ] 12\07\2019 , 15:21 : Select Query failed -[ FINE ] 12\07\2019 , 15:21 : Connection Closed -[ FINE ] 12\07\2019 , 15:21 : Statement Closed -[ FINER ] 12\07\2019 , 15:21 : Connection Initiated -[ FINER ] 12\07\2019 , 15:21 : Statement Created -[ FINER ] 12\07\2019 , 15:26 : Connection Initiated -[ FINER ] 12\07\2019 , 15:26 : Statement Created -[ FINE ] 12\07\2019 , 15:26 : Use Query executed -[ FINE ] 12\07\2019 , 15:26 : Connection Closed -[ FINE ] 12\07\2019 , 15:26 : Statement Closed -[ FINER ] 12\07\2019 , 15:26 : Connection Initiated -[ FINER ] 12\07\2019 , 15:26 : Statement Created -[ FINE ] 12\07\2019 , 15:26 : Select Query executed -[ FINE ] 12\07\2019 , 15:26 : Connection Closed -[ FINE ] 12\07\2019 , 15:26 : Statement Closed -[ FINER ] 12\07\2019 , 15:26 : Connection Initiated -[ FINER ] 12\07\2019 , 15:26 : Statement Created -[ FINE ] 12\07\2019 , 15:26 : Update Query executed -[ FINE ] 12\07\2019 , 15:26 : Connection Closed -[ FINE ] 12\07\2019 , 15:26 : Statement Closed -[ FINER ] 12\07\2019 , 15:26 : Connection Initiated -[ FINER ] 12\07\2019 , 15:26 : Statement Created -[ FINE ] 12\07\2019 , 15:27 : Select Query executed -[ FINE ] 12\07\2019 , 15:27 : Connection Closed -[ FINE ] 12\07\2019 , 15:27 : Statement Closed -[ FINER ] 12\07\2019 , 15:27 : Connection Initiated -[ FINER ] 12\07\2019 , 15:27 : Statement Created -[ SEVERE ] 12\07\2019 , 15:27 : Select Query failed -[ FINE ] 12\07\2019 , 15:27 : Connection Closed -[ FINE ] 12\07\2019 , 15:27 : Statement Closed -[ FINER ] 12\07\2019 , 15:27 : Connection Initiated -[ FINER ] 12\07\2019 , 15:27 : Statement Created -[ SEVERE ] 12\07\2019 , 15:27 : Select Query failed -[ FINE ] 12\07\2019 , 15:27 : Connection Closed -[ FINE ] 12\07\2019 , 15:27 : Statement Closed -[ FINER ] 12\07\2019 , 15:27 : Connection Initiated -[ FINER ] 12\07\2019 , 15:27 : Statement Created -[ SEVERE ] 12\07\2019 , 15:27 : Select Query failed -[ FINE ] 12\07\2019 , 15:27 : Connection Closed -[ FINE ] 12\07\2019 , 15:27 : Statement Closed -[ FINER ] 12\07\2019 , 15:27 : Connection Initiated -[ FINER ] 12\07\2019 , 15:27 : Statement Created +[ FINER ] 12\07\2019 , 15:59 : Connection Initiated +[ FINER ] 12\07\2019 , 15:59 : Statement Created +[ FINE ] 12\07\2019 , 15:59 : Connection Closed +[ FINE ] 12\07\2019 , 15:59 : Statement Closed +[ FINER ] 12\07\2019 , 15:59 : Connection Initiated +[ FINER ] 12\07\2019 , 15:59 : Statement Created +[ FINE ] 12\07\2019 , 15:59 : Connection Closed +[ FINE ] 12\07\2019 , 15:59 : Statement Closed +[ FINER ] 12\07\2019 , 15:59 : Connection Initiated +[ FINER ] 12\07\2019 , 15:59 : Statement Created +[ FINE ] 12\07\2019 , 15:59 : Update Query executed +[ FINE ] 12\07\2019 , 15:59 : Connection Closed +[ FINE ] 12\07\2019 , 15:59 : Statement Closed +[ FINER ] 12\07\2019 , 15:59 : Connection Initiated +[ FINER ] 12\07\2019 , 15:59 : Statement Created +[ FINE ] 12\07\2019 , 16:00 : Select Query executed +[ FINE ] 12\07\2019 , 16:00 : Connection Closed +[ FINE ] 12\07\2019 , 16:00 : Statement Closed +[ FINER ] 12\07\2019 , 16:00 : Connection Initiated +[ FINER ] 12\07\2019 , 16:00 : Statement Created +[ FINE ] 12\07\2019 , 16:00 : Select Query executed +[ FINE ] 12\07\2019 , 16:00 : Connection Closed +[ FINE ] 12\07\2019 , 16:00 : Statement Closed +[ FINER ] 12\07\2019 , 16:00 : Connection Initiated +[ FINER ] 12\07\2019 , 16:00 : Statement Created +[ FINER ] 12\07\2019 , 16:13 : Connection Initiated +[ FINER ] 12\07\2019 , 16:13 : Statement Created diff --git a/src/eg/edu/alexu/csd/oop/cs71/db/FileManagement.java b/src/eg/edu/alexu/csd/oop/cs71/db/FileManagement.java index d2adb42..864fe74 100644 --- a/src/eg/edu/alexu/csd/oop/cs71/db/FileManagement.java +++ b/src/eg/edu/alexu/csd/oop/cs71/db/FileManagement.java @@ -17,7 +17,7 @@ import java.util.Arrays; import java.util.HashMap; -public class FileManagement implements FileManagementInterface{ +public class FileManagement extends FileManagementInterface{ public void writeInFile(String tableName, HashMap tableColumns, ArrayList> tableData, String currentDatabase,ArrayList cNames, ArrayList cTypes){ String[] columnContents =new String[tableColumns.size()]; Arrays.fill(columnContents, ""); diff --git a/src/eg/edu/alexu/csd/oop/cs71/db/FileManagementInterface.java b/src/eg/edu/alexu/csd/oop/cs71/db/FileManagementInterface.java index 71149a1..a3045bf 100644 --- a/src/eg/edu/alexu/csd/oop/cs71/db/FileManagementInterface.java +++ b/src/eg/edu/alexu/csd/oop/cs71/db/FileManagementInterface.java @@ -8,8 +8,41 @@ import java.util.ArrayList; import java.util.HashMap; -public interface FileManagementInterface { - void writeInFile(String tableName, HashMap tableColumns, ArrayList> tableData, String currentDatabase,ArrayList cNames, ArrayList cTypes); - void readFile(String tableName, HashMap tableColumns, ArrayList> tableData, String currentDatabase, ArrayList cNames, ArrayList cTypes) throws IOException, ParserConfigurationException, SAXException; - String getTableName(String query); +public abstract class FileManagementInterface { + abstract void writeInFile(String tableName, HashMap tableColumns, ArrayList> tableData, String currentDatabase,ArrayList cNames, ArrayList cTypes); + abstract void readFile(String tableName, HashMap tableColumns, ArrayList> tableData, String currentDatabase, ArrayList cNames, ArrayList cTypes) throws IOException, ParserConfigurationException, SAXException; + String getTableName(String query){ + String tableName=""; + String[] parts=query.split(" "); + parts[0]=parts[0].toLowerCase(); + switch (parts[0]) + { + case "select":{ + int index=0; + for (String x:parts) { + x=x.toLowerCase(); + if(x.equals("from")){ + index++; + break; + } + index++; + } + tableName=parts[index]; + } + break; + case "insert": + case "alter": + case "delete":{ + tableName=parts[2]; + parts=tableName.split("\\(" ); + tableName=parts[0]; + } + break; + case "update":{ + tableName=parts[1]; + } + break; + } + return tableName; + } } diff --git a/src/eg/edu/alexu/csd/oop/cs71/db/SQLParser.java b/src/eg/edu/alexu/csd/oop/cs71/db/SQLParser.java index bf5d4bf..da4b665 100644 --- a/src/eg/edu/alexu/csd/oop/cs71/db/SQLParser.java +++ b/src/eg/edu/alexu/csd/oop/cs71/db/SQLParser.java @@ -319,12 +319,12 @@ public int alter(String query, ArrayList cNames, ArrayList cType } private void operationParser(String query, ArrayList colNames, ArrayList colTypes, ArrayList> table) { - query = query.replaceAll("\\s+|\\(+|\\)|\\,|(?i)(and\\s+(?='|\\d))|\\;", " "); + query = query.replaceAll("\\s+|\\(+|\\)|\\,|(?i)(and\\s+(?='|-?\\d))|\\;", " "); query = query.replaceAll("\\s*\\<\\>\\s*", " != "); query = query.replaceAll("\\s+(?=\\=)", ""); - Pattern P1 = Pattern.compile("\\A[\\s]*(\\w+)[\\s]*(<|>|>\\s*=|<\\s*=|!\\s*=|=)[\\s]*([']?\\w+[']?)[\\s]*\\z"); + Pattern P1 = Pattern.compile("\\A[\\s]*(\\w+)[\\s]*(<|>|>\\s*=|<\\s*=|!\\s*=|=)[\\s]*([']?-?\\w+[']?)[\\s]*\\z"); Matcher M1; - Pattern P2 = Pattern.compile("\\A[\\s]*(\\w+)[\\s]*((?i)between|in)([\\s]*([']?\\w+[']?)[\\s]*)+\\z"); + Pattern P2 = Pattern.compile("\\A[\\s]*(\\w+)[\\s]*((?i)between|in)([\\s]*([']?-?\\w+[']?)[\\s]*)+\\z"); Matcher M2; logicOperatorParser(query, colNames, colTypes, table); query = query.replaceAll("(?i)(not)\\s*", "");