Datei: Provider/MySqlConnectorProvider/NDO.MySqlConnector/MySqlProvider.cs

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