Datei: NDOInterfaces/AbstractSQLGenerator.cs
Last Commit (2a2e7ba)
1 | // |
2 | // Copyright (c) 2002-2019 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 System.Text; |
26 | |
27 | namespace NDOInterfaces |
28 | { |
29 | ····/// <summary> |
30 | ····/// Zusammenfassung für AbstractSQLGenerator. |
31 | ····/// </summary> |
32 | ····public abstract class AbstractSQLGenerator : ISqlGenerator |
33 | ····{ |
34 | ········/// <summary> |
35 | ········/// The NDO provider used to quote names. |
36 | ········/// </summary> |
37 | ········private IProvider provider; |
38 | |
39 | ········/// <summary> |
40 | ········/// This property is used by the enhancer to get and set the ndo provider, |
41 | ········/// the generator belongs to. The provider is used to quote table and column names. |
42 | ········/// </summary> |
43 | ········public virtual IProvider Provider |
44 | ········{ |
45 | ············get { return provider; } |
46 | ············set { provider = value; } |
47 | ········} |
48 | |
49 | ········/// <summary> |
50 | ········/// Error messages go there. |
51 | ········/// </summary> |
52 | ········protected IMessageAdapter messages; |
53 | |
54 | ········/// <summary> |
55 | ········/// Default Constructor. |
56 | ········/// </summary> |
57 | ········public AbstractSQLGenerator() |
58 | ········{ |
59 | ········} |
60 | |
61 | ········#region ISqlGenerator Member |
62 | |
63 | ········/// <summary> |
64 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
65 | ········/// </summary> |
66 | ········public abstract string ProviderName { get; } |
67 | |
68 | ········/// <summary> |
69 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
70 | ········/// </summary> |
71 | ········/// <param name="messages"></param> |
72 | ········public virtual void SetMessageAdapter(IMessageAdapter messages) |
73 | ········{ |
74 | ············this.messages = messages; |
75 | ········} |
76 | ········/// <summary> |
77 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
78 | ········/// </summary> |
79 | ········/// <param name="tableName"></param> |
80 | ········/// <returns></returns> |
81 | ········public virtual string DropTable(string tableName) |
82 | ········{ |
83 | ············return "DROP TABLE " + tableName + ";";············ |
84 | ········} |
85 | |
86 | ········/// <summary> |
87 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
88 | ········/// </summary> |
89 | ········/// <param name="connectionString"></param> |
90 | ········/// <returns></returns> |
91 | ········public virtual string ConnectToDatabase(string connectionString) |
92 | ········{ |
93 | ············return string.Empty; |
94 | ········} |
95 | |
96 | ········/// <summary> |
97 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
98 | ········/// </summary> |
99 | ········/// <param name="tableName"></param> |
100 | ········/// <returns></returns> |
101 | ········public virtual string BeginnTable(string tableName) |
102 | ········{············ |
103 | ············return "CREATE TABLE " + tableName + "("; |
104 | ········} |
105 | |
106 | ········/// <summary> |
107 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
108 | ········/// </summary> |
109 | ········/// <param name="tableName"></param> |
110 | ········/// <returns></returns> |
111 | ········public virtual string EndTable(string tableName) |
112 | ········{ |
113 | ············return ");"; |
114 | ········} |
115 | |
116 | ········/// <summary> |
117 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
118 | ········/// </summary> |
119 | ········public virtual NDOInterfaces.PrimaryConstraintPlacement PrimaryConstraintPlacement |
120 | ········{ |
121 | ············get { return PrimaryConstraintPlacement.InTable; } |
122 | ········} |
123 | |
124 | ········/// <summary> |
125 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
126 | ········/// </summary> |
127 | ········/// <param name="t"></param> |
128 | ········/// <returns></returns> |
129 | ········public abstract bool LengthAllowed(Type t); |
130 | |
131 | ········/// <summary> |
132 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
133 | ········/// </summary> |
134 | ········/// <param name="dbType"></param> |
135 | ········/// <returns></returns> |
136 | ········public abstract bool LengthAllowed(string dbType); |
137 | |
138 | ········/// <summary> |
139 | ········/// Converts a System.Type to default DbType value. |
140 | ········/// </summary> |
141 | ········/// <param name="t">The type to convert.</param> |
142 | ········/// <param name="size">The intended size of the type. If type is string, the value -1 means, that a CLOB type should be returned.</param> |
143 | ········/// <returns>A string representation of the DbType.</returns> |
144 | ········/// <remarks> |
145 | ········/// Concrete providers should override this function to provide DbType names, |
146 | ········/// which can be used in the DDL code of the underlying database. |
147 | ········/// </remarks> |
148 | ········public abstract string DbTypeFromType(Type t, int size = 0); |
149 | |
150 | ········/// <summary> |
151 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
152 | ········/// </summary> |
153 | ········/// <param name="columnName"></param> |
154 | ········/// <param name="dataType"></param> |
155 | ········/// <param name="columnType"></param> |
156 | ········/// <param name="width"></param> |
157 | ········/// <returns></returns> |
158 | public virtual string AutoIncrementColumn( string columnName, Type dataType, string columnType, string width) |
159 | ········{ |
160 | ············return string.Empty; |
161 | ········} |
162 | |
163 | ········/// <summary> |
164 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
165 | ········/// </summary> |
166 | ········/// <param name="columnName"></param> |
167 | ········/// <param name="dataType"></param> |
168 | ········/// <param name="columnType"></param> |
169 | ········/// <param name="width"></param> |
170 | ········/// <returns></returns> |
171 | ········public virtual string PrimaryKeyColumn(string columnName, Type dataType, string columnType, string width) |
172 | ········{ |
173 | ············return string.Empty; |
174 | ········} |
175 | |
176 | ········/// <summary> |
177 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
178 | ········/// </summary> |
179 | ········public virtual bool HasSpecialAutoIncrementColumnFormat |
180 | ········{ |
181 | ············get { return false; } |
182 | ········} |
183 | |
184 | ········/// <summary> |
185 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
186 | ········/// </summary> |
187 | ········/// <param name="primaryKeyColumns"></param> |
188 | ········/// <param name="constraintName"></param> |
189 | ········/// <param name="tableName"></param> |
190 | ········/// <returns></returns> |
191 | ········public virtual string CreatePrimaryKeyConstraint(System.Data.DataColumn[] primaryKeyColumns, string constraintName, string tableName) |
192 | ········{ |
193 | ············StringBuilder sb = new StringBuilder("CONSTRAINT "); |
194 | ············sb.Append(constraintName); |
195 | ············sb.Append(" PRIMARY KEY "); |
196 | ············GenerateColumnList(primaryKeyColumns, sb); |
197 | ············return sb.ToString(); |
198 | ········} |
199 | |
200 | ········/// <summary> |
201 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
202 | ········/// </summary> |
203 | ········/// <param name="sourceColumns"></param> |
204 | ········/// <param name="relatedColumns"></param> |
205 | ········/// <param name="constraintName"></param> |
206 | ········/// <param name="relatedTableName"></param> |
207 | ········/// <returns></returns> |
208 | ········public virtual string CreateForeignKeyConstraint(DataColumn[] sourceColumns, DataColumn[] relatedColumns, string constraintName, string relatedTableName) |
209 | ········{ |
210 | ············StringBuilder sb = new StringBuilder("CONSTRAINT "); |
211 | ············sb.Append(constraintName); |
212 | ············sb.Append(" FOREIGN KEY "); |
213 | ············GenerateColumnList(sourceColumns, sb); |
214 | ············sb.Append(" REFERENCES "); |
215 | ············sb.Append(relatedTableName); |
216 | ············GenerateColumnList(relatedColumns, sb); |
217 | ············return sb.ToString(); |
218 | ········} |
219 | |
220 | |
221 | ········/// <summary> |
222 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
223 | ········/// </summary> |
224 | ········/// <param name="allowNull"></param> |
225 | ········/// <returns></returns> |
226 | ········public virtual string NullExpression(bool allowNull) |
227 | ········{ |
228 | ············if (allowNull) |
229 | ················return "NULL"; |
230 | ············else |
231 | ················return "NOT NULL"; |
232 | ········} |
233 | |
234 | ········/// <summary> |
235 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
236 | ········/// </summary> |
237 | ········/// <param name="columns"></param> |
238 | ········/// <param name="sb"></param> |
239 | ········void GenerateColumnList(DataColumn[] columns, StringBuilder sb) |
240 | ········{ |
241 | ············sb.Append("("); |
242 | ············int lastIndex = columns.Length - 1; |
243 | ············for (int i = 0; i < columns.Length; i++) |
244 | ············{ |
245 | ················DataColumn dc = columns[i]; |
246 | ················sb.Append(provider.GetQuotedName(dc.ColumnName)); |
247 | ················if (i < lastIndex) |
248 | ····················sb.Append(","); |
249 | ············} |
250 | ············sb.Append(")"); |
251 | ········} |
252 | |
253 | ········/// <summary> |
254 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
255 | ········/// </summary> |
256 | ········/// <param name="indexName"></param> |
257 | ········/// <param name="tableName"></param> |
258 | ········/// <param name="indexColums"></param> |
259 | ········/// <returns></returns> |
260 | ········public virtual string CreateIndex(string indexName, string tableName, DataColumn[] indexColums) |
261 | ········{ |
262 | ············StringBuilder sb = new StringBuilder("CREATE INDEX "); |
263 | ············sb.Append(indexName); |
264 | ············sb.Append(" ON "); |
265 | ············sb.Append(tableName); |
266 | ············GenerateColumnList(indexColums, sb); |
267 | ············return sb.ToString(); |
268 | ········} |
269 | |
270 | ········/// <summary> |
271 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
272 | ········/// Override this function, if dropping a column needs another syntax than |
273 | ········/// 'ADD column_definition'. |
274 | ········/// </summary> |
275 | ········/// <returns></returns> |
276 | ········public virtual string AddColumn() |
277 | ········{ |
278 | ············return "ADD"; |
279 | ········} |
280 | |
281 | ········/// <summary> |
282 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
283 | ········/// Override this function, if dropping a column needs another syntax than |
284 | ········/// 'DROP COLUMN ColName' |
285 | ········/// </summary> |
286 | ········/// <param name="colName"></param> |
287 | ········/// <returns></returns> |
288 | ········public virtual string RemoveColumn(string colName) |
289 | ········{ |
290 | ············return "DROP COLUMN " + colName; |
291 | ········} |
292 | |
293 | ········/// <summary> |
294 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
295 | ········/// Override this function, if renaming a column needs another syntax than |
296 | ········/// a sequence of ADD COLUMN, UPDATE and DROP COLUMN. |
297 | ········/// </summary> |
298 | ········/// <param name="tableName"></param> |
299 | ········/// <param name="oldName"></param> |
300 | ········/// <param name="newName"></param> |
301 | ········/// <param name="typeName"></param> |
302 | ········/// <returns>This default implementaton returns an empty string (see remarks).</returns> |
303 | ········/// <remarks> |
304 | ········/// If RenameColumn returns an empty string, NDO tries to synthesize the rename function |
305 | ········/// with a sequence of ADD COLUMN, UPDATE and DROP COLUMN. |
306 | ········/// </remarks> |
307 | ········public virtual string RenameColumn(string tableName, string oldName, string newName, string typeName) |
308 | ········{ |
309 | ············return string.Empty; |
310 | ········} |
311 | |
312 | ········/// <summary> |
313 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
314 | ········/// Override this function, if altering a column type needs another syntax than |
315 | ········/// 'ALTER column_definition' |
316 | ········/// </summary> |
317 | ········/// <returns></returns> |
318 | ········public virtual string AlterColumnType() |
319 | ········{ |
320 | ············return "ALTER"; |
321 | ········} |
322 | |
323 | ········#endregion |
324 | ····} |
325 | } |
326 |
New Commit (1e68dc7)
1 | // |
2 | // Copyright (c) 2002-2019 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 System.Text; |
26 | |
27 | namespace NDOInterfaces |
28 | { |
29 | ····/// <summary> |
30 | ····/// Zusammenfassung für AbstractSQLGenerator. |
31 | ····/// </summary> |
32 | ····public abstract class AbstractSQLGenerator : ISqlGenerator |
33 | ····{ |
34 | ········/// <summary> |
35 | ········/// The NDO provider used to quote names. |
36 | ········/// </summary> |
37 | ········private IProvider provider; |
38 | |
39 | ········/// <summary> |
40 | ········/// This property is used by the enhancer to get and set the ndo provider, |
41 | ········/// the generator belongs to. The provider is used to quote table and column names. |
42 | ········/// </summary> |
43 | ········public virtual IProvider Provider |
44 | ········{ |
45 | ············get { return provider; } |
46 | ············set { provider = value; } |
47 | ········} |
48 | |
49 | ········/// <summary> |
50 | ········/// Error messages go there. |
51 | ········/// </summary> |
52 | ········protected IMessageAdapter messages; |
53 | |
54 | ········/// <summary> |
55 | ········/// Default Constructor. |
56 | ········/// </summary> |
57 | ········public AbstractSQLGenerator() |
58 | ········{ |
59 | ········} |
60 | |
61 | ········#region ISqlGenerator Member |
62 | |
63 | ········/// <summary> |
64 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
65 | ········/// </summary> |
66 | ········public abstract string ProviderName { get; } |
67 | |
68 | ········/// <summary> |
69 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
70 | ········/// </summary> |
71 | ········/// <param name="messages"></param> |
72 | ········public virtual void SetMessageAdapter(IMessageAdapter messages) |
73 | ········{ |
74 | ············this.messages = messages; |
75 | ········} |
76 | ········/// <summary> |
77 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
78 | ········/// </summary> |
79 | ········/// <param name="tableName"></param> |
80 | ········/// <returns></returns> |
81 | ········public virtual string DropTable(string tableName) |
82 | ········{ |
83 | ············return "DROP TABLE " + tableName + ";";············ |
84 | ········} |
85 | |
86 | ········/// <summary> |
87 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
88 | ········/// </summary> |
89 | ········/// <param name="connectionString"></param> |
90 | ········/// <returns></returns> |
91 | ········public virtual string ConnectToDatabase(string connectionString) |
92 | ········{ |
93 | ············return string.Empty; |
94 | ········} |
95 | |
96 | ········/// <summary> |
97 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
98 | ········/// </summary> |
99 | ········/// <param name="tableName"></param> |
100 | ········/// <returns></returns> |
101 | ········public virtual string BeginnTable(string tableName) |
102 | ········{············ |
103 | ············return "CREATE TABLE " + tableName + "("; |
104 | ········} |
105 | |
106 | ········/// <summary> |
107 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
108 | ········/// </summary> |
109 | ········/// <param name="tableName"></param> |
110 | ········/// <returns></returns> |
111 | ········public virtual string EndTable(string tableName) |
112 | ········{ |
113 | ············return ");"; |
114 | ········} |
115 | |
116 | ········/// <summary> |
117 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
118 | ········/// </summary> |
119 | ········public virtual NDOInterfaces.PrimaryConstraintPlacement PrimaryConstraintPlacement |
120 | ········{ |
121 | ············get { return PrimaryConstraintPlacement.InTable; } |
122 | ········} |
123 | |
124 | ········/// <summary> |
125 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
126 | ········/// </summary> |
127 | ········/// <param name="t"></param> |
128 | ········/// <returns></returns> |
129 | ········public abstract bool LengthAllowed(Type t); |
130 | |
131 | ········/// <summary> |
132 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
133 | ········/// </summary> |
134 | ········/// <param name="dbType"></param> |
135 | ········/// <returns></returns> |
136 | ········public abstract bool LengthAllowed(string dbType); |
137 | |
138 | ········/// <summary> |
139 | ········/// Converts a System.Type to default DbType value. |
140 | ········/// </summary> |
141 | ········/// <param name="t">The type to convert.</param> |
142 | ········/// <param name="size">The intended size of the type. If type is string, the value -1 means, that a CLOB type should be returned.</param> |
143 | ········/// <returns>A string representation of the DbType.</returns> |
144 | ········/// <remarks> |
145 | ········/// Concrete providers should override this function to provide DbType names, |
146 | ········/// which can be used in the DDL code of the underlying database. |
147 | ········/// </remarks> |
148 | ········public abstract string DbTypeFromType(Type t, int size = 0); |
149 | |
150 | ········/// <summary> |
151 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
152 | ········/// </summary> |
153 | ········/// <param name="columnName"></param> |
154 | ········/// <param name="dataType"></param> |
155 | ········/// <param name="columnType"></param> |
156 | ········/// <param name="width"></param> |
157 | ········/// <returns></returns> |
158 | public virtual string AutoIncrementColumn( string columnName, Type dataType, string columnType, string width, bool isPrimary) |
159 | ········{ |
160 | ············return string.Empty; |
161 | ········} |
162 | |
163 | ········/// <summary> |
164 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
165 | ········/// </summary> |
166 | ········/// <param name="columnName"></param> |
167 | ········/// <param name="dataType"></param> |
168 | ········/// <param name="columnType"></param> |
169 | ········/// <param name="width"></param> |
170 | ········/// <returns></returns> |
171 | ········public virtual string PrimaryKeyColumn(string columnName, Type dataType, string columnType, string width) |
172 | ········{ |
173 | ············return string.Empty; |
174 | ········} |
175 | |
176 | ········/// <summary> |
177 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
178 | ········/// </summary> |
179 | ········public virtual bool HasSpecialAutoIncrementColumnFormat |
180 | ········{ |
181 | ············get { return false; } |
182 | ········} |
183 | |
184 | ········/// <summary> |
185 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
186 | ········/// </summary> |
187 | ········/// <param name="primaryKeyColumns"></param> |
188 | ········/// <param name="constraintName"></param> |
189 | ········/// <param name="tableName"></param> |
190 | ········/// <returns></returns> |
191 | ········public virtual string CreatePrimaryKeyConstraint(System.Data.DataColumn[] primaryKeyColumns, string constraintName, string tableName) |
192 | ········{ |
193 | ············StringBuilder sb = new StringBuilder("CONSTRAINT "); |
194 | ············sb.Append(constraintName); |
195 | ············sb.Append(" PRIMARY KEY "); |
196 | ············GenerateColumnList(primaryKeyColumns, sb); |
197 | ············return sb.ToString(); |
198 | ········} |
199 | |
200 | ········/// <summary> |
201 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
202 | ········/// </summary> |
203 | ········/// <param name="sourceColumns"></param> |
204 | ········/// <param name="relatedColumns"></param> |
205 | ········/// <param name="constraintName"></param> |
206 | ········/// <param name="relatedTableName"></param> |
207 | ········/// <returns></returns> |
208 | ········public virtual string CreateForeignKeyConstraint(DataColumn[] sourceColumns, DataColumn[] relatedColumns, string constraintName, string relatedTableName) |
209 | ········{ |
210 | ············StringBuilder sb = new StringBuilder("CONSTRAINT "); |
211 | ············sb.Append(constraintName); |
212 | ············sb.Append(" FOREIGN KEY "); |
213 | ············GenerateColumnList(sourceColumns, sb); |
214 | ············sb.Append(" REFERENCES "); |
215 | ············sb.Append(relatedTableName); |
216 | ············GenerateColumnList(relatedColumns, sb); |
217 | ············return sb.ToString(); |
218 | ········} |
219 | |
220 | |
221 | ········/// <summary> |
222 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
223 | ········/// </summary> |
224 | ········/// <param name="allowNull"></param> |
225 | ········/// <returns></returns> |
226 | ········public virtual string NullExpression(bool allowNull) |
227 | ········{ |
228 | ············if (allowNull) |
229 | ················return "NULL"; |
230 | ············else |
231 | ················return "NOT NULL"; |
232 | ········} |
233 | |
234 | ········/// <summary> |
235 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
236 | ········/// </summary> |
237 | ········/// <param name="columns"></param> |
238 | ········/// <param name="sb"></param> |
239 | ········void GenerateColumnList(DataColumn[] columns, StringBuilder sb) |
240 | ········{ |
241 | ············sb.Append("("); |
242 | ············int lastIndex = columns.Length - 1; |
243 | ············for (int i = 0; i < columns.Length; i++) |
244 | ············{ |
245 | ················DataColumn dc = columns[i]; |
246 | ················sb.Append(provider.GetQuotedName(dc.ColumnName)); |
247 | ················if (i < lastIndex) |
248 | ····················sb.Append(","); |
249 | ············} |
250 | ············sb.Append(")"); |
251 | ········} |
252 | |
253 | ········/// <summary> |
254 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
255 | ········/// </summary> |
256 | ········/// <param name="indexName"></param> |
257 | ········/// <param name="tableName"></param> |
258 | ········/// <param name="indexColums"></param> |
259 | ········/// <returns></returns> |
260 | ········public virtual string CreateIndex(string indexName, string tableName, DataColumn[] indexColums) |
261 | ········{ |
262 | ············StringBuilder sb = new StringBuilder("CREATE INDEX "); |
263 | ············sb.Append(indexName); |
264 | ············sb.Append(" ON "); |
265 | ············sb.Append(tableName); |
266 | ············GenerateColumnList(indexColums, sb); |
267 | ············return sb.ToString(); |
268 | ········} |
269 | |
270 | ········/// <summary> |
271 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
272 | ········/// Override this function, if dropping a column needs another syntax than |
273 | ········/// 'ADD column_definition'. |
274 | ········/// </summary> |
275 | ········/// <returns></returns> |
276 | ········public virtual string AddColumn() |
277 | ········{ |
278 | ············return "ADD"; |
279 | ········} |
280 | |
281 | ········/// <summary> |
282 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
283 | ········/// Override this function, if dropping a column needs another syntax than |
284 | ········/// 'DROP COLUMN ColName' |
285 | ········/// </summary> |
286 | ········/// <param name="colName"></param> |
287 | ········/// <returns></returns> |
288 | ········public virtual string RemoveColumn(string colName) |
289 | ········{ |
290 | ············return "DROP COLUMN " + colName; |
291 | ········} |
292 | |
293 | ········/// <summary> |
294 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
295 | ········/// Override this function, if renaming a column needs another syntax than |
296 | ········/// a sequence of ADD COLUMN, UPDATE and DROP COLUMN. |
297 | ········/// </summary> |
298 | ········/// <param name="tableName"></param> |
299 | ········/// <param name="oldName"></param> |
300 | ········/// <param name="newName"></param> |
301 | ········/// <param name="typeName"></param> |
302 | ········/// <returns>This default implementaton returns an empty string (see remarks).</returns> |
303 | ········/// <remarks> |
304 | ········/// If RenameColumn returns an empty string, NDO tries to synthesize the rename function |
305 | ········/// with a sequence of ADD COLUMN, UPDATE and DROP COLUMN. |
306 | ········/// </remarks> |
307 | ········public virtual string RenameColumn(string tableName, string oldName, string newName, string typeName) |
308 | ········{ |
309 | ············return string.Empty; |
310 | ········} |
311 | |
312 | ········/// <summary> |
313 | ········/// See <see cref="ISqlGenerator">ISqlGenerator interface</see>. |
314 | ········/// Override this function, if altering a column type needs another syntax than |
315 | ········/// 'ALTER column_definition' |
316 | ········/// </summary> |
317 | ········/// <returns></returns> |
318 | ········public virtual string AlterColumnType() |
319 | ········{ |
320 | ············return "ALTER"; |
321 | ········} |
322 | |
323 | ········#endregion |
324 | ····} |
325 | } |
326 |