Shadowrun: Awakened 29 September 2011 - Build 871
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
RoutineAnalyzer::RoutineReader Class Reference

Connects to the MySQL database and reads out the meta-data for all routines NOTE: As written, this will assume all routines are procedures. More...

List of all members.

Public Member Functions

DataTable GetProcedureDefinitionAsDataTable ()
List< string > GetProcedureDefintions ()
 Returns a list of strings, each string being the procedure name and paramters for distinct routines within the current builder's database.
 RoutineReader (MySqlConnectionStringBuilder builder)
 Constructor Takes a builder to describe the database we will be using.

Private Member Functions

DataTable GetAllProcNames (MySqlConnection connection)
 Gets a list for all procedures in the current database.
string GetProcDefintion (MySqlConnection connection, string procName)
 Gets the definition text for a single procedure name by procName.

Static Private Member Functions

static DataTable CreateTableFromCommand (MySqlCommand command)
 Converts the result of a command into a datatable.
static string GetShowAllProcsQuery (string schema)
 Returns the SQL code for finding a list of all procedures.
static string GetShowProcQuery (string schema, string procName)
 Gets a list of.

Private Attributes

MySqlConnectionStringBuilder _builder
const string procedureMarker = "PROCEDURE"
const string showProcQuery = "SHOW CREATE PROCEDURE {0}.{1}"
const string showProcs = "select specific_name from INFORMATION_SCHEMA.routines where routine_schema = '{0}' and routine_type = 'PROCEDURE'"

Detailed Description

Definition at line 17 of file RoutineReader.cs.


Constructor & Destructor Documentation

RoutineAnalyzer::RoutineReader::RoutineReader ( MySqlConnectionStringBuilder  builder) [inline]
Parameters:
builder

Definition at line 42 of file RoutineReader.cs.

References _builder.

        {
            _builder = builder;
        }

Member Function Documentation

static DataTable RoutineAnalyzer::RoutineReader::CreateTableFromCommand ( MySqlCommand  command) [inline, static, private]
Parameters:
command
Returns:

Definition at line 73 of file RoutineReader.cs.

Referenced by GetAllProcNames(), and GetProcDefintion().

        {
            using (MySqlDataReader reader = command.ExecuteReader())
            {
                //use a datatable to find the third column of the first row, that is the definition
                DataTable table = new DataTable();
                table.Load(reader);
                return table;
            }
        }
DataTable RoutineAnalyzer::RoutineReader::GetAllProcNames ( MySqlConnection  connection) [inline, private]
Parameters:
connection
Returns:

Definition at line 89 of file RoutineReader.cs.

References _builder, CreateTableFromCommand(), and GetShowAllProcsQuery().

Referenced by GetProcedureDefinitionAsDataTable(), and GetProcedureDefintions().

        {
            using (MySqlCommand command = connection.CreateCommand())
            {
                command.CommandText = GetShowAllProcsQuery(_builder.Database);
                return CreateTableFromCommand(command);
            }
        }
string RoutineAnalyzer::RoutineReader::GetProcDefintion ( MySqlConnection  connection,
string  procName 
) [inline, private]
Parameters:
connection
procName
Returns:

Definition at line 104 of file RoutineReader.cs.

References _builder, CreateTableFromCommand(), and GetShowProcQuery().

Referenced by GetProcedureDefintions().

        {
            //create a command and query the db for the proc definition
            using (MySqlCommand command = connection.CreateCommand())
            {
                command.CommandText = GetShowProcQuery(_builder.Database, procName);
                //use a datatable to find the third column of the first row, that is the definition
                DataTable table = CreateTableFromCommand(command);
                return table.Rows[0][2].ToString();
            }
        }
DataTable RoutineAnalyzer::RoutineReader::GetProcedureDefinitionAsDataTable ( ) [inline]

Definition at line 148 of file RoutineReader.cs.

References _builder, and GetAllProcNames().

Referenced by RoutineAnalyzer::AnalyzerForm::OnScanDatabaseClick().

        {
            using (MySqlConnection connection = new MySqlConnection(_builder.ToString()))
            {
                connection.Open();
                return GetAllProcNames(connection);
            }
        }
List<string> RoutineAnalyzer::RoutineReader::GetProcedureDefintions ( ) [inline]
Returns:

Definition at line 121 of file RoutineReader.cs.

References _builder, GetAllProcNames(), GetProcDefintion(), and procedureMarker.

Referenced by RoutineAnalyzer::AnalyzerForm::GenerateCode().

        {
            using (MySqlConnection connection = new MySqlConnection(_builder.ToString()))
            {
                connection.Open();
                DataTable table = GetAllProcNames(connection);
                List<string> procedures = new List<string>();
                foreach (DataRow row in table.Rows)
                {
                    //retrieve the whole definition
                    string definition = GetProcDefintion(connection, row[0].ToString());
                    //pull out just the first line
                    int firstNewline = definition.IndexOf("\n");
                    string paramters = definition.Substring(0, firstNewline + 1);
                    //remove all of the special single quotes
                    paramters = paramters.Replace("`", "");
                    //remove from the beginning to the end of the marker, plus one for the extra space
                    int startOfProcedure = paramters.IndexOf(procedureMarker);
                    paramters = paramters.Remove(0, startOfProcedure + procedureMarker.Length +1);
                    //add this to the list of procedures
                    procedures.Add(paramters);
                }

                return procedures;
            }
        }
static string RoutineAnalyzer::RoutineReader::GetShowAllProcsQuery ( string  schema) [inline, static, private]
Parameters:
schema
Returns:

Definition at line 63 of file RoutineReader.cs.

References showProcs.

Referenced by GetAllProcNames().

        {
            return string.Format(showProcs, schema);
        }
static string RoutineAnalyzer::RoutineReader::GetShowProcQuery ( string  schema,
string  procName 
) [inline, static, private]
Parameters:
schema
procName
Returns:

Definition at line 53 of file RoutineReader.cs.

References showProcQuery.

Referenced by GetProcDefintion().

        {
            return string.Format(showProcQuery, schema, procName);
        }

Member Data Documentation

MySqlConnectionStringBuilder RoutineAnalyzer::RoutineReader::_builder [private]
const string RoutineAnalyzer::RoutineReader::procedureMarker = "PROCEDURE" [private]

Definition at line 31 of file RoutineReader.cs.

Referenced by GetProcedureDefintions().

const string RoutineAnalyzer::RoutineReader::showProcQuery = "SHOW CREATE PROCEDURE {0}.{1}" [private]

Definition at line 29 of file RoutineReader.cs.

Referenced by GetShowProcQuery().

const string RoutineAnalyzer::RoutineReader::showProcs = "select specific_name from INFORMATION_SCHEMA.routines where routine_schema = '{0}' and routine_type = 'PROCEDURE'" [private]

Definition at line 30 of file RoutineReader.cs.

Referenced by GetShowAllProcsQuery().


The documentation for this class was generated from the following file:

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net