阅读文档后,我仍然没有弄清楚如何将数据从内存(变量)正确写入数据集。例如,对于构造
CREATE TRUNCATE CHUNKED DATASET dsetint AS INT(UNLIMITED), "INSERT INTO dsetint (-1) VALUES (" << val << ")"
,这里没有问题,变量被替换并且记录消失。
例如
"CREATE TRUNCATE CHUNKED DATASET dsetchr AS VARCHAR(UNLIMITED)") char bl[] = "blabal"; "INSERT INTO dsetchr(-1) FROM MEMORY " << HDFql::variableRegister(&bl);
只写零
所以从问题链接中出来的例子
在输入处,我们有一个字节数组和一个数据大小在第一个数组中的数组
uint8_t* ptr ;
HDFql::execute("CREATE TRUNCATE FILE test.h5");
HDFql::execute("USE FILE test.h5");
status = HDFql::execute("CREATE TRUNCATE CHUNKED DATASET inclusion AS UNSIGNED VARTINYINT(UNLIMITED)");
std::vector<int> s{ 6,12 };
std::vector<uint8_t> v{0x35,0x34, 0x35, 0x00, 0x00, 0x35,0x36,0x36, 0x36, 0x36, 0x36, 0x36,0x36,0x00, 0x36, 0x00, 0x36, 0x36 };
ptr = &v[0];
int number = HDFql::variableRegister(&ptr);
for (int i = 0; i < s.size();i++)
{
scriptst << "INSERT INTO inclusion(-1) VALUES FROM MEMORY " << number << " SIZE " << s[i];
status = HDFql::execute(scriptst);
ptr = ptr + s[i];
HDFql::execute("ALTER DIMENSION Inclusions TO +1");
scriptst.str(std::string());
scriptst.clear();
}
// my expectation that there will be a record in the file
// dataset ->row1 0x35,0x34, 0x35, 0x00, 0x00, 0x35
// dataset ->row2 0x36,0x36, 0x36, 0x36, 0x36, 0x36,0x36,0x00, 0x36, 0x00, 0x36, 0x36
// dataset ->row3
我想从数组中将数据输入到一个没有缺陷的文件中,并能够随时附加它们。
更新 我的实验和对文档的阅读使我想到了这个例子,但它仍然不能满足我的需要。这里一个字节数组存储在数据集中,每行 1 个字节。但我仍然想在数据集行上存储一个不同长度的字节数组
status = HDFql::execute("CREATE TRUNCATE FILE test_Titnyint.h5");
status = HDFql::execute("USE FILE test_Titnyint.h5");
status = HDFql::execute("CREATE TRUNCATE CHUNKED DATASET inclusion AS UNSIGNED TINYINT(UNLIMITED)");
std::vector<uint8_t> array{0x35,0x34, 0x00, 0x37, 0x35, 0x35,0x36,0x36, 0x36, 0x36, 0x00, 0x36,0x36,0x36, 0x36, 0x36, 0x36, 0x36 };
uint8_t* ptr ;
ptr = &array[0];
for (int i = 0; i < array.size();i++)
{
int number = HDFql::variableRegister(ptr);
if (i > 0) { status =HDFql::execute("ALTER DIMENSION inclusion TO +1"); }
scriptst << "INSERT INTO DATASET inclusion(-1) VALUES FROM MEMORY " << number ;
status = HDFql::execute(scriptst);
HDFql::variableUnregister(ptr);
ptr = ptr + 1;
scriptst.str(std::string());
scriptst.clear();
}
status = HDFql::execute("CLOSE FILE");
备注:向量“s”和“v”应该被认为是来自外部的输入。