Datei: NDOEnhancer/NDOEnhancer/Enhancer/Generator/StandardSqlGenerator.cs

Last Commit (ab290a4)
1 //
2 // Copyright (c) 2002-2022 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.Data;
25 using NDOInterfaces;
26
27 namespace NDOEnhancer
28 {
29 ····/// <summary>
30 ····/// Zusammenfassung für StandardGenerator.
31 ····/// </summary>
32 ····internal class StandardSqlGenerator : AbstractSQLGenerator
33 ····{
34
35 ········public StandardSqlGenerator()
36 ········{············
37 ········}
38
39 ········string providerName = "Standard";
40
41 ········public void SetProviderName(string providerName)
42 ········{
43 ············this.providerName = providerName;
44 ········}
45
46 ········#region ISqlGenerator Member
47
48 ········public override string ProviderName
49 ········{
50 ············get
51 ············{
52 ················return providerName;
53 ············}
54 ········}
55
56 ········public override string ConnectToDatabase(string connectionString)
57 ········{
58 ············return "-- No Sql Generator for NDO Provider '" + providerName + "' found; this code was generated using the standard code generator.";
59 ········}
60
61
62 public override string CreateIndex( string indexName, string tableName, DataColumn[] indexColums)
63 ········{
64 ············string indexName2 = indexName.Substring(1, indexName.Length - 2);
65 ············uint hash = (uint) indexName2.GetHashCode();
66 ············if (indexName2.Length > 30)
67 ················indexName2 = indexName2.Substring(0, 22) + hash.ToString("X");
68
69 return base. CreateIndex ( Provider. GetQuotedName( indexName2) , tableName, indexColums) ;
70 ········}
71
72
73 ········public override bool LengthAllowed(Type t)
74 ········{
75 ············return t == typeof(Decimal) || t == typeof(Guid) || t == typeof(string);
76 ········}
77
78 ········public override bool LengthAllowed(string dbType)
79 ········{
80 ············return string.Compare(dbType, "varchar", true) == 0
81 ················|| string.Compare(dbType, "char", true) == 0
82 ················|| string.Compare(dbType, "decimal", true) == 0;
83 ········}
84
85 ········public override string DbTypeFromType(Type t, int size)
86 ········{
87 ············if ( t == typeof(bool) ||··t == typeof(byte) || t == typeof(sbyte)
88 ················|| t == typeof(char) || t == typeof(short) || t == typeof(ushort) )
89 ················return "SMALLINT";
90 ············else if ( t == typeof(int)|| t == typeof(uint) || t.IsSubclassOf(typeof(System.Enum)))
91 ················return "INTEGER";
92 ············else if ( t == typeof(long)|| t == typeof(ulong))
93 ················return "BIGINT";
94 ············else if ( t == typeof(System.Guid))
95 ················return "CHAR";
96 ············else if ( t == typeof(float))
97 ················return "FLOAT";
98 ············else if ( t == typeof(double))
99 ················return "DOUBLE PRECISION";
100 ············else if ( t == typeof(string))
101 ················return "VARCHAR";
102 ············else if ( t == typeof(byte[]))
103 ················return "BLOB";
104 ············else if ( t == typeof(decimal))
105 ················return "DECIMAL";
106 ············else if ( t == typeof(System.DateTime))
107 ················return "DATE";
108 ············else
109 ················return "VARCHAR";
110 ········}
111
112
113
114 ········public override string PrimaryKeyColumn(string columnName, Type dataType, string columnType, string width)
115 ········{
116 ············return columnName + ' ' + columnType + " NOT NULL CONSTRAINT PRIMARYKEY PRIMARY KEY";
117 ········}
118
119
120
121 ········public override string NullExpression(bool allowNull)
122 ········{
123 ············if (allowNull)
124 ················return "NULL";
125 ············else
126 ················return "NOT NULL";
127
128 ········}
129
130 ········#endregion
131 ····}
132 }
133
New Commit (f5f4fd8)
1 //
2 // Copyright (c) 2002-2022 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.Data;
25 using NDOInterfaces;
26
27 namespace NDOEnhancer
28 {
29 ····/// <summary>
30 ····/// Zusammenfassung für StandardGenerator.
31 ····/// </summary>
32 ····internal class StandardSqlGenerator : AbstractSQLGenerator
33 ····{
34
35 ········public StandardSqlGenerator()
36 ········{············
37 ········}
38
39 ········string providerName = "Standard";
40
41 ········public void SetProviderName(string providerName)
42 ········{
43 ············this.providerName = providerName;
44 ········}
45
46 ········#region ISqlGenerator Member
47
48 ········public override string ProviderName
49 ········{
50 ············get
51 ············{
52 ················return providerName;
53 ············}
54 ········}
55
56 ········public override string ConnectToDatabase(string connectionString)
57 ········{
58 ············return "-- No Sql Generator for NDO Provider '" + providerName + "' found; this code was generated using the standard code generator.";
59 ········}
60
61
62 public override string CreateIndex( string indexName, string tableName, DataColumn[] indexColums, bool isUnique)
63 ········{
64 ············string indexName2 = indexName.Substring(1, indexName.Length - 2);
65 ············uint hash = (uint) indexName2.GetHashCode();
66 ············if (indexName2.Length > 30)
67 ················indexName2 = indexName2.Substring(0, 22) + hash.ToString("X");
68
69 return base. CreateIndex ( Provider. GetQuotedName( indexName2) , tableName, indexColums, isUnique) ;
70 ········}
71
72
73 ········public override bool LengthAllowed(Type t)
74 ········{
75 ············return t == typeof(Decimal) || t == typeof(Guid) || t == typeof(string);
76 ········}
77
78 ········public override bool LengthAllowed(string dbType)
79 ········{
80 ············return string.Compare(dbType, "varchar", true) == 0
81 ················|| string.Compare(dbType, "char", true) == 0
82 ················|| string.Compare(dbType, "decimal", true) == 0;
83 ········}
84
85 ········public override string DbTypeFromType(Type t, int size)
86 ········{
87 ············if ( t == typeof(bool) ||··t == typeof(byte) || t == typeof(sbyte)
88 ················|| t == typeof(char) || t == typeof(short) || t == typeof(ushort) )
89 ················return "SMALLINT";
90 ············else if ( t == typeof(int)|| t == typeof(uint) || t.IsSubclassOf(typeof(System.Enum)))
91 ················return "INTEGER";
92 ············else if ( t == typeof(long)|| t == typeof(ulong))
93 ················return "BIGINT";
94 ············else if ( t == typeof(System.Guid))
95 ················return "CHAR";
96 ············else if ( t == typeof(float))
97 ················return "FLOAT";
98 ············else if ( t == typeof(double))
99 ················return "DOUBLE PRECISION";
100 ············else if ( t == typeof(string))
101 ················return "VARCHAR";
102 ············else if ( t == typeof(byte[]))
103 ················return "BLOB";
104 ············else if ( t == typeof(decimal))
105 ················return "DECIMAL";
106 ············else if ( t == typeof(System.DateTime))
107 ················return "DATE";
108 ············else
109 ················return "VARCHAR";
110 ········}
111
112
113
114 ········public override string PrimaryKeyColumn(string columnName, Type dataType, string columnType, string width)
115 ········{
116 ············return columnName + ' ' + columnType + " NOT NULL CONSTRAINT PRIMARYKEY PRIMARY KEY";
117 ········}
118
119
120
121 ········public override string NullExpression(bool allowNull)
122 ········{
123 ············if (allowNull)
124 ················return "NULL";
125 ············else
126 ················return "NOT NULL";
127
128 ········}
129
130 ········#endregion
131 ····}
132 }
133