Home | Menu


Sample Queries

Following statements are taken from the file Database.java:

System.out.println("\n @@@ TESTING PROJECT @@@\N");

System.out.println("\n *-*-*-*-*-*-* Project address of all students *-*-*-*-*-*-* \n");
Query.project("address","student").printRelation("student");

System.out.println("\n *-*-*-*-*-*-* Project number, name, description of all courses *-*-*-*-*-*-* \n");
Query.project("number name description","course").printRelation("course");

System.out.println("\n *-*-*-*-*-*-* Project ssn, name of all students *-*-*-*-*-*-* \n");
Query.project("ssn name","student").printRelation("student");

System.out.println("\n *-*-*-*-*-*-* Project number, hours of all courses *-*-*-*-*-*-* \n");
Query.project("number hours","course").printRelation("course");

System.out.println("\n *_*_*_*_*_*_* Project grade of every takes *_*_*_*_*_*_*_*_*_*_* \n");
Query.project("grade","takes").printRelation("takes");

// SELECT TESTS
System.out.println("\n @@@ TESTING SELECT @@@\N");

System.out.println("\n *-*-*-*-*-*-* Select student with \"\" *-*-*-*-*-*-* \n");
Query.select("","student").printRelation("student");

System.out.println("\n *-*-*-*-*-*-* Select student with ssn=987654321 *-*-*-*-*-*-* \n");
Query.select("ssn = 987654321","student").printRelation("student");

System.out.println("\n *-*-*-*-*-*-* Select all students with ssn>= 51234567 *-*-*-*-*-*-* \n");
Query.select("ssn >= 512345679","student").printRelation("student");

System.out.println("\n *-*-*-*-*-*-* Select all students with address = '123 Apple St. *-*-*-*-*-*-* \n");
Query.select("address = '123 Apple St.'","student").printRelation("student");

System.out.println("\n *-*-*-*-*-*-* Select all students with address != '91 Broad Street *-*-*-*-*-*-* \n");
Query.select("address != '91 Broad Street.'","student").printRelation("student");

System.out.println("\n *-*-*-*-*-*-* Select all courses with hours = 4 *-*-*-*-*-*-* \n");
Query.select("hours = 4","course").printRelation("course");

System.out.println("\n *-*-*-*-*-*-* Select all courses with hours <= 3 *-*-*-*-*-*-* \n");
Query.select("hours <= 3","course").printRelation("course");

System.out.println("\n *-*-*-*-*-*-* Select all courses with name = 'CSCI:Data Structures' and number = 456 and hours = 4 *-*-*-*-*-*-* \n");
Query.select("name = 'CSCI:Data Structures' and number = 456 and hours = 4","course").printRelation("course");

System.out.println("\n *-*-*-*-*-*-* Select all courses with name = 'Structures' and number = 456 and hours = 4 *-*-*-*-*-*-* \n");
Query.select("name = 'Structures' and number = 456 and hours = 4","course").printRelation("course");

System.out.println("\n *-*-*-*-*-*-* Select all courses with name = 'P. Vocher' and address = '123 Apple St.' *-*-*-*-*-*-* \n");
Query.select("name = 'P. Vocher' and address = '123 Apple St.'","student").printRelation("course");

System.out.println("\n *-*-*-*-*-*-* Select all students with name > 'A. Greenspan' *-*-*-*-*-*-* \n");
Query.select("name > 'A. Greenspan'","student").printRelation("student");

// FORWARD AND BACKWARD TEST
System.out.println("\n @@@ TESTING FORWARD, BACKWARD @@@\n");

System.out.println("\n *-*-*-*-*-*-*-* Forward of Student Entity Type on Takes Relationship *-*-*-*-*-*-*-* \n");
Query.forward("student","takes").printRelation("takes");

System.out.println("\n *-*-*-*-*-*-*-* Backward of Course Entity Type on Drops Relationship *-*-*-*-*-*-*-* \n");
Query.backward("course","drops").printRelation("drops");

System.out.println("\n *-*-*-*-*-*-*-* Forward of Student Entity Type on Drops Relationship *-*-*-*-*-*-*-* \n");
Query.forward("student","drops").printRelation("drops");

System.out.println("\n *-*-*-*-*-*-*-* Backward of Course Entity Type on Takes Relationship *-*-*-*-*-*-*-* \n");
Query.backward("course","takes").printRelation("takes");

// START, END TEST
System.out.println("\n @@@ TESTING START AND END @@@@\n");

System.out.println("\n *-*-*-*-*-*-*-* Start of Takes Relationship *-*-*-*-*-*-*-* \n");
Query.start("takes").printRelation("student");

System.out.println("\n *-*-*-*-*-*-*-* Start of Drops Relationship *-*-*-*-*-*-*-* \n");
Query.start("drops").printRelation("student");

System.out.println("\n *-*-*-*-*-*-*-* End of Takes Relationship *-*-*-*-*-*-*-* \n");
Query.end("takes").printRelation("course");

System.out.println("\n *-*-*-*-*-*-*-* End of Drops Relationship *-*-*-*-*-*-*-* \n");
Query.end("drops").printRelation("course");

//TESTING ALL OPERATIONS TOGETHER
// PROJECT OF A SELECT TEST
System.out.println("\n @@@@ TESTING SELECT, PROJECT, FWD, BKWD, START AND END TOGETHER @@@\n");

System.out.println("\n *-*-*-*-*-*-* Select all students with name > 'B. Bishop' and address >='123 Apple St.' *-*-*-*-*-*-* ");

System.out.println( " *-*-*-*-*-*-* Projected over name *-*-*-*-*-*-* \n");
Query.select("name > 'B. Bishop' and address >= '123 Apple St.'","student").select("ssn = 123456789","student").project("name","student").printRelation("student");

System.out.println("\n *-*-*-*-*-*-* Select all takes relationships with grade = A *-*-*-*-*-*-* ");

System.out.println( " *-*-*-*-*-*-* Projected over grade *-*-*-*-*-*-* \n");
Query.select("grade = 'A'","takes").project("grade","takes").printRelation("takes");

System.out.println("\n *-*-*-*-*-*-*-* Print names of all students who have A as their grade *-*-*-*-*-*-*-* ");

System.out.println(" *-*-*-*-*-*-* select(grade = 'A',takes).start(takes).project(name,student) *-*-*-*-*-*-* \n");
Query.select("grade = 'A'","takes").start("takes").project("name","student").printRelation("student");

System.out.println("\n *-*-*-*-*-*-*-* Print all courses that are dropped by students who have A in their grade list *-*-*-*-*-*-*-* ");

System.out.println(" *-*-*-*-*-*-* select(grade = 'A',takes).start(takes).forward(student,takes).end(drops) *-*-*-*-*-*-* \n");
Query.select("grade = A","takes").start("takes").forward("student","drops").end("drops").printRelation("course");

System.out.println("\n *-*-*-*-*-*-*-* Print All students with ssn >100000000 and ssn<90000000 *-*-*-*-*-*-*-* ");

System.out.println(" *-*-*-*-*-*-*-* select (ssn > 100000000, student).select (ssn < 900000000,student) *-*-*-*-*-*-*-* \n");
Query.select ("ssn > 100000000", "student").select ("ssn < 900000000","student").printRelation("student");

System.out.println("\n *-*-*-*-*-*-*-* Print all courses with hours<=4 and hours> 2 and hours= 3 *-*-*-*-*-*-*-* ");

System.out.println(" *-*-*-*-*-*-*-* select (hours <= 4 and hours > 2, course).select (hours = 3,course) *-*-*-*-*-*-*-* \n");
Query.select ("hours <= 4 and hours > 2", "course").select ("hours = 3","course").printRelation("course");

System.out.println("\n *-*-*-*-*-*-*-* Print students who have taken atleast one course and with ssn>5000000000 *-*-*-*-*-*-*-* ");

System.out.println(" *-*-*-*-*-*-*-* start(takes). select(ssn>50000000) *-*-*-*-*-*-*-* \n");
Query.start ("takes").select ("ssn > 500000000","student").printRelation("student");

System.out.println("\n *-*-*-*-*-*-*-* Print courses taken by students and with hours=4 *-*-*-*-*-*-*-* ");

System.out.println(" *-*-*-*-*-*-*-* end(takes) . select(hours=4) *-*-*-*-*-*-*-* \n");
Query.end ("takes").select ("hours = 4","course").printRelation("course");

System.out.println("\n *-*-*-*-*-*-*-* Print name address of all students with ssn > 2000000000 *-*-*-*-*-*-*-* ");

System.out.println(" *-*-*-*-*-*-*-* ssn>200000000 project(name,address) *-*-*-*-*-*-*-* \n");
Query.select ("ssn > 200000000", "student").project ("name address","student").printRelation("student");

System.out.println("\n *-*-*-*-*-*-*-* Print name number and desc of all courses with hours<4*-*-*-*-*-*-*-* ");

System.out.println("*-*-*-*-*-*-*-* all courses hours<4 and project(name,number,desc) *-*-*-*-*-*-*-* \n");
Query.select ("hours < 4", "course").project ("name number description","course").printRelation("course");

System.out.println("\n *-*-*-*-*-*-*-* start(takes).project(ssn name) *-*-*-*-*-*-*-* \n");
Query.start ("takes").project ("ssn name","student").printRelation("student");

System.out.println("\n *-*-*-*-*-*-*-* end(takes) project(hours name) *-*-*-*-*-*-*-* \n");
Query.end ("takes").project ("hours name","course").printRelation("course");

System.out.println("\n *-*-*-*-*-*-*-* backward(course,takes) project(ssn name) *-*-*-*-*-*-*-* \n");
Query.backward ("course","takes").project ("ssn name", "student").printRelation("student");

System.out.println("\n *-*-*-*-*-*-*-* forward(course,takes) project(hours name) *-*-*-*-*-*-*-* \n");
Query.forward ("student","takes").project ("hours name","course").printRelation("course");

System.out.println("\n *-*-*-*-*-*-*-* Print number and name of all courses taken by students with ssn>4000000000 *-*-*-*-*-*-*-* ");

System.out.println("*-*-*-*-*-*-*-* ssn>400000000 forward(student,takes) project(number name) *-*-*-*-*-*-*-* \n");
Query.select("ssn > 400000000", "student").forward("student","takes").end("takes").project ("number name","course").printRelation("course");

System.out.println("\n *-*-*-*-*-*-*-* Print all relationships pertaining to students with ssn >5000000000 *-*-*-*-*-*-*-* ");

System.out.println("*-*-*-*-*-*-*-* ssn>500000000 forward(student,takes) *-*-*-*-*-*-*-* \n");
Query.select ("ssn > 500000000", "student").forward("student","takes").printRelation("takes");

System.out.println("\n *-*-*-*-*-*-*-* Print all relationships of the courses with number > 4000 *-*-*-*-*-*-*-* ");

System.out.println("*-*-*-*-*-*-*-* number > 4000 backward(course,takes) *-*-*-*-*-*-*-* \n");
Query.select ("number > 4000", "course").backward("course","takes").printRelation("takes");




Home

Research

Resume

Projects

Personal