Remove some deprecated libraries
[mono.git] / mcs / class / FirebirdSql.Data.Firebird / FirebirdSql.Data.Firebird / DbSchema / FbForeignKeys.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 FbForeignKeys : FbDbSchema
27         {
28                 #region Constructors
29
30                 public FbForeignKeys() : base("ForeignKeys")
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 PK_TABLE_CATALOG, " +
46                                         "null AS PK_TABLE_SCHEMA, " +
47                                         "pk.rdb$relation_name AS PK_TABLE_NAME, " +
48                                         "pkseg.rdb$field_name AS PK_COLUMN_NAME, " +
49                                         "pk.rdb$constraint_name AS PK_NAME, " +
50                                         "null AS FK_TABLE_CATALOG, " +
51                                         "null AS FK_TABLE_SCHEMA, " +
52                                         "fk.rdb$relation_name AS FK_TABLE_NAME, " +
53                                         "fkseg.rdb$field_name AS FK_COLUMN_NAME, " +
54                                         "fk.rdb$constraint_name AS FK_NAME, " +
55                                         "pkseg.rdb$field_position AS ORDINAL_POSITION, " +
56                                         "ref.rdb$match_option AS MATCH_OPTION, " +
57                                         "ref.rdb$update_rule AS UPDATE_RULE, " +
58                                         "ref.rdb$delete_rule AS DELETE_RULE, " +
59                                         "fk.rdb$deferrable AS IS_DEFERRABLE, " +
60                                         "fk.rdb$initially_deferred AS INITIALLY_DEFERRED " +
61                                 "FROM " +
62                                         "rdb$relation_constraints fk, " +
63                                         "rdb$index_segments fkseg, " +
64                                         "rdb$relation_constraints pk, " +
65                                         "rdb$index_segments pkseg, " +
66                                         "rdb$ref_constraints ref ");
67
68                         where.Append(
69                                         "fk.rdb$constraint_name = ref.rdb$constraint_name and " +
70                                         "fk.rdb$index_name = fkseg.rdb$index_name and " +
71                                         "pk.rdb$constraint_name = ref.rdb$const_name_uq and " +
72                                         "pk.rdb$index_name = pkseg.rdb$index_name and " +
73                                         "pkseg.rdb$field_position = fkseg.rdb$field_position ");
74
75                         if (restrictions != null)
76                         {
77                                 int index = 0;
78
79                                 /* PK_TABLE_CATALOG     */
80                                 if (restrictions.Length >= 1 && restrictions[0] != null)
81                                 {
82                                 }
83
84                                 /* PK_TABLE_SCHEMA */
85                                 if (restrictions.Length >= 2 && restrictions[1] != null)
86                                 {
87                                 }
88
89                                 /* PK_TABLE_NAME */
90                                 if (restrictions.Length >= 3 && restrictions[2] != null)
91                                 {
92                                         where.AppendFormat(CultureInfo.CurrentCulture, " and pk.rdb$relation_name = @p{0}", index++);
93                                 }
94
95                                 /* FK_TABLE_CATALOG     */
96                                 if (restrictions.Length >= 4 && restrictions[3] != null)
97                                 {
98                                 }
99
100                                 /* FK_TABLE_SCHEMA */
101                                 if (restrictions.Length >= 5 && restrictions[4] != null)
102                                 {
103                                 }
104
105                                 /* FK_TABLE_NAME */
106                                 if (restrictions.Length >= 6 && restrictions[5] != null)
107                                 {
108                                         where.AppendFormat(CultureInfo.CurrentCulture, " and fk.rdb$relation_name = @p{0}", index++);
109                                 }
110                         }
111
112                         if (where.Length > 0)
113                         {
114                                 sql.AppendFormat(CultureInfo.CurrentCulture, " WHERE {0} ", where.ToString());
115                         }
116
117                         sql.Append(" ORDER BY fk.rdb$constraint_name, pk.rdb$relation_name, pkseg.rdb$field_position");
118
119                         return sql;
120                 }
121
122                 #endregion
123         }
124 }