hssqlppp-0.2.0: Database/HsSqlPpp/AstInternals/TypeChecking/MiscCreates.ag
{-
Copyright 2009 Jake Wheat
This file contains the ddl checking, apart from create function and
create table which have their own files.
= create view
pretty simple, just forwards the select expression type
-}
SEM Statement
| CreateView
loc.tpe = dependsOnRTpe [getTypeAnnotation @expr.annotatedTree] $
Right $ Pseudo Void
loc.backTree = CreateView @ann @name @expr.annotatedTree
loc.attrs = case getTypeAnnotation @expr.annotatedTree of
SetOfType (CompositeType c) -> c
_ -> [] --TODO: error ignored
loc.catUpdates = [CatCreateView @name @loc.attrs]
loc.statementType = []
{-
================================================================================
= create type
might move this to create table since they have a fair bit in common
main shortcomings are the names and types aren't checked
-}
ATTR TypeAttributeDef [||attrName : String
namedType : Type]
SEM TypeAttributeDef
| TypeAttDef
lhs.attrName = @name
lhs.namedType = @typ.namedType
ATTR TypeAttributeDefList [||attrs : {[(String, Type)]}]
SEM TypeAttributeDefList
| Cons lhs.attrs = (@hd.attrName, @hd.namedType) : @tl.attrs
| Nil lhs.attrs = []
SEM Statement
| CreateType
loc.tpe = Right $ Pseudo Void
loc.backTree = CreateType @ann @name @atts.annotatedTree
loc.statementType = []
loc.catUpdates = [CatCreateComposite @name @atts.attrs]
{-
= create domain
-}
SEM Statement
| CreateDomain
loc.tpe = Right $ Pseudo Void
loc.backTree = CreateDomain @ann @name @typ.annotatedTree @checkName @check.annotatedTree
loc.statementType = []
loc.catUpdates = [CatCreateDomain (DomainType @name) @typ.namedType]
--allow refering to value as 'value' in check expression
check.lib = fromRight @lhs.lib $
updateBindings @lhs.lib @lhs.cat
[LibStackIDs [("", [("value", @typ.namedType)])]]
SEM Statement
| CreateLanguage
loc.tpe = Right $ Pseudo Void
loc.backTree = CreateLanguage @ann @name
loc.statementType = []
loc.catUpdates = [CatCreateFunction FunName "plpgsql_call_handler" [] (Pseudo LanguageHandler) False
,CatCreateFunction FunName "plpgsql_validator" [ScalarType "oid"] (Pseudo Void) False]