f6cd82ae16db805c49d3f5510cc149e65f77bcb2
[mono.git] / mcs / class / FirebirdSql.Data.Firebird / FirebirdSql.Data.Firebird / DbSchema / FbViewPrivileges.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 FbViewPrivileges : FbDbSchema
27         {
28                 #region Constructors
29
30                 public FbViewPrivileges() : base("ViewPrivileges")
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 VIEW_CATALOG, " +
46                                         "null AS VIEW_SCHEMA, " +
47                                         "priv.rdb$relation_name AS VIEW_NAME, " +
48                                         "priv.rdb$user AS GRANTEE, " +
49                                         "priv.rdb$grantor AS GRANTOR, " +
50                                         "priv.rdb$privilege AS PRIVILEGE, " +
51                                         "priv.rdb$grant_option AS WITH_GRANT " +
52                                 "FROM " +
53                                         "rdb$user_privileges priv " +
54                                         "left join rdb$relations rel ON priv.rdb$relation_name = rel.rdb$relation_name");
55
56                         where.Append("priv.rdb$object_type = 0");
57                         where.Append(" AND rel.rdb$view_source IS NOT NULL");
58
59                         if (restrictions != null)
60                         {
61                                 int index = 0;
62
63                                 /* VIEW_CATALOG */
64                                 if (restrictions.Length >= 1 && restrictions[0] != null)
65                                 {
66                                 }
67
68                                 /* VIEW_SCHEMA */
69                                 if (restrictions.Length >= 2 && restrictions[1] != null)
70                                 {
71                                 }
72
73                                 /* VIEW_NAME */
74                                 if (restrictions.Length >= 3 && restrictions[2] != null)
75                                 {
76                                         where.AppendFormat(CultureInfo.CurrentCulture, " AND priv.rdb$relation_name = @p{0}", index++);
77                                 }
78
79                                 /* GRANTOR */
80                                 if (restrictions.Length >= 4 && restrictions[3] != null)
81                                 {
82                                         where.AppendFormat(CultureInfo.CurrentCulture, " AND priv.rdb$grantor = @p{0}", index++);
83                                 }
84
85                                 /* GRANTEE */
86                                 if (restrictions.Length >= 5 && restrictions[4] != null)
87                                 {
88                                         where.AppendFormat(CultureInfo.CurrentCulture, " AND priv.rdb$user = @p{0}", index++);
89                                 }
90                         }
91
92                         if (where.Length > 0)
93                         {
94                                 sql.AppendFormat(CultureInfo.CurrentCulture, " WHERE {0} ", where.ToString());
95                         }
96
97                         sql.Append(" ORDER BY priv.rdb$relation_name, priv.rdb$user");
98
99                         return sql;
100                 }
101
102                 #endregion
103         }
104 }