@@ -18,6 +18,8 @@ public SchemaProvider(MySqlConnection connection)
18
18
{ "DataTypes" , FillDataTypes } ,
19
19
{ "Procedures" , FillProcedures } ,
20
20
{ "ReservedWords" , FillReservedWords } ,
21
+ { "Tables" , FillTables } ,
22
+ { "Views" , FillViews } ,
21
23
} ;
22
24
}
23
25
@@ -469,6 +471,97 @@ private void FillReservedWords(DataTable dataTable)
469
471
dataTable . Rows . Add ( word ) ;
470
472
}
471
473
474
+ private void FillTables ( DataTable dataTable )
475
+ {
476
+ dataTable . Columns . AddRange ( new [ ]
477
+ {
478
+ new DataColumn ( "TABLE_CATALOG" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
479
+ new DataColumn ( "TABLE_SCHEMA" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
480
+ new DataColumn ( "TABLE_NAME" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
481
+ new DataColumn ( "TABLE_TYPE" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
482
+ new DataColumn ( "ENGINE" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
483
+ new DataColumn ( "VERSION" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
484
+ new DataColumn ( "ROW_FORMAT" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
485
+ new DataColumn ( "TABLE_ROWS" , typeof ( long ) ) , // lgtm[cs/local-not-disposed]
486
+ new DataColumn ( "AVG_ROW_LENGTH" , typeof ( long ) ) , // lgtm[cs/local-not-disposed]
487
+ new DataColumn ( "DATA_LENGTH" , typeof ( long ) ) , // lgtm[cs/local-not-disposed]
488
+ new DataColumn ( "MAX_DATA_LENGTH" , typeof ( long ) ) , // lgtm[cs/local-not-disposed]
489
+ new DataColumn ( "INDEX_LENGTH" , typeof ( long ) ) , // lgtm[cs/local-not-disposed]
490
+ new DataColumn ( "DATA_FREE" , typeof ( long ) ) , // lgtm[cs/local-not-disposed]
491
+ new DataColumn ( "AUTO_INCREMENT" , typeof ( long ) ) , // lgtm[cs/local-not-disposed]
492
+ new DataColumn ( "CREATE_TIME" , typeof ( DateTime ) ) , // lgtm[cs/local-not-disposed]
493
+ new DataColumn ( "UPDATE_TIME" , typeof ( DateTime ) ) , // lgtm[cs/local-not-disposed]
494
+ new DataColumn ( "CHECK_TIME" , typeof ( DateTime ) ) , // lgtm[cs/local-not-disposed]
495
+ new DataColumn ( "TABLE_COLLATION" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
496
+ new DataColumn ( "CHECKSUM" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
497
+ new DataColumn ( "CREATE_OPTIONS" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
498
+ new DataColumn ( "TABLE_COMMENT" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
499
+ } ) ;
500
+
501
+ Action ? close = null ;
502
+ if ( m_connection . State != ConnectionState . Open )
503
+ {
504
+ m_connection . Open ( ) ;
505
+ close = m_connection . Close ;
506
+ }
507
+
508
+ using ( var command = m_connection . CreateCommand ( ) )
509
+ {
510
+ #pragma warning disable CA2100
511
+ command . CommandText = "SELECT " + string . Join ( ", " , dataTable . Columns . Cast < DataColumn > ( ) . Select ( x => x . ColumnName ) ) + " FROM INFORMATION_SCHEMA.TABLES;" ;
512
+ #pragma warning restore CA2100
513
+ using var reader = command . ExecuteReader ( ) ;
514
+ while ( reader . Read ( ) )
515
+ {
516
+ var rowValues = new object [ dataTable . Columns . Count ] ;
517
+ reader . GetValues ( rowValues ) ;
518
+ dataTable . Rows . Add ( rowValues ) ;
519
+ }
520
+ }
521
+
522
+ close ? . Invoke ( ) ;
523
+ }
524
+
525
+ private void FillViews ( DataTable dataTable )
526
+ {
527
+ dataTable . Columns . AddRange ( new [ ]
528
+ {
529
+ new DataColumn ( "TABLE_CATALOG" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
530
+ new DataColumn ( "TABLE_SCHEMA" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
531
+ new DataColumn ( "TABLE_NAME" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
532
+ new DataColumn ( "VIEW_DEFINITION" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
533
+ new DataColumn ( "CHECK_OPTION" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
534
+ new DataColumn ( "IS_UPDATABLE" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
535
+ new DataColumn ( "DEFINER" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
536
+ new DataColumn ( "SECURITY_TYPE" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
537
+ new DataColumn ( "CHARACTER_SET_CLIENT" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
538
+ new DataColumn ( "COLLATION_CONNECTION" , typeof ( string ) ) , // lgtm[cs/local-not-disposed]
539
+ } ) ;
540
+
541
+ Action ? close = null ;
542
+ if ( m_connection . State != ConnectionState . Open )
543
+ {
544
+ m_connection . Open ( ) ;
545
+ close = m_connection . Close ;
546
+ }
547
+
548
+ using ( var command = m_connection . CreateCommand ( ) )
549
+ {
550
+ #pragma warning disable CA2100
551
+ command . CommandText = "SELECT " + string . Join ( ", " , dataTable . Columns . Cast < DataColumn > ( ) . Select ( x => x . ColumnName ) ) + " FROM INFORMATION_SCHEMA.VIEWS;" ;
552
+ #pragma warning restore CA2100
553
+ using var reader = command . ExecuteReader ( ) ;
554
+ while ( reader . Read ( ) )
555
+ {
556
+ var rowValues = new object [ dataTable . Columns . Count ] ;
557
+ reader . GetValues ( rowValues ) ;
558
+ dataTable . Rows . Add ( rowValues ) ;
559
+ }
560
+ }
561
+
562
+ close ? . Invoke ( ) ;
563
+ }
564
+
472
565
readonly MySqlConnection m_connection ;
473
566
readonly Dictionary < string , Action < DataTable > > m_schemaCollections ;
474
567
}
0 commit comments