示例#1
0
 public SimpleObjectSaver(ObjectInfo info, QueryComposer composer, DataProvider provider, IDbObjectHandler handler)
 {
     this.Info = info;
     this.Composer = composer;
     this.Provider = provider;
     this.Handler = handler;
 }
示例#2
0
 public void Test2()
 {
     StaticRecorder.ConnectionOpendTimes = 0;
     var ctx = new DataProvider("SQLite");
     DbEntry.UsingTransaction(() => ctx.ExecuteNonQuery("select * from test"));
     Assert.AreEqual(1, StaticRecorder.ConnectionOpendTimes);
 }
示例#3
0
 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);
 }
示例#4
0
 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);
     });
 }
示例#5
0
 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;
 }
示例#6
0
 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);
 }
示例#7
0
 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);
         }
     }
 }
示例#8
0
 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");
     }
 }
示例#9
0
 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;
 }
示例#10
0
        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();
        }
示例#11
0
        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);
        }
示例#12
0
 public DbTimeProvider(DataProvider context)
 {
     _context = context;
 }
示例#13
0
 public void TestGenerateData()
 {
     var sql = ResourceHelper.ReadToEnd(typeof(InitTestDatabase), "TestTable.sql");
     var init = new DataProvider("Init");
     init.ExecuteNonQuery(sql);
 }
示例#14
0
 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];
 }
示例#15
0
 public RelationModelSaver(ObjectInfo info, QueryComposer composer, DataProvider provider, IDbObjectHandler handler)
     : base(info, composer, provider, handler)
 {
 }
示例#16
0
 public KeyModelDeleter(ObjectInfo info, QueryComposer composer, DataProvider provider, IDbObjectHandler handler)
     : base(info, composer, provider, handler)
 {
 }
示例#17
0
 public override void ExecuteDropSequence(DataProvider dp, string tableName)
 {
     string sql = string.Format("DROP SEQUENCE {0}_SEQ;\n", tableName.ToUpper());
     dp.ExecuteNonQuery(sql);
 }
示例#18
0
 public AutoSchemeFixerCreateTable(DataProvider provider, ObjectInfo info)
 {
     this.Provider = provider;
     _createTables = GetCreateTables(info);
 }
示例#19
0
 internal CachedModelOperator(ObjectInfo info, QueryComposer composer, DataProvider provider, IDbObjectHandler handler)
     : base(info, composer, provider, handler)
 {
 }
示例#20
0
 public CommonBulkCopy(DataProvider provider, bool identityInsert)
 {
     this._provider = provider;
     this._identityInsert = identityInsert;
 }
示例#21
0
 public AutoSchemeFixerRemoveColumns(DataProvider provider, ObjectInfo info) : base(provider, info)
 {
 }
示例#22
0
 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;
 }
示例#23
0
 public override void ExecuteDropSequence(DataProvider dp, string tableName)
 {
     string sql = string.Format("DROP GENERATOR GEN_{0}_ID;\n", tableName.ToUpper());
     dp.ExecuteNonQuery(sql);
 }
示例#24
0
 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);
 }
示例#25
0
 public virtual void ExecuteDropSequence(DataProvider dp, string tableName)
 {
 }
示例#26
0
 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);
 }