MCPcopy Create free account
hub / github.com/dolthub/doltgresql / convertSQLStmts

Function convertSQLStmts

server/ast/create_function.go:221–254  ·  view source on GitHub ↗

convertSQLStmts takes parser.Statements and routine parameters and returns converted to string representation and vitess statements.

(stmts parser.Statements, params []pgnodes.RoutineParam)

Source from the content-addressed store, hash-verified

219// convertSQLStmts takes parser.Statements and routine parameters and
220// returns converted to string representation and vitess statements.
221func convertSQLStmts(stmts parser.Statements, params []pgnodes.RoutineParam) (string, []vitess.Statement, error) {
222 paramMap := make(map[string]*framework.ParamTypAndValue, len(params))
223 for i, param := range params {
224 tv := &framework.ParamTypAndValue{
225 Typ: param.Type,
226 Val: nil,
227 FromCreate: true,
228 }
229 // placeholder name is empty
230 if param.Name == "\"\"" {
231 n := fmt.Sprintf("$%d", i+1)
232 paramMap[n] = tv
233 params[i].Name = n
234 } else {
235 paramMap[param.Name] = tv
236 }
237 }
238
239 var sqlDefs = make([]string, len(stmts))
240 var vitessASTs = make([]vitess.Statement, len(stmts))
241 for i, stmt := range stmts {
242 sqlDefs[i] = stmt.AST.String()
243 err := framework.ReplaceFunctionColumn(stmt.AST, paramMap)
244 if err != nil {
245 return "", nil, err
246 }
247 // stmt.AST is updated at this point with FunctionColumn
248 vitessASTs[i], err = Convert(stmt)
249 if err != nil {
250 return "", nil, err
251 }
252 }
253 return strings.Join(sqlDefs, ";"), vitessASTs, nil
254}
255
256// validateRoutineOptions ensures that each option is defined only once. Returns a map containing all options, or an
257// error if an option is invalid or is defined multiple times.

Callers 2

nodeCreateFunctionFunction · 0.85
handleLanguageSQLAsFunction · 0.85

Calls 3

ReplaceFunctionColumnFunction · 0.92
ConvertFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected