3

I have written some C# code to store data into hypertable database. However I don't know how to update the data. Below is what I have done:

Hypertable b = new Hypertable();
b.Write("1", "value1");//this line is for writing to database
b.Write("1", "value111");//this line is for updating the value whose key = "1"

and my Write function is:

public override bool Write(string key, string value)
{
    try
    {
        using (IContext context = Context.Create(connectionString))
        using (IClient client = context.CreateClient())
        {
            using (INamespace ns = client.OpenNamespace("Test", OpenDispositions.OpenAlways | OpenDispositions.CreateIntermediate))
            {
                using (ITable table = ns.OpenTable(tableName))
                {
                    using (ITableMutator mutator = table.CreateMutator())
                    {
                        Key _key = new Key { Row = key, ColumnFamily = "vvalue" };
                        mutator.Set(_key, Encoding.UTF8.GetBytes(value));
                    }
                }
            }
        }
        return true;
    }
    catch (Exception e)
    {
        Console.WriteLine("Hypertable--Write--{0}", e.Message);
        return false;
    }
}


So my update is simply write again with the same key but different value. However after updating I do a read of that key and value, it is supposed to show the new key and value (key = "1" and value = "value111") but it doesn't, it just shows the old key and value (key = "1" and value = "value1")
I don't know why this happens. Any tips will be appreciated. Thanks.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
user1642888
  • 127
  • 1
  • 1
  • 8
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Dec 08 '12 at 01:48
  • did you solved this problem ? which version of hypertable you are using ? because there is no method: mutator_set , you have to use set_cell or set_cell_as_array – fmt.Println.MKO Jan 24 '13 at 10:04

1 Answers1

0

You can try adding mutator.Flush() to your innermost using block, although it should be called automatically when mutator goes out of scope...

Ria
  • 10,237
  • 3
  • 33
  • 60
Arne Joris
  • 86
  • 4
  • My posts here will hopefully answer your question in depth. http://stackoverflow.com/questions/17955954/hypertable-loading-data-using-mutators-vs-load-data-infile. I have tried loading using mutator and also direct load using flat file. Good luck. – NullException Jul 30 '13 at 19:44