Exemplo n.º 1
0
        /// <summary>
        /// Run EA SQL Query with Exception handling
        /// <para/>return null if error, it also displays the error message in MessageBox
        /// <para/>return "" if nothing found
        /// <para/>return xml string if ok
        /// </summary>
        /// <returns>string</returns>
        public bool SqlExecuteWithException(string sql)
        {
            // delete an existing error file
            SqlError.DeleteEaSqlError();
            try
            {
                // run the query (select * .. from
                sql = FormatSql(sql);
                // store final/last query which is executed
                SqlError.WriteHoToolsLastSql(sql);

                Repository.Execute(sql);
                if (!SqlError.ExistsEaSqlErrorFile())
                {
                    return(true);
                }
                else
                {
                    MessageBox.Show(SqlError.ReadEaSqlError(), @"Error SQL (CTRL+C to copy it!!)");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($@"SQL:{Environment.NewLine}{sql}{Environment.NewLine}{ex.Message}", @"Error SQL");
                return(false);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Run EA SQL Query with Exception handling. It deletes the error file and reads it back to detect errors.
 /// <para/>return null if error, it also displays the error message in MessageBox
 /// <para/>return "" if nothing found
 /// <para/>return xml string if ok
 /// </summary>
 /// <param name="query"></param>
 /// <returns>string</returns>
 public string SqlQueryWithException(string query)
 {
     // delete an existing error file
     SqlError.DeleteEaSqlError();
     try
     {
         // is query or a changing SQL?
         //if (Regex.IsMatch(query, "^\s*select ", RegexOptions.IgnoreCase | RegexOptions.Multiline)) {
         // run the query (select * .. from
         string xml = SqlQueryNative(query);
         if (!SqlError.ExistsEaSqlErrorFile())
         {
             return(xml);
         }
         else
         {
             MessageBox.Show(SqlError.ReadEaSqlError(), @"Error SQL (CTRL+C to copy it!!)");
             return(null);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show($@"SQL:{Environment.NewLine}{query}{Environment.NewLine}{ex.Message}", @"Error SQL");
         return(null);
     }
 }