Exemple #1
0
        public static Boolean ExecuteBatch(string sql, bool showError = false)
        {
            SqlStatments st = new SqlStatments();

            string[] sqls = SqlStatments.ParseSQLtoSubSQLs(sql);
            int      i, size = sqls != null ? sqls.Length : 0;
            string   temp;
            bool     success = true;
            bool     executeWithParameters = false;

            for (i = 0; i < size; i++)
            {
                temp = sqls[i].Trim();
                if (temp.Length > 0)
                {
                    // do not execute comments
                    if (temp.StartsWith("--"))
                    {
                        log("Not running: " + temp);
                        continue;
                    }
                    if (temp.ToLower().StartsWith("exec"))
                    {
                        if (temp.IndexOf(NAME_VALUE_PARAMETER) >= 0 || executeWithParameters)
                        {
                            success &= ExecuteStoredProcedureWithParameters(temp);
                            executeWithParameters = true;
                        }
                        else
                        {
                            success &= ExecuteStoreProcedure(temp, showError);
                        }
                    }
                    else
                    {
                        success &= ExecuteUpdateSQL(temp, showError);
                    }
                }
            }

            return(success);
        }
Exemple #2
0
        public static bool IsValidSQL(string sql, out string message)
        {
            DataSet ds = new DataSet();

            message = string.Empty;

            if (m_adapter == null)
            {
                return(false);
            }

            string[] sqls = SqlStatments.ParseSQLtoSubSQLs(sql);

            foreach (string statement in sqls)
            {
                if (!string.IsNullOrEmpty(statement))
                {
                    sql = "EXPLAIN PLAN  FOR " + statement;

                    DbServices.m_adapter.SelectCommand             = DbServices.m_command;
                    DbServices.m_adapter.SelectCommand.CommandText = sql;


                    try
                    {
                        DbServices.m_adapter.Fill(ds, "table");
                    }
                    catch (SqlException ex)
                    {
                        message = ex.Message;

                        return(false);
                    }
                }
            }
            return(true);
        }