views:

42

answers:

1

This test checks if only one SP ends with Insert, Load, or Save, then it's successful.

//Query to find SPs for a certain Table name
string check_SP =
    "SELECT ROUTINE_NAME, ROUTINE_DEFINITION " +
    "FROM INFORMATION_SCHEMA.ROUTINES " +
    "WHERE ROUTINE_DEFINITION LIKE '%CLNT_" + Table_Name + "%' " +
    "AND ROUTINE_TYPE='PROCEDURE'";

conn2.Open();
SqlCommand cmd_SP = new SqlCommand(check_SP, conn2);
list_SP = cmd_SP.ExecuteReader(); //Write 'check_SP' query results to 'list_SP'

while (list_SP.Read())
{
    if (list_SP[0].ToString().EndsWith("Insert")
        || list_SP[0].ToString().EndsWith("Load")
        || list_SP[0].ToString().EndsWith("Save"))
    {
        Console.WriteLine(list_SP[0]);
        test = true;
    }
    else
    {
        Console.WriteLine("Missing SP");
        test = false;
        break;
    }                    
}

What I wanna do is to break the while loop whenever there is no Stored Procedure that ends with Insert, or Load, or Save. (i.e. Each table should have at least these three SPs or else the test will fail)

+3  A: 

Leaving aside whether this is the right way to do this or not, you'll need to change your logic to check for the existence of each type of procedure individually:

bool insertExists = false;
bool loadExists = false;
bool saveExists = false;
while (list_SP.Read())
{
    if (list_SP[0].ToString().EndsWith("Insert"))
    {
        insertExists = true;
    }
    if (list_SP[0].ToString().EndsWith("Load"))
    {
        loadExists = true;
    }
    if (list_SP[0].ToString().EndsWith("Save"))
    {
        saveExists = true;
    }
    if (insertExists && loadExists && saveExists)
    {
        Console.WriteLine("All three exist");
        break;
    }
}

if (!insertExists)
{
    Console.WriteLine("Missing insert");
}
if (!loadExists)
{
    Console.WriteLine("Missing load");
}
if (!saveExists)
{
    Console.WriteLine("Missing save");
}
ChrisF
thx Chris I appreciate your help
Reda