* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / FirebirdSql.Data.Firebird / FirebirdSql.Data.Firebird / DbSchema / FbProcedures.cs
1 /*
2  *      Firebird ADO.NET Data provider for .NET and Mono 
3  * 
4  *         The contents of this file are subject to the Initial 
5  *         Developer's Public License Version 1.0 (the "License"); 
6  *         you may not use this file except in compliance with the 
7  *         License. You may obtain a copy of the License at 
8  *         http://www.firebirdsql.org/index.php?op=doc&id=idpl
9  *
10  *         Software distributed under the License is distributed on 
11  *         an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either 
12  *         express or implied. See the License for the specific 
13  *         language governing rights and limitations under the License.
14  * 
15  *      Copyright (c) 2002, 2005 Carlos Guzman Alvarez
16  *      All Rights Reserved.
17  */
18
19 using System;
20 using System.Data;
21 using System.Globalization;
22 using System.Text;
23
24 namespace FirebirdSql.Data.Firebird.DbSchema
25 {
26         internal class FbProcedures : FbDbSchema
27         {
28                 #region Constructors
29
30                 public FbProcedures() : base("Procedures")
31                 {
32                 }
33
34                 #endregion
35
36                 #region Protected Methods
37
38                 protected override StringBuilder GetCommandText(object[] restrictions)
39                 {
40                         StringBuilder sql = new StringBuilder();
41                         StringBuilder where = new StringBuilder();
42
43                         sql.Append(
44                                 @"SELECT " +
45                                         "null AS PROCEDURE_CATALOG, " +
46                                         "null AS PROCEDURE_SCHEMA, " +
47                                         "rdb$procedure_name AS PROCEDURE_NAME, " +
48                                         "rdb$procedure_inputs AS INPUTS, " +
49                                         "rdb$procedure_outputs AS OUTPUTS, " +
50                                         "rdb$procedure_source AS SOURCE, " +
51                                         "rdb$description AS DESCRIPTION " +
52                                 "FROM " +
53                                         "rdb$procedures");
54
55                         if (restrictions != null)
56                         {
57                                 int index = 0;
58
59                                 /* PROCEDURE_CATALOG */
60                                 if (restrictions.Length >= 1 && restrictions[0] != null)
61                                 {
62                                 }
63
64                                 /* PROCEDURE_SCHEMA     */
65                                 if (restrictions.Length >= 2 && restrictions[1] != null)
66                                 {
67                                 }
68
69                                 /* PROCEDURE_NAME */
70                                 if (restrictions.Length >= 3 && restrictions[2] != null)
71                                 {
72                                         where.AppendFormat(CultureInfo.CurrentCulture, "rdb$procedure_name = @p{0}", index++);
73                                 }
74                         }
75
76                         if (where.Length > 0)
77                         {
78                                 sql.AppendFormat(CultureInfo.CurrentCulture, " WHERE {0} ", where.ToString());
79                         }
80
81                         sql.Append(" ORDER BY rdb$procedure_name");
82
83                         return sql;
84                 }
85
86                 protected override DataTable ProcessResult(DataTable schema)
87                 {
88                         schema.BeginLoadData();
89
90                         foreach (DataRow row in schema.Rows)
91                         {
92                                 if (row["INPUTS"] == DBNull.Value)
93                                 {
94                                         row["INPUTS"] = 0;
95                                 }
96                                 if (row["OUTPUTS"] == DBNull.Value)
97                                 {
98                                         row["OUTPUTS"] = 0;
99                                 }
100                         }
101
102                         schema.EndLoadData();
103                         schema.AcceptChanges();
104
105                         return schema;
106                 }
107
108                 #endregion
109         }
110 }