【发布时间】:2021-10-15 14:55:42
【问题描述】:
我有一个 SQLite 数据库,将图像数据存储在一个表中。 该表以整数格式保存图像的高度和宽度,以 BLOB 格式保存实际图像的二进制数据。
我目前正在使用回调函数来获取所需的数据,如下所示,
/*
MethodName : callback
FUnctionality : This method is used to fetch the Output data in Collection format based on the Query passed to sqlite3_exec API.
*/
static int callback(void* data, int argc, char** argv, char** azColName)
{
int i, width, height;
//Iterating columns
for (i = 0; i < argc; i++) {
string columnName = azColName[i];
if (columnName == "Image_Height")
{
height= stoll(columnVal);
}//end of if
else if (columnName == "Image_Width")
{
width = stoll(columnVal);
}//end of else if
else if (columnName == "BLOB_DATA")
{
**/ *How to fetch BLOB data? */**
}//end of else if
}//end of for
return 0;
}//end of callback
我们如何存储 BLOB 数据,以便在进一步的步骤中转换为实际图像? 我们不知道任何可用于存储 BLOB 数据的方法,因为我们是这个概念的新手。 有什么方法可以满足我们的要求吗?
【问题讨论】:
-
你最初是如何将BLOB数据存储在表中的?只需颠倒这个过程。
-
我目前正在使用包含 BLOB 数据的可用本地数据库。目标是从表格中可用的 BLOB 数据中获取数据。
-
不要使用
sqlite3_exec()函数。使用prepared statement 并直接访问BLOB 列数据,方法是将其复制到unsigned char[]。