private ExeFileTarget(string raw) : base(raw) { if (Name.ToLower().EndsWith("exe")) { Type = ExeType.Application; } else { Type = ExeType.Script; } }
//------------------------------------------------------------------- public void SetExeType(MemVisualizer.ExeType p) { mExe = p; }
public bool command(string conn_str, string sql, ExeType exe_type,bool deal =false) { //if (conn_str.Length > 0) this.conn_str = conn_str;//rm save this.is_exec = false; if (this.debug) this.post_text(conn_str); this.post_text(sql); //New if (!this.is_conn) { try { this.status = MysqlStatus.NewConn; this.conn = new MySqlConnection(this.conn_str); this.is_conn = false; } catch (Exception ex) { this.status = MysqlStatus.NewConnExecption; if (this.debug) Console.WriteLine(ex.ToString()); else this.ex_s = ex.ToString(); this.post_text(ex.ToString()); return false; } } // Open if (!this.is_conn) { try { if(this.debug) Console.WriteLine("Connecting to MySQL..."); this.status = MysqlStatus.OpenConn; this.conn.Open(); this.is_conn = true; } catch (Exception ex) { this.status = MysqlStatus.OpenConnExecption; if (this.debug) Console.WriteLine(ex.ToString()); else this.ex_s = ex.ToString(); this.post_text(ex.ToString()); return false; } } //check is_conn if (!this.is_conn) return false; //new cmd MySqlCommand cmd; try { this.status = MysqlStatus.NewCmd; cmd = new MySqlCommand(sql, this.conn); } catch (Exception ex) { this.status = MysqlStatus.NewCmdExecption; if (this.debug) Console.WriteLine(ex.ToString()); else this.ex_s = ex.ToString(); this.post_text(ex.ToString()); return false; } //Select if (exe_type == ExeType.Select) { try { this.status = MysqlStatus.Select; this.rdr = cmd.ExecuteReader(); if (deal) deal_rdr(); } catch (Exception ex) { this.status = MysqlStatus.SelectExecption; if (this.debug) Console.WriteLine(ex.ToString()); else this.ex_s = ex.ToString(); this.post_text(ex.ToString()); return false; } } //insert if (exe_type == ExeType.Insert) { try { this.status = MysqlStatus.Insert; cmd.ExecuteNonQuery(); } catch (Exception ex) { this.status = MysqlStatus.InsertExecption; if(this.debug) Console.WriteLine(ex.ToString()); else this.ex_s = ex.ToString(); this.post_text(ex.ToString()); return false; } } //Script if (exe_type == ExeType.Script) { this.script_error_count = 0; try { MySqlScript script = new MySqlScript(this.conn, sql); script.Error += new MySqlScriptErrorEventHandler(this.script_Error); script.ScriptCompleted += new EventHandler(this.script_ScriptCompleted); script.StatementExecuted += new MySqlStatementExecutedEventHandler(this.script_StatementExecuted); int count = script.Execute(); if (debug) Console.WriteLine("Executed " + count + " statement(s)."); if (debug) Console.WriteLine("Delimiter: " + script.Delimiter); } catch (Exception ex) { this.script_error_count++; this.status = MysqlStatus.ScriptExecption; if(debug) Console.WriteLine(ex.ToString()); else this.ex_s = ex.ToString(); this.post_text(ex.ToString()); return false; } if (this.script_error_count > 0) return false; } this.is_exec = true; return true; }
public bool transaction(string conn_str, string sql, ExeType exe_type,bool deal=false) { string s_task="begin ; "+sql+" commit ; "; return this.command(conn_str,s_task, exe_type,deal); }
public bool command(string sql, ExeType exe_type, bool deal = false) { return this.command(this.conn_str,sql, exe_type, deal); }