--- a/directmapping-webapp/src/main/scala/Servlet.scala Sat Feb 12 10:37:46 2011 -0500
+++ b/directmapping-webapp/src/main/scala/Servlet.scala Sat Feb 12 11:11:50 2011 -0500
@@ -108,25 +108,25 @@
FOREIGN KEY (deptName, deptCity) REFERENCES Department(name, city));
INSERT INTO TaskAssignments (worker, project, deptName, deptCity) VALUES (7, "pencil survey", "accounting", "Cambridge");""",
- "_1table0rows" ->
+ "1table0rows" ->
"""CREATE TABLE Student (
Name VARCHAR(50)
);""",
- "_1table1row" ->
+ "1table1row" ->
"""CREATE TABLE Student (
Name VARCHAR(50)
);
INSERT INTO Student (Name) VALUES ("Venus");""",
- "_1table2columns1row" ->
+ "1table2columns1row" ->
"""CREATE TABLE Student (
ID INT,
Name VARCHAR(50)
);
INSERT INTO Student (ID, Name) VALUES(10,"Venus");""",
- "_1table3columns1row" ->
+ "1table3columns1row" ->
"""CREATE TABLE Student (
ID INT,
FirstName VARCHAR(50),
@@ -134,7 +134,7 @@
);
INSERT INTO Student (ID, FirstName, LastName) VALUES (10,"Venus", "Williams");""",
- "_2duplicates0nulls" ->
+ "2duplicates0nulls" ->
"""CREATE TABLE IOUs (
fname CHAR(20),
lname CHAR(20),
@@ -148,17 +148,58 @@
Student VARCHAR(50),
Sport VARCHAR(50)
);
-INSERT INTO Student_Sport (Student,Sport) VALUES ("Venus", "Tennis");""")
+INSERT INTO Student_Sport (Student,Sport) VALUES ("Venus", "Tennis");""",
+
+ "1table1compositeprimarykey3columns1row" ->
+"""CREATE TABLE Student (
+ ID integer,
+ Name varchar(50),
+ Sport varchar (50),
+ PRIMARY KEY (ID,Name)
+);
+INSERT INTO Student (ID, Name,Sport) VALUES(10,"Venus Williams","Tennis");""",
+
+ "1table1primarykey1column1row" ->
+"""CREATE TABLE Student (
+Name varchar(50) PRIMARY KEY
+);
+INSERT INTO Student (Name) VALUES ("Venus");""",
+
+ "2tables1primarykey1foreingkey" ->
+"""CREATE TABLE Student (
+ID integer,
+Name varchar(50),
+Sport integer,
+PRIMARY KEY (ID),
+FOREIGN KEY(Sport) REFERENCES Sport(ID)
+);
+
+CREATE TABLE Sport (
+ID integer,
+Name varchar (50),
+PRIMARY KEY (ID)
+);
+
+INSERT INTO Student (ID, Name, Sport) VALUES (10,"Venus Williams", 100);
+INSERT INTO Student (ID, Name, Sport) VALUES (20,"Demi Moore", NULL);
+INSERT INTO Sport (ID, Name) VALUES (100,"Tennis");""")
def format(varr:String, sql:String):String = {
val formattedSQL = sql.replaceAll("\n+$", "").replaceAll("\n", "\\\\n\\\\\n")
"var " + varr + " = '" + formattedSQL + "';"
}
- val Script:String = scripts map { case (varr, sql) => format(varr, sql) } mkString "\n\n"
+ def validJSvar(varr:String) = {
+ if ("^[0-9]".r.findFirstIn(varr).isDefined)
+ "_" + varr
+ else
+ varr
+ }
+
+ val Script:String = scripts map { case (varr, sql) => format(validJSvar(varr), sql) } mkString "\n\n"
def renderVar(varr:String) =
- <p><input value={ varr } type="button" onclick={ "document.getElementById('sql').value = " + varr + ";" } /></p>
+ <p><input value={ varr } type="button" onclick={ "document.getElementById('sql').value = " + validJSvar(varr) + ";" } /></p>
}
@@ -187,8 +228,7 @@
}
}
- override def doGet(request:HttpServletRequest, response:HttpServletResponse) =
- processIndex(request, response)
+ override def doGet(request:HttpServletRequest, response:HttpServletResponse) = doPost(request, response)
val xhtmlDoctype = DocType("html",
PublicID("-//W3C//DTD XHTML 1.0 Strict//EN",
@@ -216,7 +256,7 @@
{ List("emp_addr", "hier_tabl_proto", "hier_table", "multi_key", "ref_no_pk") map renderVar }
</div>
<div style="float:left;">
- { List("1table0rows", "1table1row", "1table2columns1row", "1table3columns1row", "2duplicates0nulls", "varchar_varchar_1row") map renderVar }
+ { List("1table0rows", "1table1row", "1table2columns1row", "1table3columns1row", "2duplicates0nulls", "varchar_varchar_1row", "1table1compositeprimarykey3columns1row", "1table1primarykey1column1row", "2tables1primarykey1foreingkey") map renderVar }
</div>
</div>
<p><input name="hierarchy" checked="checked" type="checkbox" />Detects hierarchy relation</p>