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

Last Commit (4b748a1)
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
New Commit (f856804)
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 IDbConnection NewConnection( string connectionString)
46 ········{
47 ············return new NdoMySqlConnectorConnection( new MySqlConnection(connectionString) );
48 ········}
49
50 public override IDbCommand NewSqlCommand( IDbConnection connection)
51 ········{
52 ············MySqlCommand command = new MySqlCommand();
53 command. Connection = ( MySqlConnection) ( ( INdoDbConnection) 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( IDbConnection conn, string owner)
275 ········{
276 MySqlCommand cmd = new MySqlCommand( "show tables", ( MySqlConnection) ( ( INdoDbConnection) 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