3 // Christian Hergert <chris@mosaix.net>
4 // Daniel Morgan <danielmorgan@verizon.net>
5 // Ben Motmans <ben.motmans@gmail.com>
7 // Copyright (C) 2005 Mosaix Communications, Inc.
8 // Copyright (C) 2005 Daniel Morgan
9 // Copyright (c) 2007 Ben Motmans
11 // Permission is hereby granted, free of charge, to any person obtaining a copy
12 // of this software and associated documentation files (the "Software"), to deal
13 // in the Software without restriction, including without limitation the rights
14 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 // copies of the Software, and to permit persons to whom the Software is
16 // furnished to do so, subject to the following conditions:
18 // The above copyright notice and this permission notice shall be included in
19 // all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
33 using System
.Data
.OracleClient
;
34 using System
.Collections
.Generic
;
35
namespace MonoDevelop
.Database
.Sql
.Oracle
37 public class OracleSchemaProvider
: AbstractSchemaProvider
39 public OracleSchemaProvider (IConnectionPool connectionPool
)
40 : base (connectionPool
)
42 //TODO: table, column, procedure, view, user, sequence, trigger capabilities
45 // public override ICollection<TableSchema> GetTables ()
47 // CheckConnectionState ();
48 // List<TableSchema> tables = new List<TableSchema> ();
50 // IDbCommand command = connectionProvider.CreateCommand (
51 // "SELECT OWNER, TABLE_NAME, TABLESPACE_NAME " +
52 // "FROM ALL_TABLES " +
53 // "ORDER BY OWNER, TABLE_NAME"
56 // using (IDataReader r = command.ExecuteReader()) {
57 // while (r.Read ()) {
58 // TableSchema table = new TableSchema (this);
60 // table.OwnerName = r.GetValue (0).ToString();
61 // table.SchemaName = r.GetValue (0).ToString();
62 // table.Name = r.GetString (1).ToString();
63 // table.IsSystemTable = IsSystem (table.OwnerName);
64 // table.TableSpaceName = r.GetValue (2).ToString();
66 // StringBuilder sb = new StringBuilder();
67 // sb.AppendFormat ("-- Table: {0}\n", table.Name);
68 // sb.AppendFormat ("-- DROP TABLE {0};\n\n", table.Name);
69 // sb.AppendFormat ("CREATE TABLE {0} (\n", table.Name);
71 // ICollection<ColumnSchema> columns = table.Columns;
72 // string[] parts = new string[columns.Count];
74 // foreach (ColumnSchema col in columns)
75 // parts[i++] = col.Definition;
76 // sb.Append (String.Join (",\n", parts));
78 // ICollection<ConstraintSchema> constraints = table.Constraints;
79 // parts = new string[constraints.Count];
80 // if (constraints.Count > 0)
83 // foreach (ConstraintSchema constr in constraints)
84 // parts[i++] = "\t" + constr.Definition;
85 // sb.Append (String.Join (",\n", parts));
87 // //sb.AppendFormat ("\n) COMMENT '{0}';", table.Comment);
88 // table.Definition = sb.ToString ();
90 // tables.Add (table);
94 // connectionProvider.Close (command.Connection);
100 // public override ICollection<ColumnSchema> GetTableColumns (TableSchema table)
102 // CheckConnectionState ();
103 // List<ColumnSchema> columns = new List<ColumnSchema> ();
105 // IDbCommand command = connectionProvider.CreateCommand (
106 // "SELECT OWNER, TABLE_NAME, COLUMN_NAME, " +
107 // " DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, " +
108 // " NULLABLE, COLUMN_ID, DEFAULT_LENGTH, DATA_DEFAULT " +
109 // "FROM ALL_TAB_COLUMNS " +
110 // "WHERE OWNER = '" + table.OwnerName + "' " +
111 // "AND TABLE_NAME = '" + table.Name + "' " +
112 // "ORDER BY OWNER, TABLE_NAME, COLUMN_ID"
115 // using (IDataReader r = command.ExecuteReader()) {
116 // while (r.Read ()) {
117 // ColumnSchema column = new ColumnSchema (this);
119 // column.Name = GetCheckedString (r, 2);
120 // column.DataTypeName = GetCheckedString (r, 3);
121 // column.OwnerName = table.OwnerName;
122 // column.SchemaName = table.OwnerName;
123 // column.NotNull = GetCheckedString (r, 7) == "Y";
124 // column.Length = GetCheckedInt32 (r, 4);
125 // column.Precision = GetCheckedInt32 (r, 5);
126 // column.Scale = GetCheckedInt32 (r, 6);
127 // column.ColumnID = GetCheckedInt32 (r, 8);
129 // StringBuilder sb = new StringBuilder();
130 // sb.AppendFormat("{0} {1}{2}",
132 // column.DataTypeName,
133 // (column.Length > 0) ? ("(" + column.Length + ")") : "");
134 // sb.AppendFormat(" {0}", column.NotNull ? "NOT NULL" : "NULL");
135 // //if (column.Default.Length > 0)
136 // // sb.AppendFormat(" DEFAULT {0}", column.Default);
137 // column.Definition = sb.ToString();
139 // columns.Add (column);
143 // connectionProvider.Close (command.Connection);
149 // public override ICollection<ViewSchema> GetViews ()
151 // CheckConnectionState ();
152 // List<ViewSchema> views = new List<ViewSchema> ();
154 // IDbCommand command = connectionProvider.CreateCommand (
155 // "SELECT OWNER, VIEW_NAME, TEXT " +
156 // "FROM ALL_VIEWS " +
157 // "ORDER BY OWNER, VIEW_NAME"
160 // using (IDataReader r = command.ExecuteReader()) {
161 // while (r.Read ()) {
162 // ViewSchema view = new ViewSchema (this);
164 // view.Name = r.GetString(1);
165 // view.SchemaName = r.GetString (0);
166 // view.OwnerName = r.GetString (0);
167 // view.Definition = r.GetString (2);
168 // view.IsSystemView = IsSystem (view.OwnerName);
174 // connectionProvider.Close (command.Connection);
179 // public override ICollection<ColumnSchema> GetViewColumns (ViewSchema view)
181 // CheckConnectionState ();
182 // List<ColumnSchema> columns = new List<ColumnSchema> ();
184 // IDbCommand command = connectionProvider.CreateCommand (
186 // " FROM " + view.Name +
190 // using (IDataReader r = command.ExecuteReader()) {
191 // while (r.Read ()) {
192 // for (int i = 0; i < r.FieldCount; i++) {
193 // ColumnSchema column = new ColumnSchema (this);
195 // column.Name = r.GetString (0);
196 // column.DataTypeName = r.GetString (1);
197 // column.SchemaName = view.SchemaName;
198 // column.NotNull = r.GetBoolean (3);
199 // column.Length = r.GetInt32 (2);
201 // columns.Add (column);
206 // connectionProvider.Close (command.Connection);
212 // public override ICollection<ConstraintSchema> GetTableConstraints (TableSchema table)
214 // CheckConnectionState ();
215 // List<ConstraintSchema> constraints = new List<ConstraintSchema> ();
217 // IDbCommand command = connectionProvider.CreateCommand (
218 // "SELECT k.owner, k.table_name, k.constraint_name, " +
219 // " k.constraint_type, k.status, k.validated " +
220 // "FROM all_constraints k " +
221 // "WHERE k.owner = '" + table.OwnerName + "' " +
222 // "AND k.table_name = '" + table.Name + "' " +
223 // "and k.constraint_type = 'P'"
226 // using (IDataReader r = command.ExecuteReader()) {
227 // while (r.Read ()) {
228 // ConstraintSchema constraint = null;
230 // switch (r.GetString(4)) {
233 // constraint = new PrimaryKeyConstraintSchema (this);
237 // constraint.Name = r.GetString (3);
238 // constraint.Definition = "";
240 // constraints.Add (constraint);
244 // connectionProvider.Close (command.Connection);
247 // return constraints;
250 // public override DataTypeSchema GetDataType (string name)
253 // throw new ArgumentNullException ("name");
254 // name = name.ToUpper ();
256 // DataTypeSchema dts = new DataTypeSchema (this);
270 // private bool IsSystem (string owner)