Exemplo n.º 1
0
        public void CheckUniAdapterTest()
        {
            ProviderSetting.CurrentDBProvider = DbProviderType.OracleOdpNetManaged;
            UniDbConnection connect = new UniDbConnection("knvtest", "3");

            connect.Open();
            Assert.AreEqual(connect.State, ConnectionState.Open);

            UniDbAdapter a = new UniDbAdapter("select * from test_apstaff.temp_rep where per_num=:p_per_num", connect);

            a.TableMappings.Add("Table", "temp_rep");
            a.SelectCommand.Parameters.Add("p_per_num", UniDbType.String, "14534");
            DataSet ds = new DataSet();

            a.Fill(ds);
            a.Dispose();

            UniDbAdapter a1 = new UniDbAdapter("declare begin open :c for select * from test_apstaff.temp_rep where per_num=:p_per_num; end;", connect);

            a1.TableMappings.Add("Table", "temp_rep1");
            a1.SelectCommand.Parameters.Add("p_per_num", UniDbType.String, "14534");
            a1.SelectCommand.Parameters.Add("c", UniDbType.RefCursor);

            a1.Fill(ds);

            Assert.AreEqual(ds.Tables["temp_rep1"].Rows.Count, 2);

            UniDbAdapter a2 = new UniDbAdapter();
            UniDbCommand cm = new UniDbCommand("declare begin open :c for select * from test_apstaff.temp_rep where per_num=:p_per_num; end;", connect);

            a2.SelectCommand = cm;
            a2.TableMappings.Add("Table", "temp_rep2");
            a2.SelectCommand.Parameters.Add("p_per_num", UniDbType.String);
            a2.SelectCommand.Parameters.Add("c", UniDbType.RefCursor);
            a2.SelectCommand.SetParameters(new TestFilter());

            DataTable t = new DataTable();

            a2.Fill(ds);
            Assert.AreEqual(ds.Tables["temp_rep2"].Rows.Count, 2);
            Assert.IsTrue(ds.Tables["temp_rep2"].Rows.Cast <DataRow>().All(r => r["PER_NUM"].ToString() == "12714"));

            a2.SelectCommand.Parameters["p_per_num"].Value = "13772";
            a2.Fill(t);
            Assert.AreEqual(t.Rows.Count, 2);
            Assert.IsTrue(t.Rows.Cast <DataRow>().All(r => r["PER_NUM"].ToString() == "13772"));



            connect.Close();
            connect.Dispose();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Инициализирует адаптер сохранения данных
        /// </summary>
        public virtual void InitializeAdapter()
        {
            _dataAdapter = new UniDbAdapter();
            _dataAdapter.AcceptChangesDuringUpdate = false;

            if (!string.IsNullOrEmpty(DbTableName))
            {
                _dataAdapter.SelectCommand = UniCommandBuilder.GetSelectCommand(SchemaName, DbTableName);
            }
            UniSchemaColumn[] cols = SchemaTableManager.GetUpdatedColumns(TableName).ToArray();
            if (cols == null)
            {
                return;
            }

            _dataAdapter.AcceptChangesDuringUpdate = false;

            _dataAdapter.InsertCommand = UniCommandBuilder.GetInsertCommand(SchemaName, TableName, cols);
            _dataAdapter.UpdateCommand = UniCommandBuilder.GetUpdateCommand(SchemaName, TableName, cols);
            _dataAdapter.DeleteCommand = UniCommandBuilder.GetDeleteCommand(SchemaName, TableName, cols);
        }