src/Pure/General/sql.scala
changeset 65702 7c6a91deb212
parent 65701 d788c11176e5
child 65703 cead65c19f2e
equal deleted inserted replaced
65701:d788c11176e5 65702:7c6a91deb212
   124       case bad => error("Duplicate column names " + commas_quote(bad) + " for table " + quote(name))
   124       case bad => error("Duplicate column names " + commas_quote(bad) + " for table " + quote(name))
   125     }
   125     }
   126 
   126 
   127     def ident: String = SQL.ident(name)
   127     def ident: String = SQL.ident(name)
   128 
   128 
   129     def expr: String =
   129     def query: String =
   130       if (body == "") error("Missing SQL body for table " + quote(name))
   130       if (body == "") error("Missing SQL body for table " + quote(name))
   131       else SQL.enclose(body)
   131       else SQL.enclose(body)
       
   132 
       
   133     def query_alias(alias: String = name): String =
       
   134       query + " AS " + SQL.ident(alias)
   132 
   135 
   133     def create(strict: Boolean = false, sql_type: Type.Value => String): String =
   136     def create(strict: Boolean = false, sql_type: Type.Value => String): String =
   134     {
   137     {
   135       val primary_key =
   138       val primary_key =
   136         columns.filter(_.primary_key).map(_.name) match {
   139         columns.filter(_.primary_key).map(_.name) match {
   307       using_statement(table.create_index(name, columns, strict, unique))(_.execute())
   310       using_statement(table.create_index(name, columns, strict, unique))(_.execute())
   308 
   311 
   309     def create_view(table: Table, strict: Boolean = false): Unit =
   312     def create_view(table: Table, strict: Boolean = false): Unit =
   310     {
   313     {
   311       if (strict || !tables.contains(table.name)) {
   314       if (strict || !tables.contains(table.name)) {
   312         val sql = "CREATE VIEW " + table.ident + " AS " + table.expr
   315         val sql = "CREATE VIEW " + table.ident + " AS " + table.query
   313         using_statement(sql)(_.execute())
   316         using_statement(sql)(_.execute())
   314       }
   317       }
   315     }
   318     }
   316   }
   319   }
   317 }
   320 }