@@ -217,96 +217,23 @@ private static async Task ClearPoolAsync(MySqlConnection connection, IOBehavior
217
217
#if ! NETSTANDARD1_3
218
218
protected override DbProviderFactory DbProviderFactory => MySqlClientFactory . Instance ;
219
219
220
- /// <summary>
221
- /// System.Data.Common, initial implementation of API DBConnection.GetSchema(String)
222
- /// Returns schema information for the data source of this DbConnection using the specified string for the schema name.
223
- /// </summary>
224
- /// <param name="collectionName">Specifies the name of the schema to return.</param>
225
- /// <returns>A DataTable that contains schema information.</returns>
226
- public override System . Data . DataTable GetSchema ( string collectionName )
227
- {
228
- return GetSchema ( collectionName , null ) ;
229
- }
220
+ /// <inheritdoc cref="DbConnection.GetSchema()"/>
221
+ public override DataTable GetSchema ( ) => GetSchemaProvider ( ) . GetSchema ( ) ;
230
222
231
-
232
- /// <summary>
233
- /// System.Data.Common, initial implementation of API DBConnection.GetSchema(String)
234
- /// Returns schema information for the data source of this DbConnection using the specified string for the schema name.
235
- /// </summary>
236
- /// <param name="collectionName">Specifies the name of the schema to return.</param>
237
- /// <param name="restrictions">Restrictions not supported yet.</param>
238
- /// <returns>A DataTable that contains schema information.</returns>
239
- public override System . Data . DataTable GetSchema ( string collectionName , string [ ] restrictions )
240
- {
241
- var dt = new DataTable ( collectionName ) ;
242
- switch ( collectionName )
243
- {
244
- case "DataTypes" :
245
- dt . Columns . AddRange ( new [ ] { // The names come from DbMetaDataColumnNames
246
- new DataColumn ( "DataType" , typeof ( string ) ) ,
247
- new DataColumn ( "TypeName" , typeof ( string ) ) ,
248
- new DataColumn ( "ProviderDbType" , typeof ( int ) ) ,
249
- new DataColumn ( "IsUnsigned" , typeof ( bool ) )
250
- } ) ;
251
-
252
- // Column type mappings:
253
- var colTypes = Types . TypeMapper . Instance . GetColumnMappings ( ) ;
254
- foreach ( var map in colTypes )
255
- {
256
- var dbTypeMap = map . DbTypeMapping ;
257
- var dbType = dbTypeMap . DbTypes . FirstOrDefault ( ) ;
258
- dt . Rows . Add ( new object [ ] {
259
- dbTypeMap . ClrType . FullName ,
260
- map . DataTypeName ,
261
- ( int ) dbType ,
262
- map . Unsigned
263
- } ) ;
264
- }
223
+ /// <inheritdoc cref="DbConnection.GetSchema(string)"/>
224
+ public override DataTable GetSchema ( string collectionName ) => GetSchemaProvider ( ) . GetSchema ( collectionName ) ;
265
225
266
- // Data type mappings:
267
- foreach ( MySqlDbType mapItem in Enum . GetValues ( typeof ( MySqlDbType ) ) )
268
- {
269
- var typeName = Enum . GetName ( typeof ( MySqlDbType ) , mapItem ) ;
270
- var dbType = Types . TypeMapper . Instance . GetDbTypeForMySqlDbType ( mapItem ) ;
271
- var map = Types . TypeMapper . Instance . GetDbTypeMapping ( dbType ) ;
272
- if ( map != null ) // MySqlDbType.Set is not supported by the mapper.
273
- {
274
- dt . Rows . Add ( new object [ ] {
275
- map . ClrType . FullName ,
276
- Enum . GetName ( typeof ( MySqlDbType ) , mapItem ) . ToLower ( ) ,
277
- ( int ) dbType ,
278
- typeName . Contains ( "UInt" ) || typeName . Contains ( "UByte" )
279
- } ) ;
280
- }
281
- }
282
- return dt ;
283
-
284
- case "Procedures" :
285
- dt . Columns . AddRange ( new [ ] {
286
- new DataColumn ( "ROUTINE_TYPE" ) ,
287
- new DataColumn ( "ROUTINE_SCHEMA" ) ,
288
- new DataColumn ( "SPECIFIC_NAME" )
289
- } ) ;
290
- var procsQuery = "SELECT ROUTINE_TYPE, ROUTINE_SCHEMA, SPECIFIC_NAME FROM INFORMATION_SCHEMA.ROUTINES;" ;
291
- if ( m_connectionState != ConnectionState . Open )
292
- {
293
- Open ( ) ;
294
- }
295
- using ( var com = new MySqlCommand ( procsQuery , this ) )
296
- using ( var reader = com . ExecuteReader ( ) )
297
- {
298
- while ( reader . Read ( ) )
299
- {
300
- dt . Rows . Add ( new object [ ] { reader . GetString ( 0 ) , reader . GetString ( 1 ) , reader . GetString ( 2 ) } ) ;
301
- }
302
- }
303
- return dt ;
226
+ /// <inheritdoc cref="DbConnection.GetSchema(string)"/>
227
+ public override DataTable GetSchema ( string collectionName , string [ ] restrictions ) => GetSchemaProvider ( ) . GetSchema ( collectionName ) ;
304
228
305
- default :
306
- throw new NotImplementedException ( "Not yet supported: GetSchema(\" " + collectionName + "\" ). Please send a PR." ) ;
307
- }
229
+ private SchemaProvider GetSchemaProvider ( )
230
+ {
231
+ if ( m_schemaProvider == null )
232
+ m_schemaProvider = new SchemaProvider ( this ) ;
233
+ return m_schemaProvider ;
308
234
}
309
235
236
+ SchemaProvider m_schemaProvider ;
310
237
#endif
311
238
312
239
public override int ConnectionTimeout => m_connectionSettings . ConnectionTimeout ;
0 commit comments