-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support CREATE|ALTER|DROP PROCEDURE and ALTER FUNCTION
- Loading branch information
1 parent
b469e59
commit 2017ad9
Showing
11 changed files
with
40,139 additions
and
39,692 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2024 Dolthub, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Copyright 2020 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package tree | ||
|
||
var _ Statement = &AlterFunction{} | ||
|
||
// AlterFunction represents a ALTER FUNCTION statement. | ||
type AlterFunction struct { | ||
Name *UnresolvedObjectName | ||
Args RoutineArgs | ||
Options []RoutineOption | ||
Restrict bool | ||
Rename *UnresolvedObjectName | ||
Owner string | ||
Schema string | ||
No bool | ||
Extension string | ||
} | ||
|
||
// Format implements the NodeFormatter interface. | ||
func (node *AlterFunction) Format(ctx *FmtCtx) { | ||
ctx.WriteString("ALTER FUNCTION ") | ||
ctx.FormatNode(node.Name) | ||
if node.Args != nil { | ||
ctx.WriteString(" ( ") | ||
ctx.FormatNode(node.Name) | ||
ctx.WriteString(" )") | ||
} | ||
if node.Options != nil { | ||
for i, option := range node.Options { | ||
if i != 0 { | ||
ctx.WriteByte(' ') | ||
} | ||
ctx.FormatNode(option) | ||
} | ||
if node.Restrict { | ||
ctx.WriteString(" RESTRICT") | ||
} | ||
} else if node.Rename != nil { | ||
ctx.WriteString(" RENAME TO ") | ||
ctx.FormatNode(node.Rename) | ||
} else if node.Owner != "" { | ||
ctx.WriteString(" OWNER TO ") | ||
ctx.WriteString(node.Owner) | ||
} else if node.Schema != "" { | ||
ctx.WriteString(" SET SCHEMA ") | ||
ctx.WriteString(node.Schema) | ||
} else { | ||
if node.No { | ||
ctx.WriteString(" NO") | ||
} | ||
ctx.WriteString(" DEPENDS ON EXTENSION ") | ||
ctx.WriteString(node.Extension) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2024 Dolthub, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Copyright 2020 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package tree | ||
|
||
var _ Statement = &AlterProcedure{} | ||
|
||
// AlterProcedure represents a ALTER PROCEDURE statement. | ||
type AlterProcedure struct { | ||
Name *UnresolvedObjectName | ||
Args RoutineArgs | ||
Options []RoutineOption | ||
Restrict bool | ||
Rename *UnresolvedObjectName | ||
Owner string | ||
Schema string | ||
No bool | ||
Extension string | ||
} | ||
|
||
// Format implements the NodeFormatter interface. | ||
func (node *AlterProcedure) Format(ctx *FmtCtx) { | ||
ctx.WriteString("ALTER PROCEDURE ") | ||
ctx.FormatNode(node.Name) | ||
if node.Args != nil { | ||
ctx.WriteString(" ( ") | ||
ctx.FormatNode(node.Name) | ||
ctx.WriteString(" )") | ||
} | ||
if node.Options != nil { | ||
for i, option := range node.Options { | ||
if i != 0 { | ||
ctx.WriteByte(' ') | ||
} | ||
ctx.FormatNode(option) | ||
} | ||
if node.Restrict { | ||
ctx.WriteString(" RESTRICT") | ||
} | ||
} else if node.Rename != nil { | ||
ctx.WriteString(" RENAME TO ") | ||
ctx.FormatNode(node.Rename) | ||
} else if node.Owner != "" { | ||
ctx.WriteString(" OWNER TO ") | ||
ctx.WriteString(node.Owner) | ||
} else if node.Schema != "" { | ||
ctx.WriteString(" SET SCHEMA ") | ||
ctx.WriteString(node.Schema) | ||
} else { | ||
if node.No { | ||
ctx.WriteString(" NO") | ||
} | ||
ctx.WriteString(" DEPENDS ON EXTENSION ") | ||
ctx.WriteString(node.Extension) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2024 Dolthub, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Copyright 2012, Google Inc. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in licenses/BSD-vitess.txt. | ||
|
||
// Portions of this file are additionally subject to the following | ||
// license and copyright. | ||
// | ||
// Copyright 2015 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
// This code was derived from https://github.com/youtube/vitess. | ||
|
||
package tree | ||
|
||
var _ Statement = &CreateProcedure{} | ||
|
||
// CreateProcedure represents a CREATE PROCEDURE statement. | ||
type CreateProcedure struct { | ||
Name *UnresolvedObjectName | ||
Replace bool | ||
Args RoutineArgs | ||
Options []RoutineOption | ||
} | ||
|
||
// Format implements the NodeFormatter interface. | ||
func (node *CreateProcedure) Format(ctx *FmtCtx) { | ||
ctx.WriteString("CREATE ") | ||
if node.Replace { | ||
ctx.WriteString("OR REPLACE ") | ||
} | ||
ctx.WriteString("PROCEDURE ") | ||
ctx.FormatNode(node.Name) | ||
if len(node.Args) != 0 { | ||
ctx.WriteString(" (") | ||
ctx.FormatNode(node.Args) | ||
ctx.WriteString(" )") | ||
} | ||
for i, option := range node.Options { | ||
if i != 0 { | ||
ctx.WriteByte(' ') | ||
} | ||
ctx.FormatNode(option) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.