开发者

Failed to read blob data from sqlite

i store blob data with php like this

$this->_db->exec"CREATE TABLE media (url TEXT, content BLOB)");

$fp = fopen($encoded['path'], 'rb');
$sql = "INSERT INTO media (url, content) VALUES (?, ?)";
$stmt = $this->_db->prepare($sql)开发者_StackOverflow;
$stmt->bindValue(1, $encoded['url'], PDO::PARAM_STR);
$stmt->bindValue(2, $fp, PDO::PARAM_LOB);
$stmt->execute();
fclose($fp);

And in my c++ program (using bada framework) i read the data from blob column back. The problem is, when i use php on my localhost (version 5.3.2-1ubuntu4.2), my c++ app can recognize the blob column as blob type correctly. But when i use my remote host (php version 5.2.12) to create sqlite file, my c++ app recognizes the blob column as TEXT TYPE and my binary data is corrupted.

Does anyone know why and any work around?

Thanks


Make sure you're reading and writing the same SQLite versions and not: Server = SQLite2 <-> C++ = SQLite2 or Server = SQLite3 <-> C++ = SQLite3 because that will fail.

If that's the problem (which is most likely the case due to the changes within SQLite, rendering the two versions incompatible to read vise-versa), you have two options:

  1. you can either update your server (ask your provider), or
  2. you can use the applicable C++ sourcecode to enable your software to read what your server can handle. For this purpose, you can get the sourcecode of SQLite2 (as well as all other builds that are archived there) at sqlite.org. To be more exact, you can find the latest download of the most recent version SQLite2 sourcecode at http://www.sqlite.org/cgi/src/info/47fee16ba9 so you can compile support into your c++ program.

Hope that rocks your boat. ;)

PS: If that's not the problem and you are reading/writing to the same SQLite versions, you could try to hex-encode the binary data you are trying to store and save it to a TEXT instead of a BLOB. It's a workaround, but it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜