changeset 327:0a9c000c9dd5

~ arranged SQL INTEGER/INT tokens in descending order of length, + validJSvar to create valid Javascript var names
author Eric Prud'hommeaux <eric@w3.org>
date Sat, 12 Feb 2011 11:11:50 -0500
parents 3a461a205011 (current diff) ab266c5fd61f (diff)
children 6343be6fac49 c69b9aac210c
files directmapping-webapp/src/main/scala/Servlet.scala sql/src/main/scala/SQL.scala
diffstat 2 files changed, 53 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- 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>
--- a/sql/src/main/scala/SQL.scala	Sat Feb 12 10:37:46 2011 -0500
+++ b/sql/src/main/scala/SQL.scala	Sat Feb 12 11:11:50 2011 -0500
@@ -266,8 +266,8 @@
   )
 
   def typpe:Parser[RDB.Datatype] = (
-      "(?i)INT".r ~ opt(size) ^^ { case _ => RDB.Datatype.INTEGER } // alias for INTEGER
-    | "(?i)INTEGER".r ~ opt(size)^^ { case _ => RDB.Datatype.INTEGER }
+      "(?i)INTEGER".r ~ opt(size)^^ { case _ => RDB.Datatype.INTEGER }
+    | "(?i)INT".r ~ opt(size) ^^ { case _ => RDB.Datatype.INTEGER } // alias for INTEGER
     | "(?i)DOUBLE".r ^^ { case _ => RDB.Datatype.DOUBLE }
     | "(?i)FLOAT".r ^^ { case _ => RDB.Datatype.FLOAT }
     | "(?i)STRING".r ^^ { case _ => RDB.Datatype.STRING }
Set up and maintained by W3C Systems Team, please report bugs to sysreq@w3.org.

W3C would like to thank Microsoft who donated the server that allows us to run this service.