public SimpleObjectSaver(ObjectInfo info, QueryComposer composer, DataProvider provider, IDbObjectHandler handler) { this.Info = info; this.Composer = composer; this.Provider = provider; this.Handler = handler; }
public void Test2() { StaticRecorder.ConnectionOpendTimes = 0; var ctx = new DataProvider("SQLite"); DbEntry.UsingTransaction(() => ctx.ExecuteNonQuery("select * from test")); Assert.AreEqual(1, StaticRecorder.ConnectionOpendTimes); }
public void Test4() { StaticRecorder.ConnectionOpendTimes = 0; var ctx = new DataProvider("SQLite"); ctx.ExecuteNonQuery("select * from test"); ctx.ExecuteNonQuery("select * from test"); Assert.AreEqual(2, StaticRecorder.ConnectionOpendTimes); }
public void TestGetTheRightCopier2() { var dc = new DataProvider("SqlServerMock"); DbEntry.NewTransaction(delegate { IDbBulkCopy c = dc.GetDbBulkCopy(false); // exception Assert.IsNotNull(c); Assert.IsTrue(c is SqlServerBulkCopy); }); }
public IDbConnection GetConnection(DataProvider provider) { if (_state == ConnectionContextState.NoConnection) { CheckContextAreSame(provider); _connection = provider.Driver.GetDbConnection(); _connection.Open(); provider.Dialect.InitConnection(provider.Driver, _connection); _state = ConnectionContextState.ConnectionOpened; } return _connection; }
public static SimpleDeleter CreateDeleter(ObjectInfo info, QueryComposer composer, DataProvider provider, IDbObjectHandler handler) { if(info.HasRelation) { return new RelationModelDeleter(info, composer, provider, handler); } if(info.HasOnePrimaryKey && info.KeyMembers[0].UnsavedValue != null) { return new KeyModelDeleter(info, composer, provider, handler); } return new SimpleDeleter(info, composer, provider, handler); }
private void CheckContextAreSame(DataProvider provider) { if(_contextName == null) { _contextName = provider.Driver.Name; } else { if(_contextName != provider.Driver.Name) { throw new DataException("The transaction should use [{0}] but was [{1}]", _contextName, provider.Driver.Name); } } }
public static AutoSchemeFixer CreateInstance(DataProvider provider, ObjectInfo info) { switch(provider.Driver.AutoScheme) { case AutoScheme.None: return new AutoSchemeFixer(); case AutoScheme.CreateTable: return new AutoSchemeFixerCreateTable(provider, info); case AutoScheme.AddColumns: return new AutoSchemeFixerAddColumns(provider, info); case AutoScheme.RemoveColumns: return new AutoSchemeFixerRemoveColumns(provider, info); default: throw new DataException("Application Error"); } }
private IDbTransaction GetTransaction(DataProvider provider) { if (_state == ConnectionContextState.ConnectionOpened || _state == ConnectionContextState.TransactionEnded) { switch (_transactionState) { case ConnectionContextTransactionState.UnspecifiedTransaction: _transaction = GetConnection(provider).BeginTransaction(); _state = ConnectionContextState.TransactionStarted; break; case ConnectionContextTransactionState.SpecifiedTransaciton: _transaction = GetConnection(provider).BeginTransaction(_isolationLevel); _state = ConnectionContextState.TransactionStarted; break; } } return _transaction; }
public void Test1() { SqlRecorder.Start(); var de = new DataProvider("SQLite"); var sql = new SqlStatement("test log") {NeedLog = false}; de.ExecuteNonQuery(sql); Assert.AreEqual(0, SqlRecorder.List.Count); sql.NeedLog = true; de.ExecuteNonQuery(sql); Assert.AreEqual(1, SqlRecorder.List.Count); Assert.AreEqual("test log<Text><30>()", SqlRecorder.LastMessage); SqlRecorder.Stop(); }
public static SimpleObjectSaver CreateSaver(ObjectInfo info, QueryComposer composer, DataProvider provider, IDbObjectHandler handler) { if (info.HasSystemKey && info.KeyMembers[0].UnsavedValue == null) { throw new DataException("System key must have UnsavedValue."); } if (info.HandleType.IsSubclassOf(typeof(DbObjectSmartUpdate))) { if (info.HasRelation) { return new RelationModelSaver(info, composer, provider, handler); } return new DbModelSaver(info, composer, provider, handler); } if(info.HasSystemKey) { return new DbObjectSaver(info, composer, provider, handler); } return new SimpleObjectSaver(info, composer, provider, handler); }
public DbTimeProvider(DataProvider context) { _context = context; }
public void TestGenerateData() { var sql = ResourceHelper.ReadToEnd(typeof(InitTestDatabase), "TestTable.sql"); var init = new DataProvider("Init"); init.ExecuteNonQuery(sql); }
private void button4_Click(object sender, System.EventArgs e) { var dataBase1 = new DataProvider("1"); var sql = new SqlStatement("SELECT TOP 50 * FROM [Sheet1$]"); dataGrid1.DataSource = dataBase1.ExecuteDataset(sql).Tables[0]; }
public RelationModelSaver(ObjectInfo info, QueryComposer composer, DataProvider provider, IDbObjectHandler handler) : base(info, composer, provider, handler) { }
public KeyModelDeleter(ObjectInfo info, QueryComposer composer, DataProvider provider, IDbObjectHandler handler) : base(info, composer, provider, handler) { }
public override void ExecuteDropSequence(DataProvider dp, string tableName) { string sql = string.Format("DROP SEQUENCE {0}_SEQ;\n", tableName.ToUpper()); dp.ExecuteNonQuery(sql); }
public AutoSchemeFixerCreateTable(DataProvider provider, ObjectInfo info) { this.Provider = provider; _createTables = GetCreateTables(info); }
internal CachedModelOperator(ObjectInfo info, QueryComposer composer, DataProvider provider, IDbObjectHandler handler) : base(info, composer, provider, handler) { }
public CommonBulkCopy(DataProvider provider, bool identityInsert) { this._provider = provider; this._identityInsert = identityInsert; }
public AutoSchemeFixerRemoveColumns(DataProvider provider, ObjectInfo info) : base(provider, info) { }
public IDbCommand GetDbCommand(SqlStatement sql, DataProvider provider) { CheckContextAreSame(provider); var e = provider.Driver.GetDbCommand(sql, GetConnection(provider)); if (GetTransaction(provider) != null) { e.Transaction = _transaction; } return e; }
public override void ExecuteDropSequence(DataProvider dp, string tableName) { string sql = string.Format("DROP GENERATOR GEN_{0}_ID;\n", tableName.ToUpper()); dp.ExecuteNonQuery(sql); }
public virtual object ExecuteInsert(InsertStatementBuilder sb, ObjectInfo info, DataProvider provider) { if (info.HasOnePrimaryKey && info.KeyMembers[0].MemberType == typeof(Guid)) { if(info.KeyMembers[0].Is.DbGenerateGuid) { Guid key = Util.NewGuid(); sb.Values[0].Value = key; } SqlStatement sql = sb.ToSqlStatement(provider.Dialect, null, info.AllowSqlLog); provider.ExecuteNonQuery(sql); return sb.Values[0].Value; } return ExecuteInsertIntKey(sb, info, provider); }
public virtual void ExecuteDropSequence(DataProvider dp, string tableName) { }
protected virtual object ExecuteInsertIntKey(InsertStatementBuilder sb, ObjectInfo info, DataProvider provider) { SqlStatement sql = sb.ToSqlStatement(provider.Dialect, null, info.AllowSqlLog); sql.SqlCommandText = AddIdentitySelectToInsert(sql.SqlCommandText); return provider.ExecuteScalar(sql); }