public static IDataReader RunSqlCommandsReader(this DbConnection conn, ISqlDialect dialect, string sql) { List <string> items = new List <string>(); foreach (string item in QueryTools.GoSplit(sql)) { items.Add(item); } for (int i = 0; i < items.Count; i++) { if (i < items.Count - 1) { using (DbCommand c = conn.CreateCommand()) { c.Connection = conn; c.CommandText = items[i]; Logging.Debug("Executing SQL:" + items[i]); c.ExecuteNonQueryEx(dialect); } } else { return(RunOneSqlCommandReader(conn, dialect, items[i])); } } throw new InternalError("DAE-00160 No return reader"); }
public static void ExecuteNonQueries(this DbConnection conn, string sql, ISqlDialect dialect) { foreach (string cmd in QueryTools.GoSplit(sql)) { ExecuteNonQuery(conn, cmd, dialect); } }
//public static List<string> LoadColumnNames(this DbConnection conn, NameWithSchema table) //{ // Logging.Debug("Getting column list, tablename={0}", table); // DataTable data = conn.GetSchema("Columns", new string[] { null, table.Schema, table.Name }).SelectNewTable("1=1", "ORDINAL_POSITION ASC"); // List<string> lst = new List<string>(); // foreach (DataRow row in data.Rows) lst.Add(row["COLUMN_NAME"].ToString()); // return lst; //} //public static List<string> LoadSchemaNames(this DbConnection conn, DbProviderFactory factory) //{ // List<string> res = new List<string>(); // using (DbCommand cmd = factory.CreateCommand()) // { // cmd.Connection = conn; // cmd.CommandText = "SELECT * FROM INFORMATION_SCHEMA.SCHEMATA"; // using (DbDataReader reader = cmd.ExecuteReader()) // { // while (reader.Read()) // { // res.Add(reader["SCHEMA_NAME"].ToString()); // } // } // } // return res; //} public static void ExecuteNonQueries(this DbConnection conn, string sql, ISqlDialect dialect, DbTransaction tran, int?timeout) { foreach (string cmd in QueryTools.GoSplit(sql)) { ExecuteNonQuery(conn, cmd, dialect, tran, timeout); } }
private void RunScript(ISqlDumper dmp) { using (var fr = GetInputStream()) { foreach (string sql in QueryTools.GoSplit(fr)) { dmp.WriteRaw(sql); dmp.EndCommand(); } } }
public static void RunSqlCommands(this DbConnection conn, ISqlDialect dialect, string sql) { DbTransaction trans = null; if (dialect.DialectCaps.NestedTransactions) { try { trans = conn.BeginTransaction(); } catch (Exception) { trans = null; } } try { foreach (string sql_item in QueryTools.GoSplit(sql)) { using (DbCommand c = conn.CreateCommand()) { if (trans != null) { c.Transaction = trans; } c.Connection = conn; c.CommandText = sql_item; Logging.Debug("Executing SQL:" + sql_item); c.ExecuteNonQueryEx(dialect); } } } catch { if (trans != null) { trans.Rollback(); } throw; } if (trans != null) { trans.Commit(); } }
public virtual void Run(TextReader reader) { if (UseSpecificSplitter) { var splitter = m_dialect.CreateQuerySplitter(); foreach (var item in splitter.Run(reader)) { ShowProgress(); try { ExecuteDumpQuery(item.Data); OkInc(); } catch (Exception err) { ReportFail(item.Data, err); } } } else { foreach (string sql in QueryTools.GoSplit(reader)) { ShowProgress(); try { ExecuteDumpQuery(sql); OkInc(); } catch (Exception err) { ReportFail(sql, err); } } } ReportFinish(); }