cassandra c# datastax 客户端插入 blob
cassandra c# datastax client insert blob
嗨,我想知道是否有更优雅的方式来插入 blob 而不是将字节数组转换为字符串,例如:
string strblob = "0x00" + BitConverter.ToString(stream2.GetBuffer()).Replace("-", "");
ISession session = cluster.Connect("abc");
session.Execute(string.Format("insert into events(blob) values ({0})", blobStr));
有一个更优雅、更有效的解决方案,那就是使用绑定语句。
byte[] blob = stream2.GetBuffer();
ISession session = cluster.Connect("abc");
PreparedStatement preparedStatement = session.Prepare("INSERT INTO events(blob) VALUES (?)");
BoundStatement boundStatement = preparedStatement.Bind(blob);
session.Execute(boundStatement);
PreparedStatement 背后的想法是对字符串查询进行一次解析,然后根据需要使用不同的值重复使用它。因此,请跟踪您准备好的陈述。
嗨,我想知道是否有更优雅的方式来插入 blob 而不是将字节数组转换为字符串,例如:
string strblob = "0x00" + BitConverter.ToString(stream2.GetBuffer()).Replace("-", "");
ISession session = cluster.Connect("abc");
session.Execute(string.Format("insert into events(blob) values ({0})", blobStr));
有一个更优雅、更有效的解决方案,那就是使用绑定语句。
byte[] blob = stream2.GetBuffer();
ISession session = cluster.Connect("abc");
PreparedStatement preparedStatement = session.Prepare("INSERT INTO events(blob) VALUES (?)");
BoundStatement boundStatement = preparedStatement.Bind(blob);
session.Execute(boundStatement);
PreparedStatement 背后的想法是对字符串查询进行一次解析,然后根据需要使用不同的值重复使用它。因此,请跟踪您准备好的陈述。