public List <string> GetTableNames() { var ret = new List <string>(); DbStructInterface si = Dialect.GetDbStructInterface(); string userId = Dialect.GetUserId(Driver.ConnectionString); DbEntry.UsingConnection(() => { using (var c = (DbConnection)(Scope <ConnectionContext> .Current.GetConnection(this))) { var t = c.GetSchema(si.TablesTypeName, si.TablesParams); foreach (DataRow dr in t.Rows) { if (si.FiltrateDatabaseName) { if (!dr["TABLE_SCHEMA"].Equals(c.Database)) { continue; } } if (userId != null) { if (!dr["OWNER"].Equals(userId)) { continue; } } string s = dr[si.TableNameString].ToString(); ret.Add(s); } } }); return(ret); }
private void ExecuteDataset(SqlStatement sql, DataSet ds) { DbEntry.UsingConnection(delegate { using (IDbCommand e = GetDbCommand(sql)) { IDbDataAdapter d = InnerDriver.GetDbAdapter(e); if (Dialect.ExecuteEachLine) { int i = 0; foreach (string s in Split(e.CommandText)) { e.CommandText = s; ((DbDataAdapter)d).Fill(ds, 0, DataSettings.MaxRecords, "Table" + i); i++; } } else { d.Fill(ds); } PopulateOutParams(sql, e); } }); }
private int UpdateDataset(SqlStatement insertSql, SqlStatement updateSql, SqlStatement deleteSql, DataSet ds, int updateBatchSize, UpdateRowSource updateRowSource, bool throwException) { int ret = 0; DbEntry.UsingConnection(delegate { IDbDataAdapter d = InnerDriver.GetDbAdapter(); if (insertSql != null) { d.InsertCommand = GetDbCommandForUpdate(insertSql, updateRowSource); } if (updateSql != null) { d.UpdateCommand = GetDbCommandForUpdate(updateSql, updateRowSource); } if (deleteSql != null) { d.DeleteCommand = GetDbCommandForUpdate(deleteSql, updateRowSource); } var adapter = d as DbDataAdapter; if (adapter != null) { adapter.UpdateBatchSize = updateBatchSize; } else if (throwException) { throw new DataException("The DbDataAdapter doesn't support UpdateBatchSize feature."); } ret = d.Update(ds); ds.AcceptChanges(); }); return(ret); }
public void TestUpdateDatasetDirect2() { var dc = DbEntry.Provider; var sql = new SqlStatement("select [Id],[Name] from [People] where 1=0"); DataSet ds = dc.ExecuteDataset(sql); DbEntry.UsingConnection(delegate { var da = (DbDataAdapter)dc.Driver.GetDbAdapter(dc.GetDbCommand(sql)); var cb = dc.Driver.GetCommandBuilder(); cb.DataAdapter = da; DataTable dt = ds.Tables[0]; for (int i = 0; i < 10; i++) { object[] row = { 0, "jxf" }; dt.Rows.Add(row); } da.Update(ds); ds.AcceptChanges(); }); var list = DbEntry.From <SinglePerson>().Where(Condition.Empty).OrderBy("Id").Select(); Assert.AreEqual(13, list.Count); Assert.AreEqual("Tom", list[0].Name); Assert.AreEqual("jxf", list[3].Name); Assert.AreEqual("jxf", list[12].Name); }
public void TestUpdateDatasetDirect1() { var dc = DbEntry.Provider; DataSet ds = dc.ExecuteDataset(new SqlStatement("select [Name] from [People] where 1=0")); DbEntry.UsingConnection(delegate { var da = (DbDataAdapter)dc.Driver.GetDbAdapter(); var sql = new SqlStatement("insert into [People] ([Name]) VALUES (@name)"); var c = (DbCommand)dc.GetDbCommand(sql); c.Parameters.Add(dc.Driver.GetDbParameter(new DataParameter("name", "", "name"))); da.InsertCommand = c; DataTable dt = ds.Tables[0]; for (int i = 0; i < 10; i++) { object[] row = { "jxf" }; dt.Rows.Add(row); } da.Update(ds); ds.AcceptChanges(); }); var list = DbEntry.From <SinglePerson>().Where(Condition.Empty).OrderBy("Id").Select(); Assert.AreEqual(13, list.Count); Assert.AreEqual("Tom", list[0].Name); Assert.AreEqual("jxf", list[3].Name); Assert.AreEqual("jxf", list[12].Name); }
public void Test3() { DbEntry.UsingConnection( () => { DbEntry.Provider.ExecuteNonQuery("PRAGMA foreign_keys = ON;"); DbEntry.Provider.ExecuteNonQuery("INSERT INTO [PCs] ([Name],[Person_Id]) VALUES ('should be failed', 6);"); }); }
public void Test3() { Assert.Throws <SQLiteException>(() => { DbEntry.UsingConnection( () => { DbEntry.Provider.ExecuteNonQuery("PRAGMA foreign_keys = ON;"); DbEntry.Provider.ExecuteNonQuery("INSERT INTO [PCs] ([Name],[Person_Id]) VALUES ('should be failed', 6);"); }); }, SQLiteExceptionMessage); }
public int ExecuteNonQuery(SqlStatement sql) { int i = 0; DbEntry.UsingConnection(delegate { using (IDbCommand e = GetDbCommand(sql)) { ProcessLines(e, e1 => i += e1.ExecuteNonQuery()); PopulateOutParams(sql, e); } }); return(i); }
public void ExecuteDataReader(SqlStatement sql, CommandBehavior behavior, Action <IDataReader> callback) { DbEntry.UsingConnection(delegate { using (IDbCommand e = GetDbCommand(sql)) { ProcessLines(e, e1 => { using (IDataReader r = e1.ExecuteReader(behavior)) { PopulateOutParams(sql, e1); callback(r); } }); } }); }
public void Test1() { DbEntry.UsingConnection( () => { new CtxUser { Name = "test" }.Save(); DbEntry.NewTransaction(() => new CtxSvcUser { Name = "aaa" }.Save()); }); }
// for oracle internal void ExecuteDataReader(SqlStatement sql, Type returnType, Action <IDataReader> callback) { DbEntry.UsingConnection(delegate { using (IDbCommand e = GetDbCommand(sql)) { ProcessLines(e, e1 => { using (IDataReader r = e1.ExecuteReader(CommandBehavior.Default)) { PopulateOutParams(sql, e1); using (IDataReader dr = Dialect.GetDataReader(r, returnType)) { callback(dr); } } }); } }); }
public object ExecuteScalar(SqlStatement sql) { object obj = null; DbEntry.UsingConnection(delegate { using (IDbCommand e = GetDbCommand(sql)) { if (Dialect.ExecuteEachLine) { ExecuteBeforeLines(e); } obj = e.ExecuteScalar(); PopulateOutParams(sql, e); } }); return(obj); }
public void ExecuteDataReader(SqlStatement sql, CommandBehavior behavior, Action <IDataReader> callback) { DbEntry.UsingConnection(delegate { using (IDbCommand e = GetDbCommand(sql)) { if (Dialect.ExecuteEachLine) { ExecuteBeforeLines(e); } using (IDataReader r = e.ExecuteReader(behavior)) { PopulateOutParams(sql, e); callback(r); } } }); }
public int ExecuteNonQuery(SqlStatement sql) { int i = 0; DbEntry.UsingConnection(delegate { using (IDbCommand e = GetDbCommand(sql)) { if (Dialect.ExecuteEachLine) { i = ExecuteBeforeLines(e); } i += e.ExecuteNonQuery(); PopulateOutParams(sql, e); } }); return(i); }
public int UpdateDataset(SqlStatement selectSql, DataSet ds, int updateBatchSize, UpdateRowSource updateRowSource) { int ret = 0; DbEntry.UsingConnection( () => { var c = GetDbCommand(selectSql); c.UpdatedRowSource = updateRowSource; var d = (DbDataAdapter)InnerDriver.GetDbAdapter(c); var cb = InnerDriver.GetCommandBuilder(); cb.QuotePrefix = Dialect.OpenQuote.ToString(); cb.QuoteSuffix = Dialect.CloseQuote.ToString(); cb.DataAdapter = d; d.UpdateBatchSize = updateBatchSize; ret = d.Update(ds); ds.AcceptChanges(); }); return(ret); }