@@ -866,8 +866,8 @@ let private columnConstraint =
866866 %% +.( zeroOrOne * constraintName)
867867 -- +. constraintType
868868 -- ws
869- -|> fun name cty columnName ->
870- { Name = name |? cty.DefaultName( columnName)
869+ -|> fun name cty columnName tblName ->
870+ { Name = name |? cty.DefaultName( tblName , columnName)
871871 ColumnConstraintType = cty
872872 }
873873
@@ -881,13 +881,13 @@ let private columnDef =
881881 -- +.( zeroOrOne * collation)
882882 -- +.( zeroOrOne * defaultValue)
883883 -- +.( columnConstraint * qty.[ 0 ..])
884- -|> fun name typeName nullable collation defaultVal constraints ->
884+ -|> fun name typeName nullable collation defaultVal constraints tblName ->
885885 { Name = name
886886 Type = typeName
887887 Nullable = Option.isSome nullable
888888 Collation = collation
889889 DefaultValue = defaultVal
890- Constraints = constraints |> Seq.map ((|>) name) |> Seq.toArray
890+ Constraints = constraints |> Seq.map ( fun f -> f name tblName ) |> Seq.toArray
891891 }
892892
893893let private tableIndexConstraintType =
@@ -927,8 +927,8 @@ let private tableConstraint =
927927 %% +.( zeroOrOne * constraintName)
928928 -- +. tableConstraintType
929929 -- ws
930- -|> fun name cty ->
931- { Name = match name with | Some name -> name | None -> Name ( cty.DefaultName() )
930+ -|> fun name cty tblName ->
931+ { Name = match name with | Some name -> name | None -> cty.DefaultName( tblName )
932932 TableConstraintType = cty
933933 }
934934
@@ -939,10 +939,13 @@ let private alterTableStmt =
939939 -- +. name
940940 -|> RenameTo
941941 let add =
942- let addColumn = %% kw " COLUMN" -- +. withSource columnDef -|> AddColumn
942+ let addColumn =
943+ %% kw " COLUMN" -- +. withSource columnDef
944+ -|> fun cdef tblName -> AddColumn ( applySource cdef tblName)
943945 let addDefault =
944- %% kw " DEFAULT" -- kw " FOR" -- +. name -- ws -- +. expr -|> fun name expr -> AddDefault ( name, expr)
945- let addConstraint = withSource tableConstraint |>> AddConstraint
946+ %% kw " DEFAULT" -- kw " FOR" -- +. name -- ws -- +. expr
947+ -|> fun name expr _ -> AddDefault ( name, expr)
948+ let addConstraint = withSource tableConstraint |>> fun cstr tblName -> AddConstraint ( applySource cstr tblName)
946949 %% kw " ADD"
947950 -- +.[ addColumn
948951 addDefault
@@ -986,15 +989,16 @@ let private alterTableStmt =
986989 changeType
987990 ]
988991 -|> (|>)
992+ let ignoreTblName parser = parser |>> fun x _ -> x
989993 %% kw " ALTER"
990994 -- kw " TABLE"
991995 -- +. objectName
992- -- +.[ renameTo
996+ -- +.[ ignoreTblName renameTo
993997 add
994- drop
995- alterColumn
998+ ignoreTblName drop
999+ ignoreTblName alterColumn
9961000 ]
997- -|> fun table alteration -> { Table = table; Alteration = alteration }
1001+ -|> fun table alteration -> { Table = table; Alteration = alteration table.ObjectName }
9981002
9991003let private createTableDefinition =
10001004 let part =
@@ -1007,16 +1011,20 @@ let private createTableDefinition =
10071011 -- +.( qty.[ 0 ..] /. tws ',' * part)
10081012 -- ')'
10091013 -- ws
1010- -|> fun parts ->
1014+ -|> fun parts tblName ->
10111015 { Columns =
1012- parts |> Seq.choose ( function | Choice2Of2 cdef -> Some cdef | Choice1Of2 _ -> None) |> Seq.toArray
1016+ parts
1017+ |> Seq.choose ( function | Choice2Of2 cdef -> Some ( applySource cdef tblName) | Choice1Of2 _ -> None)
1018+ |> Seq.toArray
10131019 Constraints =
1014- parts |> Seq.choose ( function | Choice1Of2 ct -> Some ct | Choice2Of2 _ -> None) |> Seq.toArray
1020+ parts
1021+ |> Seq.choose ( function | Choice1Of2 ct -> Some ( applySource ct tblName) | Choice2Of2 _ -> None)
1022+ |> Seq.toArray
10151023 }
10161024
10171025let private createTableAs =
1018- %[ %% kw " AS" -- +. selectStmt -|> CreateAsSelect
1019- %% +. createTableDefinition -|> CreateAsDefinition
1026+ %[ %% kw " AS" -- +. selectStmt -|> fun select _ -> CreateAsSelect select
1027+ %% +. createTableDefinition -|> fun def tblName -> CreateAsDefinition ( def tblName )
10201028 ]
10211029
10221030let private temporary = %( zeroOrOne * [ kw " TEMPORARY" ; kw " TEMP" ])
@@ -1030,7 +1038,7 @@ let private createTableStmt =
10301038 -|> fun temp name createAs ->
10311039 { Temporary = Option.isSome temp
10321040 Name = name
1033- As = createAs
1041+ As = createAs name.ObjectName
10341042 }
10351043
10361044let private createIndexStmt =
0 commit comments