如何在 Informix 上将二进制 blob 写入磁盘
我在 informix 数据库中有一些图像,作为二进制 blob 字段 (jpg),我如何使用 SQL 将图像写入磁盘?
I have some images in an informix database, as a binary blob field (jpg), how can i write the images onto disk with an SQL?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
数据存储在 BYTE 字段还是 BLOB 字段中?
如果数据存储在 BLOB 列中,那么您可以使用:
如果数据存储在 BYTE 列中,那么您必须更加努力地工作。如果您的计算机上有 ESQL/C (ClientSDK) 和 C 编译器,那么我建议从 IIUG Software 获取 SQLCMD存档并解压软件。您需要 Informix 环境集,并且需要能够编译 C 程序。然后运行:
您指定什么作为前缀并不重要 - 您只需要运行配置脚本即可。
然后,您可以编译所有内容 (
make
),也可以简单地编译程序selblob
(make selblob
)。这个程序就是我所说的“小插曲”;一个微观程序,展示如何选择 BYTE blob 到磁盘。然而,它也是功能齐全的;它几乎可以处理您扔给它的任何东西,或者诊断错误。如果您的数据库名为
precious
,则字节数据位于表byte_table
中,保存数据的列为byte_column
,主键列分别是col1
(所需值为23
)和col2
(所需值为“Habeas Corpus”
),然后您可以运行:这会将字节值卸载到指定文件中。
如果您没有 ESQL/C 或 C 编译器或没有使用它们的权限,那么生活会更加困难。最接近的方法是使用 DB-Access 中的 UNLOAD 语句:
这将创建一个包含字节值(每个字符 2 个字节)的十六进制转储的文件。然后,您需要对文件进行后处理,将十六进制转换为常规数据。请注意,如果该列是 TEXT 列而不是 BYTE 列,则不需要转换。您可以使用相当简单的 Perl 脚本来进行转换(前提是文件足够小,可以放入内存中 - 如果文件不够小,您必须更加努力):
长度条件指定 '
>; 1
' 处理卸载数据末尾的换行符。(对于“歇斯底里的葡萄干”,又名“历史原因”,我仍然将 BYTE 和 TEXT 称为“blob 类型”,尽管 IDS 9.00 为“智能 blob”引入了显式名称 BLOB 和 CLOB,这是一对略有不同的数据类型大致对应的功能 - 在我的书中,它们都是 blob(小写)类型 这就是 1990 年(比 BLOB 和 CLOB blob 被添加六年或更长时间)了解 BYTE 和 TEXT blob 的老家伙们的麻烦。
无论如何,对于旧式斑点没有一个好的替代官方术语。使用“愚蠢的斑点”在政治上是不正确的!)
Is the data stored in a BYTE or a BLOB field?
If the data is stored in a BLOB column, then you can use:
If the data is stored in a BYTE column, then you have to work rather harder. If you have ESQL/C (ClientSDK) and a C compiler on your machine, then I recommend obtaining SQLCMD from the IIUG Software Archive and extracting the software. You need your Informix environment set, and you need to be able to compile C programs. Then run:
It doesn't much matter what you specify as the prefix - you just need to run the configure script.
You can then either compile everything (
make
), or you can simply compile the programselblob
(make selblob
). That program is what I call a 'vignette'; a microscopic program that shows how to select a BYTE blob to disk. It is, however, also fully-functional; it will work with just about anything that you throw at it, or diagnose an error.If your database is called
precious
, the byte data is in a tablebyte_table
, the column holding the data isbyte_column
, and the primary key columns arecol1
(and the value required is23
) andcol2
(and the value required is"Habeas Corpus"
), then you can run:This will unload the byte value into the named file.
If you don't have ESQL/C or a C compiler or permission to use them, then life is more difficult. The closest approach is to use the UNLOAD statement in DB-Access:
This will create a file containing a hex-dump of the byte value (2 bytes per character). You then need to post-process the file to convert the hex into regular data. Note that if the column was a TEXT column instead of a BYTE column, then no conversion would be needed. You can use a fairly simple Perl script to do the conversion (provided the file is small enough to be slurped into memory - you have to work harder if it is not small enough):
The length condition specifies '
> 1
' to deal with the newline at the end of the unloaded data.(For 'hysterical raisins', aka 'historical reasons', I still call both BYTE and TEXT 'blob types', even though IDS 9.00 introduced the explicit names BLOB and CLOB for 'smart blobs', a slightly different pair of data types with roughly corresponding functionality - in my book, they're all blob (lower-case) types. That's the trouble with old guys who learned about BYTE and TEXT blobs in 1990, six years or more before BLOB and CLOB blobs were added.
In any case, there isn't a good alternative official terminology for the older style blobs; using 'dumb blobs' is not politically correct!)
您需要编写一个小程序来查询数据库并将 blob 保存到磁盘。大多数数据库没有“在磁盘上打开文件”的概念。
You need to write a small program that queries the database and saves the blobs to disk. Most databases have no notion of "open file on disk".