Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.DataImporter/HeuristicLab.DataImporter.DbExplorer.Oracle/OracleExplorer.cs @ 15061

Last change on this file since 15061 was 9615, checked in by mkommend, 11 years ago

#1734: Updated copyright information in all DataImporter classes.

File size: 4.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Data.Common;
25using System.Globalization;
26using HeuristicLab.DataImporter.DbExplorer.Interfaces;
27
28namespace HeuristicLab.DataImporter.DbExplorer.Oracle {
29  public class OracleExplorer : DbExplorerBase {
30
31    private enum NumericDataType { Number, Binary_Float, Binary_Double, Smallint, Int, bigint, Float, Real }
32    public override bool IsNumericDataType(string type) {
33      NumericDataType numericDataType;
34      return Enum.TryParse<NumericDataType>(type, true, out numericDataType);
35    }
36
37    private enum DateDataType { Date, TimeStamp } //caution TimeStamp With Time Zone, With Local Time Zone also available
38    public override bool IsDateDataType(string type) {
39      DateDataType dateDataType;
40      return Enum.TryParse<DateDataType>(type, true, out dateDataType);
41    }
42
43    private enum StringDataType { Char, NChar, Varchar, Varchar2, NVarchar2 }
44    public override bool IsStringDataType(string type) {
45      StringDataType stringDataType;
46      return Enum.TryParse<StringDataType>(type, true, out stringDataType);
47    }
48
49    public override bool IsFilterableDataType(string type) {
50      return IsNumericDataType(type) || IsDateDataType(type) || IsStringDataType(type);
51    }
52
53    public override string MenuItemDescription {
54      get { return "Connect to Oracle"; }
55    }
56
57    private OracleConnectionWizard wizard;
58    protected override IDbConnectionWizard DbConnectionWizard {
59      get {
60        if (wizard == null)
61          wizard = new OracleConnectionWizard();
62        return wizard;
63      }
64    }
65
66    public override IEnumerable<DbTable> AllTables {
67      get {
68        if (Connection == null) {
69          throw new InvalidOperationException("Connection to database not correctly set!");
70        }
71        List<DbTable> allTables = new List<DbTable>();
72        using (DbConnection conn = Connection.CreateConnection()) {
73          conn.Open();
74          using (DbCommand cmd = conn.CreateCommand()) {
75            cmd.CommandText = @"select owner,table_name from all_tables where lower(owner) not like '%sys%' union " +
76                              @"select owner,view_name from all_views where lower(owner) not like '%sys%' order by owner,table_name";
77            using (DbDataReader reader = cmd.ExecuteReader()) {
78              while (reader.Read()) {
79                allTables.Add(new DbTable(reader.GetString(0), reader.GetString(1)));
80              }
81              reader.Close();
82            }//end using reader
83          }//end using command
84
85          //fill columns for table
86          foreach (DbTable table in allTables) {
87            using (DbCommand cmd = conn.CreateCommand()) {
88              cmd.CommandText = @"select column_name,data_type from all_tab_columns where table_name = '" + table.TableName + "' and owner = '" + table.OwnerName + "'";
89              using (DbDataReader reader = cmd.ExecuteReader()) {
90                while (reader.Read()) {
91                  table.AddColumn(new DbColumn(reader.GetString(0), reader.GetString(1)));
92                }
93                reader.Close();
94              }//end using reader
95            }//end using command
96          }//end foreach table
97          conn.Close();
98        }//end using connection
99        allTables.Sort(new DbTableComparator());
100
101        return allTables;
102      }
103    }
104
105    protected override string ConvertDate(DateTime date) {
106      string ret = date.ToString(CultureInfo.InvariantCulture);
107      ret = "to_date('" + ret + "','MM/DD/YYYY HH24:MI:SS')";
108      return ret;
109    }
110
111    protected override string ConvertDouble(double value) {
112      return value.ToString(CultureInfo.InvariantCulture);
113    }
114
115  }
116}
Note: See TracBrowser for help on using the repository browser.