(txn *sql.Tx, schemaName string)
| 1212 | } |
| 1213 | |
| 1214 | func getRoutines(txn *sql.Tx, schemaName string) ([]*storepb.FunctionMetadata, []*storepb.ProcedureMetadata, []*storepb.PackageMetadata, error) { |
| 1215 | var functions []*storepb.FunctionMetadata |
| 1216 | var procedures []*storepb.ProcedureMetadata |
| 1217 | var packages []*storepb.PackageMetadata |
| 1218 | |
| 1219 | // Get function comments |
| 1220 | functionCommentMap, err := getFunctionComments(txn, schemaName) |
| 1221 | if err != nil { |
| 1222 | return nil, nil, nil, errors.Wrapf(err, "failed to get function comments") |
| 1223 | } |
| 1224 | |
| 1225 | query := fmt.Sprintf(` |
| 1226 | SELECT |
| 1227 | NAME, |
| 1228 | TYPE, |
| 1229 | TEXT |
| 1230 | FROM ALL_SOURCE |
| 1231 | WHERE |
| 1232 | TYPE IN ('FUNCTION', 'PROCEDURE', 'PACKAGE') |
| 1233 | AND |
| 1234 | OWNER = '%s' |
| 1235 | ORDER BY NAME, TYPE, LINE`, schemaName) |
| 1236 | |
| 1237 | slog.Debug("running get routines query") |
| 1238 | rows, err := txn.Query(query) |
| 1239 | if err != nil { |
| 1240 | return nil, nil, nil, util.FormatErrorWithQuery(err, query) |
| 1241 | } |
| 1242 | defer rows.Close() |
| 1243 | |
| 1244 | var currentName, currentType string |
| 1245 | var defText []string |
| 1246 | for rows.Next() { |
| 1247 | var name, t, def string |
| 1248 | if err := rows.Scan(&name, &t, &def); err != nil { |
| 1249 | return nil, nil, nil, err |
| 1250 | } |
| 1251 | if name == currentName && t == currentType { |
| 1252 | defText = append(defText, def) |
| 1253 | } else { |
| 1254 | // Oracle may include a trailing C-string null terminator via the go-ora driver. |
| 1255 | switch currentType { |
| 1256 | case "FUNCTION": |
| 1257 | function := &storepb.FunctionMetadata{ |
| 1258 | Name: currentName, |
| 1259 | Definition: strings.TrimRight(strings.Join(defText, ""), "\x00"), |
| 1260 | } |
| 1261 | key := db.TableKey{Schema: schemaName, Table: currentName} |
| 1262 | if comment, ok := functionCommentMap[key]; ok { |
| 1263 | function.Comment = comment |
| 1264 | } |
| 1265 | functions = append(functions, function) |
| 1266 | case "PROCEDURE": |
| 1267 | procedures = append(procedures, &storepb.ProcedureMetadata{ |
| 1268 | Name: currentName, |
| 1269 | Definition: strings.TrimRight(strings.Join(defText, ""), "\x00"), |
| 1270 | }) |
| 1271 | case "PACKAGE": |
no test coverage detected