Datei: Provider/OracleProvider/NDO.Oracle/Generator.cs

Last Commit (ab290a4)
1 //
2 // Copyright (c) 2002-2016 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22
23 using System;
24 using System.Text;
25 using System.Collections;
26 using System.Data;
27 using Oracle.ManagedDataAccess.Client;
28 using System.IO;
29 using NDOInterfaces;
30
31
32 namespace OracleProvider
33 {
34 ····public class OracleGenerator : AbstractSQLGenerator
35 ····{
36
37 ········public OracleGenerator()
38 ········{
39 ········}
40
41 public override string CreateIndex( string indexName, string tableName, DataColumn[] indexColums)
42 ········{
43 ············string indexName2 = indexName.Substring(1, indexName.Length - 2);
44 ············uint hash = (uint)indexName2.GetHashCode();
45 ············if (indexName2.Length > 30)
46 ················indexName2 = indexName2.Substring(0, 22) + hash.ToString("X");
47
48 return base. CreateIndex( Provider. GetQuotedName( indexName2) , tableName, indexColums) ;
49 ········}
50
51
52 ········public override string ProviderName
53 ········{
54 ············get { return "Oracle"; }
55 ········}
56
57 ········public override string DropTable(string tableName)
58 ········{
59 ············if (tableName.Length > 35)··// 30 + 4 * '"' + '.'
60 ············{
61 ················string s = "Warning: TableName " + tableName + " is too long.";
62 ················if(messages != null)
63 ····················messages.WriteLine(s);
64 ················else
65 ····················Console.WriteLine(s);
66 ············}
67 ············return "DROP TABLE " + tableName + ";";
68 ········}
69
70
71 ········public override bool LengthAllowed(Type t)
72 ········{
73 ············return t != typeof(DateTime);
74 ········}
75
76 ········public override bool LengthAllowed(string dbType)
77 ········{
78 ············return dbType != "Date";
79 ········}
80
81 ········public override string DbTypeFromType(Type t, int size)
82 ········{
83 ············t = ((NDOAbstractProvider)this.Provider).ConvertNullableType(t);
84
85 ············// The Oracle ADO.NET provider gives us an OracleType.DateTime instead
86 ············// of an OracleType.Date
87 ············if (t == typeof(DateTime))
88 ················return "Date";
89
90 ············if ( t == typeof(bool) || t == typeof(byte) || t == typeof(sbyte) || t == typeof(ushort) || t == typeof(int) || t == typeof(short) || t == typeof(uint) || t == typeof(long) || t == typeof(ulong) || t == typeof(float) || t == typeof(double) || t == typeof(decimal) )
91 ················return "Number";
92
93 ············if (t == typeof( string ) && size == -1)
94 ················return "CLOB";
95
96 ············OracleDbType dbType = (OracleDbType)Provider.GetDbType(t);
97
98 ············return dbType.ToString();
99 ········}
100
101 ········public override string AlterColumnType()
102 ········{
103 ············return ("MODIFY");
104 ········}
105 ····}
106 }
107
New Commit (f5f4fd8)
1 //
2 // Copyright (c) 2002-2016 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22
23 using System;
24 using System.Text;
25 using System.Collections;
26 using System.Data;
27 using Oracle.ManagedDataAccess.Client;
28 using System.IO;
29 using NDOInterfaces;
30
31
32 namespace OracleProvider
33 {
34 ····public class OracleGenerator : AbstractSQLGenerator
35 ····{
36
37 ········public OracleGenerator()
38 ········{
39 ········}
40
41 public override string CreateIndex( string indexName, string tableName, DataColumn[] indexColums, bool isUnique)
42 ········{
43 ············string indexName2 = indexName.Substring(1, indexName.Length - 2);
44 ············uint hash = (uint)indexName2.GetHashCode();
45 ············if (indexName2.Length > 30)
46 ················indexName2 = indexName2.Substring(0, 22) + hash.ToString("X");
47
48 return base. CreateIndex( Provider. GetQuotedName( indexName2) , tableName, indexColums, isUnique) ;
49 ········}
50
51
52 ········public override string ProviderName
53 ········{
54 ············get { return "Oracle"; }
55 ········}
56
57 ········public override string DropTable(string tableName)
58 ········{
59 ············if (tableName.Length > 35)··// 30 + 4 * '"' + '.'
60 ············{
61 ················string s = "Warning: TableName " + tableName + " is too long.";
62 ················if(messages != null)
63 ····················messages.WriteLine(s);
64 ················else
65 ····················Console.WriteLine(s);
66 ············}
67 ············return "DROP TABLE " + tableName + ";";
68 ········}
69
70
71 ········public override bool LengthAllowed(Type t)
72 ········{
73 ············return t != typeof(DateTime);
74 ········}
75
76 ········public override bool LengthAllowed(string dbType)
77 ········{
78 ············return dbType != "Date";
79 ········}
80
81 ········public override string DbTypeFromType(Type t, int size)
82 ········{
83 ············t = ((NDOAbstractProvider)this.Provider).ConvertNullableType(t);
84
85 ············// The Oracle ADO.NET provider gives us an OracleType.DateTime instead
86 ············// of an OracleType.Date
87 ············if (t == typeof(DateTime))
88 ················return "Date";
89
90 ············if ( t == typeof(bool) || t == typeof(byte) || t == typeof(sbyte) || t == typeof(ushort) || t == typeof(int) || t == typeof(short) || t == typeof(uint) || t == typeof(long) || t == typeof(ulong) || t == typeof(float) || t == typeof(double) || t == typeof(decimal) )
91 ················return "Number";
92
93 ············if (t == typeof( string ) && size == -1)
94 ················return "CLOB";
95
96 ············OracleDbType dbType = (OracleDbType)Provider.GetDbType(t);
97
98 ············return dbType.ToString();
99 ········}
100
101 ········public override string AlterColumnType()
102 ········{
103 ············return ("MODIFY");
104 ········}
105 ····}
106 }
107