Advertisement
Geoclasm

SQL.GetTables( )

Dec 7th, 2015
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1.     /// <summary>
  2.     /// Return Multiple Tables from a Data Set.
  3.     /// </summary>
  4.     /// <param name="Tables">Tables for which to query</param>
  5.     /// <param name="Filters">
  6.     /// Array of filters for each table.
  7.     /// Must contain a filter for each table in the form of FIELD0 equatable @param_val_0, ..., FIELDN equatable @param_val_N
  8.     /// Filter strings can be null.
  9.     /// </param>
  10.     /// <param name="Parameters">
  11.     /// Array of an array of objects for each filter.
  12.     /// Must contain an object set for each table.
  13.     /// Object sets can be null.
  14.     /// </param>
  15.     public async Task GetTables( string[ ] Tables, string[ ] Filters, object[ ][ ] Parameters ) {
  16.         this.Adapters = new MySqlDataAdapter[Tables.Length];
  17.         int FilterIndex;
  18.         object[ ] ParameterSet = null;
  19.         string Query = null, Filter = null;
  20.         foreach ( string Table in Tables ) {
  21.             FilterIndex = Tables.ToList( ).IndexOf( Table );
  22.             Filter = Filters[FilterIndex];
  23.             ParameterSet = Parameters[FilterIndex];
  24.             Query = "SELECT * FROM " + Table + " WHERE ";
  25.             if ( string.IsNullOrEmpty( Filter ) )
  26.                 Query += "1;";
  27.             else
  28.                 Query += Filter + ";";
  29.             MySqlDataAdapter Adapter = new MySqlDataAdapter( new MySqlCommand( Query ) { CommandType = CommandType.Text } );
  30.             if ( ParameterSet != null )
  31.                 for ( int x = 0; x < ParameterSet.Length; x++ )
  32.                     Adapter.SelectCommand.Parameters.AddWithValue( "@param_val_" + x, ParameterSet[x] );
  33.             Adapter.TableMappings.Add( Table, Table );
  34.             this.Adapters[Tables.ToList( ).IndexOf( Table )] = Adapter;
  35.         }
  36.         if (Methods.IsOnline)
  37.             await this.ReadTables( );
  38.     }
  39.  
  40. //SQL.Adapters :
  41.     private MySqlDataAdapter[ ] Adapters;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement