【问题标题】:How to update data in hypertable如何更新超表中的数据
【发布时间】:2012-09-06 02:16:02
【问题描述】:

我已经编写了一些 C# 代码来将数据存储到超表数据库中。但是我不知道如何更新数据。 以下是我所做的:

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"

而我的写函数是:

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;
    }
}


所以我的更新只是用相同的键但不同的值再次写入。但是在更新后我读取了那个键和值,它应该显示新的键和值(键 =“1”和值 =“value111”)但它没有,它只显示旧的键和值(键 = “1”,值 = “值 1”)
我不知道为什么会这样。任何提示将不胜感激。谢谢。

【问题讨论】:

  • 我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
  • 这个问题你解决了吗?您使用的是哪个版本的超表?因为没有方法: mutator_set ,你必须使用 set_cell 或 set_cell_as_array

标签: c# hypertable


【解决方案1】:

您可以尝试将 mutator.Flush() 添加到最里面的 using 块中,尽管它应该在 mutator 超出范围时自动调用...

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-27
  • 1970-01-01
相关资源
最近更新 更多