Here's an example of updating a row in the database. First we retrieve it into a DAO, then change the value for City, save it and later restore the value back to the original.

        [Test]
        public void UpdateSingleRow()
        {
            //Get city of Customer with id = ALFKI
            var f = new Filter();
            f.Add("Customerid", "ALFKI");
            var customers = D2Bk.Fetch(f, new Customers());
            Assert.AreEqual(1, customers.Count);
            
            var customer = customers[0] as Customers;
            Assert.IsNotNull(customer);
            
            //Save current city to restore later
            string saveCity = customer.City;
            customer.City = "Saint Paul";
            //Save city
            D2Bk.SaveOne(customer);
            
            //Retrieve customer once more
            customers = D2Bk.Fetch(f, new Customers());
            Assert.AreEqual(1, customers.Count);
            customer = customers[0] as Customers;
            if (customer != null)
            {
                Assert.AreEqual("Saint Paul", customer.City);
                customer.City = saveCity;
                D2Bk.SaveOne(customer);
            }
        }


Data Broker generates the Update statement as follows:

UPDATE [Customers] SET City =  @City  WHERE (Customerid = @FLD1 )

As you can see, there is no string concatenation - Data Broker always uses parameterized queries.

Last edited Mar 2, 2009 at 11:42 PM by dbroker, version 5

Comments

No comments yet.