Datei: Provider/MySqlNdoProvider/NDO.MySql/MySqlProvider.cs

Last Commit (e9b343b)
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.Text.RegularExpressions;
26 using System.Data;
27 using System.Data.Common;
28 using NDOInterfaces;
29 using System.Collections;
30 using MySql.Data.MySqlClient;
31 using MySql.Data.Types;
32
33 namespace NDO.MySqlProvider
34 {
35 ····/// <summary>
36 ····/// Sample adapter class to connect new ADO.NET Providers with NDO.
37 ····/// This Adapter is based on the MySql MySql Data Connector
38 ····/// </summary>
39 ····public class Provider : NDOAbstractProvider
40 ····{
41 ········// The following methods provide objects of provider classes
42 ········// which implement common interfaces in .NET:
43 ········// IDbConnection, IDbCommand, DbDataAdapter and the Parameter objects
44 ········#region Provide specialized type objects
45 ········public override System.Data.IDbConnection NewConnection(string connectionString)
46 ········{
47 ············return new MySqlConnection(connectionString);
48 ········}
49
50 ········public override System.Data.IDbCommand NewSqlCommand(System.Data.IDbConnection connection)
51 ········{
52 ············MySqlCommand command = new MySqlCommand();
53 ············command.Connection = (MySqlConnection)connection;
54 ············return command;
55 ········}
56
57 ········public override DbDataAdapter NewDataAdapter(System.Data.IDbCommand select, System.Data.IDbCommand update, System.Data.IDbCommand insert, System.Data.IDbCommand delete)
58 ········{
59 ············MySqlDataAdapter da = new MySqlDataAdapter();
60 ············da.SelectCommand = (MySqlCommand)select;
61 ············da.UpdateCommand = (MySqlCommand)update;
62 ············da.InsertCommand = (MySqlCommand)insert;
63 ············da.DeleteCommand = (MySqlCommand)delete;
64 ············return da;
65 ········}
66
67 ········/// <summary>
68 ········/// See <see cref="IProvider"> IProvider interface </see>
69 ········/// </summary>
70 ········public override object NewCommandBuilder(DbDataAdapter dataAdapter)
71 ········{
72 ············return new MySqlCommandBuilder((MySqlDataAdapter)dataAdapter);
73 ········}
74
75
76 ········public override IDataParameter AddParameter(System.Data.IDbCommand command, string parameterName, object dbType, int size, string columnName)
77 ········{
78 ············return ((MySqlCommand)command).Parameters.Add(new MySqlParameter(parameterName, (MySql.Data.MySqlClient.MySqlDbType)dbType, size, columnName));············
79 ········}
80
81 ········public override IDataParameter AddParameter(IDbCommand command, string parameterName, object dbType, int size, ParameterDirection dir, bool isNullable, byte precision, byte scale, string srcColumn, DataRowVersion srcVersion, object value)
82 ········{
83 ············return ((MySqlCommand)command).Parameters.Add(new MySqlParameter(parameterName, (MySql.Data.MySqlClient.MySqlDbType)dbType, size, dir, isNullable, precision, scale, srcColumn, srcVersion, value));
84 ········}
85 ········#endregion
86
87 ········// The following method convert System.Type objects to MySql.Data.MySqlClient.MySqlDbType-Members
88 ········// For your own adapter use members of the database type emumeration
89 ········// of your ADO.NET provider
90 ········#region Provide MySql.Data.MySqlClient.MySqlDbType members
91 ········public override object GetDbType(Type t)
92 ········{
93 ············t = base.ConvertNullableType(t);
94 ············if ( t == typeof(bool) )
95 ················return MySql.Data.MySqlClient.MySqlDbType.Byte;
96 ············else if ( t == typeof(byte) )
97 ················return MySql.Data.MySqlClient.MySqlDbType.Byte;
98 ············else if ( t == typeof(sbyte) )
99 ················return MySql.Data.MySqlClient.MySqlDbType.Byte;
100 ············else if ( t == typeof(char) )
101 ················return MySql.Data.MySqlClient.MySqlDbType.Int16;
102 ············else if ( t == typeof(short))
103 ················return MySql.Data.MySqlClient.MySqlDbType.Int16;
104 ············else if ( t == typeof(ushort))
105 ················return MySql.Data.MySqlClient.MySqlDbType.Int16;
106 ············else if ( t == typeof(int))
107 ················return MySql.Data.MySqlClient.MySqlDbType.Int32;
108 ············else if ( t == typeof(uint))
109 ················return MySql.Data.MySqlClient.MySqlDbType.Int32;
110 ············else if ( t == typeof(long))
111 ················return MySql.Data.MySqlClient.MySqlDbType.Int64;
112 ············else if ( t == typeof(System.Guid))
113 ················return MySql.Data.MySqlClient.MySqlDbType.VarChar;
114 ············else if ( t == typeof(ulong))
115 ················return MySql.Data.MySqlClient.MySqlDbType.Int64;
116 ············else if ( t == typeof(float))
117 ················return MySql.Data.MySqlClient.MySqlDbType.Float;
118 ············else if ( t == typeof(double))
119 ················return MySql.Data.MySqlClient.MySqlDbType.Double;
120 ············else if ( t == typeof(string))
121 ················return MySql.Data.MySqlClient.MySqlDbType.VarChar;
122 ············else if ( t == typeof(byte[]))
123 ················return MySql.Data.MySqlClient.MySqlDbType.MediumBlob;
124 ············else if ( t == typeof(decimal))
125 ················return MySql.Data.MySqlClient.MySqlDbType.Decimal;
126 ············else if ( t == typeof(System.DateTime))
127 ················return MySql.Data.MySqlClient.MySqlDbType.DateTime;
128 ············else if ( t.IsSubclassOf(typeof(System.Enum)))
129 ················return MySql.Data.MySqlClient.MySqlDbType.Int32;
130 ············else
131 ················throw new NDOException(27, "NDO.MySqlProvider.GetDbType: Typ " + t.Name + " kann nicht in MySql.Data.MySqlClient.MySqlDbType konvertiert werden");
132 ········}
133
134 ········// The following method converts string representations of MySql.Data.MySqlClient.MySqlDbType-Members
135 ········// into MySql.Data.MySqlClient.MySqlDbType.
136 ········// For your own adapter use members of the database type emumeration of your
137 ········// ADO.NET provider and convert it to the respective enumeration type········
138 ········public override object GetDbType(string typeName)
139 ········{
140 ············if (Enum.TryParse<MySqlDbType>( typeName, out var dbtype ))
141 ················return dbtype;
142 ············if (typeName == "BigInt")
143 ················return MySqlDbType.Int64;
144 ············if (typeName == "Datetime")
145 ················return MySqlDbType.DateTime;
146 ············if (typeName == "Long")
147 ················return MySqlDbType.Int64;
148 ············if (typeName == "LongLong")
149 ················return MySqlDbType.Int64;
150 ············throw new NDOException(27, "NDOMySql.Provider.GetDbType: Typname " + typeName + " kann nicht in MySql.Data.MySqlClient.MySqlDbType konvertiert werden");
151 ········}
152
153 ········public override string GetDbTypeString( IDbDataParameter parameter )
154 ········{
155 ············return (((MySqlParameter)parameter).MySqlDbType).ToString();
156 ········}
157
158 ········private string GetDateExpression(System.DateTime dt)
159 ········{
160 ············//'9999-12-31 23:59:59'
161 ············return "'" + dt.ToString("yyyy-MM-dd HH:mm:ss") + "'";
162 ········}
163 ····
164
165 ········public override int GetDefaultLength(System.Type t)
166 ········{
167 ············t = base.ConvertNullableType(t);
168 ············if ( t == typeof(bool) )
169 ················return 1;
170 ············else if ( t == typeof(byte) )
171 ················return 1;
172 ············else if ( t == typeof(sbyte) )
173 ················return 1;
174 ············else if ( t == typeof(char) )
175 ················return 2;
176 ············else if ( t == typeof(short))
177 ················return 2;
178 ············else if ( t == typeof(ushort))
179 ················return 2;
180 ············else if ( t == typeof(int))
181 ················return 4;
182 ············else if ( t == typeof(uint))
183 ················return 4;
184 ············else if ( t == typeof(long))
185 ················return 8;
186 ············else if ( t == typeof(System.Guid))
187 ················return 36;
188 ············else if ( t == typeof(ulong))
189 ················return 8;
190 ············else if ( t == typeof(float))
191 ················return 4;
192 ············else if ( t == typeof(double))
193 ················return 8;
194 ············else if ( t == typeof(string))
195 ················return 255;
196 ············else if ( t == typeof(byte[]))
197 ················return 100000;
198 ············else if ( t == typeof(decimal))
199 ················return 18;
200 ············else if ( t == typeof(System.DateTime))
201 ················return 16;
202 ············else if ( t.IsSubclassOf(typeof(System.Enum)))
203 ················return 4;
204 ············else
205 ················return 0;········
206 ········}
207
208
209 ········public override string Wildcard
210 ········{
211 ············get { return "%"; }
212 ········}
213
214 ········public override bool UseNamedParams
215 ········{
216 ············get { return true; }
217 ········}
218
219
220 ········#endregion
221 ········
222 ········//private Hashtable namedParameters = new Hashtable();
223 ········public override string GetNamedParameter(string plainParameterName)
224 ········{
225 ············return "?" + plainParameterName;
226 ········}
227 ····
228 ········public override string GetQuotedName(string plainName)
229 ········{
230 ············return "`" + plainName + "`";
231 ········}
232 ····
233 ········public override string GetSqlLiteral(object o)
234 ········{
235 ············if (o is DateTime)
236 ················return this.GetDateExpression((DateTime)o);
237 ············return base.GetSqlLiteral (o);
238 ········}
239 ········
240
241 ········/// <summary>
242 ········/// Indicates whether the last automatically generated ID can be retrieved.
243 ········/// Returns true if a database provides automatically incremented IDs and its syntax has an expression
244 ········/// which retrieves the last generated ID; otherwise false.
245 ········/// </summary>
246 ········public override bool SupportsLastInsertedId
247 ········{
248 ············get { return true; }
249 ········}
250
251
252 ········/// <summary>
253 ········/// Gets an expression in the SQL dialect of the database, which retrieves the ID of the last
254 ········/// inserted row, if the ID is automatically generated by the database.
255 ········/// </summary>
256 ········public override string GetLastInsertedId(string tableName, string columnName)
257 ········{
258 ············return "LAST_INSERT_ID()";
259 ········}
260
261 ········/// <summary>
262 ········/// Determines whether a database supports bulk command strings.
263 ········/// </summary>
264 ········public override bool SupportsBulkCommands
265 ········{
266 ············get { return true; }
267 ········}
268 ········
269
270 ········/// <summary>
271 ········/// Generate one big command string out of several partial commands to save roundtrips
272 ········/// to the server.
273 ········/// </summary>
274 ········/// <param name="commands"></param>
275 ········/// <returns></returns>
276 ········public override string GenerateBulkCommand(string[] commands)
277 ········{
278 ············StringBuilder sb = new StringBuilder(commands.Length * 100);
279 ············foreach (string s in commands)
280 ············{
281 ················sb.Append(s);
282 ················sb.Append(';');
283 ············}
284 ············return sb.ToString();
285 ········}
286
287 ············
288 ········public override string[] GetTableNames(IDbConnection conn, string owner)
289 ········{
290 ············MySqlCommand cmd = new MySqlCommand("show tables", (MySqlConnection) conn);
291 ············bool wasOpen = true;
292 ············if (conn.State == ConnectionState.Closed)
293 ············{
294 ················conn.Open();
295 ················wasOpen = false;
296 ············}
297 ············MySqlDataReader dr = cmd.ExecuteReader();
298 ············IList result = new ArrayList();
299 ············while (dr.Read())
300 ················result.Add(dr.GetString(0));
301 ············dr.Close();
302 ············if (!wasOpen)
303 ················conn.Close();
304 ············string[] strresult = new string[result.Count];
305 ············for (int i = 0; i < result.Count; i++)
306 ················strresult[i] = (string) result[i];
307 ············return strresult;
308 ········}
309 ····
310 ········public override string[] TypeNames
311 ········{
312 ············get
313 ············{················
314 ················return Enum.GetNames(typeof(MySql.Data.MySqlClient.MySqlDbType));
315 ············}
316 ········}
317
318 ········public override string Name { get { return "MySql"; }··}
319
320 ········public override bool SupportsInsertBatch
321 ········{
322 ············get
323 ············{
324 ················return true;
325 ············}
326 ········}
327
328 ········public override bool SupportsNativeGuidType
329 ········{
330 ············get { return false; }
331 ········}
332
333 ········public override string FetchLimit( int skip, int take )
334 ········{
335 ············return "LIMIT " + take + " OFFSET " + skip;
336 ········}
337
338
339 ········public override string CreateDatabase(string databaseName, string connectionString, object additionalData)
340 ········{
341 ············base.CreateDatabase( databaseName, connectionString, additionalData );
342
343 ············Regex regex = new Regex(@"Database\s*=([^\;]*)");
344 ············Match match = regex.Match( connectionString );
345 ············if (match.Success)
346 ············{
347 ················return connectionString.Substring(0, match.Groups[1].Index) + databaseName + connectionString.Substring(match.Index + match.Length);
348 ············}
349 ············
350 ············if (!connectionString.EndsWith(";"))
351 ················connectionString = connectionString + ";";
352 ············
353 ············return connectionString + "Database=" + databaseName;
354 ········}
355 ····}
356 }
357
New Commit (273289e)
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.Text.RegularExpressions;
26 using System.Data;
27 using System.Data.Common;
28 using NDOInterfaces;
29 using System.Collections;
30 using MySql.Data.MySqlClient;
31 using MySql.Data.Types;
32
33 namespace NDO.MySqlProvider
34 {
35 ····/// <summary>
36 ····/// Sample adapter class to connect new ADO.NET Providers with NDO.
37 ····/// This Adapter is based on the MySql MySql Data Connector
38 ····/// </summary>
39 ····public class Provider : NDOAbstractProvider
40 ····{
41 ········// The following methods provide objects of provider classes
42 ········// which implement common interfaces in .NET:
43 ········// IDbConnection, IDbCommand, DbDataAdapter and the Parameter objects
44 ········#region Provide specialized type objects
45 ········public override System.Data.IDbConnection NewConnection(string connectionString)
46 ········{
47 ············return new MySqlConnection(connectionString);
48 ········}
49
50 ········public override System.Data.IDbCommand NewSqlCommand(System.Data.IDbConnection connection)
51 ········{
52 ············MySqlCommand command = new MySqlCommand();
53 ············command.Connection = (MySqlConnection)connection;
54 ············return command;
55 ········}
56
57 ········public override DbDataAdapter NewDataAdapter(System.Data.IDbCommand select, System.Data.IDbCommand update, System.Data.IDbCommand insert, System.Data.IDbCommand delete)
58 ········{
59 ············MySqlDataAdapter da = new MySqlDataAdapter();
60 ············da.SelectCommand = (MySqlCommand)select;
61 ············da.UpdateCommand = (MySqlCommand)update;
62 ············da.InsertCommand = (MySqlCommand)insert;
63 ············da.DeleteCommand = (MySqlCommand)delete;
64 ············return da;
65 ········}
66
67 ········/// <summary>
68 ········/// See <see cref="IProvider"> IProvider interface </see>
69 ········/// </summary>
70 ········public override object NewCommandBuilder(DbDataAdapter dataAdapter)
71 ········{
72 ············return new MySqlCommandBuilder((MySqlDataAdapter)dataAdapter);
73 ········}
74
75
76 ········public override IDataParameter AddParameter(System.Data.IDbCommand command, string parameterName, object dbType, int size, string columnName)
77 ········{
78 ············return ((MySqlCommand)command).Parameters.Add(new MySqlParameter(parameterName, (MySql.Data.MySqlClient.MySqlDbType)dbType, size, columnName));············
79 ········}
80
81 ········public override IDataParameter AddParameter(IDbCommand command, string parameterName, object dbType, int size, ParameterDirection dir, bool isNullable, byte precision, byte scale, string srcColumn, DataRowVersion srcVersion, object value)
82 ········{
83 ············return ((MySqlCommand)command).Parameters.Add(new MySqlParameter(parameterName, (MySql.Data.MySqlClient.MySqlDbType)dbType, size, dir, isNullable, precision, scale, srcColumn, srcVersion, value));
84 ········}
85 ········#endregion
86
87 ········// The following method convert System.Type objects to MySql.Data.MySqlClient.MySqlDbType-Members
88 ········// For your own adapter use members of the database type emumeration
89 ········// of your ADO.NET provider
90 ········#region Provide MySql.Data.MySqlClient.MySqlDbType members
91 ········public override object GetDbType(Type t)
92 ········{
93 ············t = base.ConvertNullableType(t);
94 ············if ( t == typeof(bool) )
95 ················return MySql.Data.MySqlClient.MySqlDbType.Byte;
96 ············else if ( t == typeof(byte) )
97 ················return MySql.Data.MySqlClient.MySqlDbType.Byte;
98 ············else if ( t == typeof(sbyte) )
99 ················return MySql.Data.MySqlClient.MySqlDbType.Byte;
100 ············else if ( t == typeof(char) )
101 ················return MySql.Data.MySqlClient.MySqlDbType.Int16;
102 ············else if ( t == typeof(short))
103 ················return MySql.Data.MySqlClient.MySqlDbType.Int16;
104 ············else if ( t == typeof(ushort))
105 ················return MySql.Data.MySqlClient.MySqlDbType.Int16;
106 ············else if ( t == typeof(int))
107 ················return MySql.Data.MySqlClient.MySqlDbType.Int32;
108 ············else if ( t == typeof(uint))
109 ················return MySql.Data.MySqlClient.MySqlDbType.Int32;
110 ············else if ( t == typeof(long))
111 ················return MySql.Data.MySqlClient.MySqlDbType.Int64;
112 ············else if ( t == typeof(System.Guid))
113 ················return MySql.Data.MySqlClient.MySqlDbType.VarChar;
114 ············else if ( t == typeof(ulong))
115 ················return MySql.Data.MySqlClient.MySqlDbType.Int64;
116 ············else if ( t == typeof(float))
117 ················return MySql.Data.MySqlClient.MySqlDbType.Float;
118 ············else if ( t == typeof(double))
119 ················return MySql.Data.MySqlClient.MySqlDbType.Double;
120 ············else if ( t == typeof(string))
121 ················return MySql.Data.MySqlClient.MySqlDbType.VarChar;
122 ············else if ( t == typeof(byte[]))
123 ················return MySql.Data.MySqlClient.MySqlDbType.MediumBlob;
124 ············else if ( t == typeof(decimal))
125 ················return MySql.Data.MySqlClient.MySqlDbType.Decimal;
126 ············else if ( t == typeof(System.DateTime))
127 ················return MySql.Data.MySqlClient.MySqlDbType.DateTime;
128 ············else if ( t.IsSubclassOf(typeof(System.Enum)))
129 ················return MySql.Data.MySqlClient.MySqlDbType.Int32;
130 ············else
131 ················throw new NDOException(27, "NDO.MySqlProvider.GetDbType: Typ " + t.Name + " kann nicht in MySql.Data.MySqlClient.MySqlDbType konvertiert werden");
132 ········}
133
134 ········// The following method converts string representations of MySql.Data.MySqlClient.MySqlDbType-Members
135 ········// into MySql.Data.MySqlClient.MySqlDbType.
136 ········// For your own adapter use members of the database type emumeration of your
137 ········// ADO.NET provider and convert it to the respective enumeration type········
138 ········public override object GetDbType(string typeName)
139 ········{
140 ············if (Enum.TryParse<MySqlDbType>( typeName, out var dbtype ))
141 ················return dbtype;
142 ············if (typeName == "BigInt")
143 ················return MySqlDbType.Int64;
144 ············if (typeName == "Datetime")
145 ················return MySqlDbType.DateTime;
146 ············if (typeName == "Long")
147 ················return MySqlDbType.Int64;
148 ············if (typeName == "LongLong")
149 ················return MySqlDbType.Int64;
150 ············throw new NDOException(27, "NDOMySql.Provider.GetDbType: Typname " + typeName + " kann nicht in MySql.Data.MySqlClient.MySqlDbType konvertiert werden");
151 ········}
152
153 ········public override string GetDbTypeString( IDbDataParameter parameter )
154 ········{
155 ············return (((MySqlParameter)parameter).MySqlDbType).ToString();
156 ········}
157
 
 
 
 
 
158
 
159 ········public override int GetDefaultLength(System.Type t)
160 ········{
161 ············t = base.ConvertNullableType(t);
162 ············if ( t == typeof(bool) )
163 ················return 1;
164 ············else if ( t == typeof(byte) )
165 ················return 1;
166 ············else if ( t == typeof(sbyte) )
167 ················return 1;
168 ············else if ( t == typeof(char) )
169 ················return 2;
170 ············else if ( t == typeof(short))
171 ················return 2;
172 ············else if ( t == typeof(ushort))
173 ················return 2;
174 ············else if ( t == typeof(int))
175 ················return 4;
176 ············else if ( t == typeof(uint))
177 ················return 4;
178 ············else if ( t == typeof(long))
179 ················return 8;
180 ············else if ( t == typeof(System.Guid))
181 ················return 36;
182 ············else if ( t == typeof(ulong))
183 ················return 8;
184 ············else if ( t == typeof(float))
185 ················return 4;
186 ············else if ( t == typeof(double))
187 ················return 8;
188 ············else if ( t == typeof(string))
189 ················return 255;
190 ············else if ( t == typeof(byte[]))
191 ················return 100000;
192 ············else if ( t == typeof(decimal))
193 ················return 18;
194 ············else if ( t == typeof(System.DateTime))
195 ················return 16;
196 ············else if ( t.IsSubclassOf(typeof(System.Enum)))
197 ················return 4;
198 ············else
199 ················return 0;········
200 ········}
201
202
203 ········public override string Wildcard
204 ········{
205 ············get { return "%"; }
206 ········}
207
208 ········public override bool UseNamedParams
209 ········{
210 ············get { return true; }
211 ········}
212
213
214 ········#endregion
215 ········
216 ········//private Hashtable namedParameters = new Hashtable();
217 ········public override string GetNamedParameter(string plainParameterName)
218 ········{
219 ············return "?" + plainParameterName;
220 ········}
221 ····
222 ········public override string GetQuotedName(string plainName)
223 ········{
224 ············return "`" + plainName + "`";
 
 
 
 
 
 
 
225 ········}
 
226 ········
227 ········/// <summary>
228 ········/// Indicates whether the last automatically generated ID can be retrieved.
229 ········/// Returns true if a database provides automatically incremented IDs and its syntax has an expression
230 ········/// which retrieves the last generated ID; otherwise false.
231 ········/// </summary>
232 ········public override bool SupportsLastInsertedId
233 ········{
234 ············get { return true; }
235 ········}
236
237
238 ········/// <summary>
239 ········/// Gets an expression in the SQL dialect of the database, which retrieves the ID of the last
240 ········/// inserted row, if the ID is automatically generated by the database.
241 ········/// </summary>
242 ········public override string GetLastInsertedId(string tableName, string columnName)
243 ········{
244 ············return "LAST_INSERT_ID()";
245 ········}
246
247 ········/// <summary>
248 ········/// Determines whether a database supports bulk command strings.
249 ········/// </summary>
250 ········public override bool SupportsBulkCommands
251 ········{
252 ············get { return true; }
253 ········}
254 ········
255
256 ········/// <summary>
257 ········/// Generate one big command string out of several partial commands to save roundtrips
258 ········/// to the server.
259 ········/// </summary>
260 ········/// <param name="commands"></param>
261 ········/// <returns></returns>
262 ········public override string GenerateBulkCommand(string[] commands)
263 ········{
264 ············StringBuilder sb = new StringBuilder(commands.Length * 100);
265 ············foreach (string s in commands)
266 ············{
267 ················sb.Append(s);
268 ················sb.Append(';');
269 ············}
270 ············return sb.ToString();
271 ········}
272
273 ············
274 ········public override string[] GetTableNames(IDbConnection conn, string owner)
275 ········{
276 ············MySqlCommand cmd = new MySqlCommand("show tables", (MySqlConnection) conn);
277 ············bool wasOpen = true;
278 ············if (conn.State == ConnectionState.Closed)
279 ············{
280 ················conn.Open();
281 ················wasOpen = false;
282 ············}
283 ············MySqlDataReader dr = cmd.ExecuteReader();
284 ············IList result = new ArrayList();
285 ············while (dr.Read())
286 ················result.Add(dr.GetString(0));
287 ············dr.Close();
288 ············if (!wasOpen)
289 ················conn.Close();
290 ············string[] strresult = new string[result.Count];
291 ············for (int i = 0; i < result.Count; i++)
292 ················strresult[i] = (string) result[i];
293 ············return strresult;
294 ········}
295 ····
296 ········public override string[] TypeNames
297 ········{
298 ············get
299 ············{················
300 ················return Enum.GetNames(typeof(MySql.Data.MySqlClient.MySqlDbType));
301 ············}
302 ········}
303
304 ········public override string Name { get { return "MySql"; }··}
305
306 ········public override bool SupportsInsertBatch
307 ········{
308 ············get
309 ············{
310 ················return true;
311 ············}
312 ········}
313
314 ········public override bool SupportsNativeGuidType
315 ········{
316 ············get { return false; }
317 ········}
318
319 ········public override string FetchLimit( int skip, int take )
320 ········{
321 ············return "LIMIT " + take + " OFFSET " + skip;
322 ········}
323
324
325 ········public override string CreateDatabase(string databaseName, string connectionString, object additionalData)
326 ········{
327 ············base.CreateDatabase( databaseName, connectionString, additionalData );
328
329 ············Regex regex = new Regex(@"Database\s*=([^\;]*)");
330 ············Match match = regex.Match( connectionString );
331 ············if (match.Success)
332 ············{
333 ················return connectionString.Substring(0, match.Groups[1].Index) + databaseName + connectionString.Substring(match.Index + match.Length);
334 ············}
335 ············
336 ············if (!connectionString.EndsWith(";"))
337 ················connectionString = connectionString + ";";
338 ············
339 ············return connectionString + "Database=" + databaseName;
340 ········}
341 ····}
342 }
343