01: /*
02: * FirebirdProcedureReader.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.db.firebird;
13:
14: import workbench.db.JdbcProcedureReader;
15: import workbench.db.ProcedureReader;
16: import workbench.db.WbConnection;
17: import workbench.storage.DataStore;
18: import workbench.util.StringUtil;
19:
20: /**
21: * An implementation of the ProcedureReader interface for the
22: * <a href="http://www.firebirdsql.org">Firebird</a> database server
23: * @author support@sql-workbench.net
24: */
25: public class FirebirdProcedureReader extends JdbcProcedureReader {
26: public FirebirdProcedureReader(WbConnection conn) {
27: super (conn);
28: }
29:
30: public StringBuilder getProcedureHeader(String aCatalog,
31: String aSchema, String aProcname, int procType) {
32: StringBuilder source = new StringBuilder();
33: try {
34: DataStore ds = this .getProcedureColumns(aCatalog, aSchema,
35: aProcname);
36: source.append("CREATE PROCEDURE ");
37: source.append(aProcname);
38: String retType = null;
39: int count = ds.getRowCount();
40: int added = 0;
41: for (int i = 0; i < count; i++) {
42: String vartype = ds
43: .getValueAsString(
44: i,
45: ProcedureReader.COLUMN_IDX_PROC_COLUMNS_DATA_TYPE);
46: String name = ds
47: .getValueAsString(
48: i,
49: ProcedureReader.COLUMN_IDX_PROC_COLUMNS_COL_NAME);
50: String ret = ds
51: .getValueAsString(
52: i,
53: ProcedureReader.COLUMN_IDX_PROC_COLUMNS_RESULT_TYPE);
54: if ("OUT".equals(ret)) {
55: retType = "(" + name + " " + vartype + ")";
56: } else {
57: if (added > 0) {
58: source.append(',');
59: } else {
60: source.append(" (");
61: }
62: source.append(name);
63: source.append(' ');
64: source.append(vartype);
65: added++;
66: }
67: }
68: if (added > 0)
69: source.append(')');
70: if (retType != null) {
71: source.append("\nRETURNS ");
72: source.append(retType);
73: }
74: source.append("\nAS\n");
75: } catch (Exception e) {
76: source = StringUtil.emptyBuffer();
77: }
78: return source;
79: }
80:
81: }
|