将 OLE 对象从 Access 导入 MySQL
我在访问表中有一个表,其中包含产品条目,其中一列有一个存储为 OLE 对象的 jpg 图像。 我正在尝试将此表导入 MySQL,但似乎没有任何效果。 我尝试过 MySQL 迁移工具,但它存在 Access 和 OLE 对象的已知问题。 (问题是它不起作用并将字段留空)我还尝试了 此站点< /a> 当数据导入时,图像似乎在传输过程中被损坏。 当我尝试预览图像时,我只是得到一个二进制视图,如果我将其作为 jpg 图像保存在磁盘上并尝试打开它,我会收到一条错误消息,指出图像已损坏。
Access中的图像很好,可以预览。 Access 将数据存储为 OLE 对象,当我将其导入 MySql 时,它会保存在 MediumBlob 字段中。
以前有人遇到过这个问题吗?他们是如何解决的?
I have a table in an access table which contains Product entries, one of the columns has a jpg image stored as an OLE Object. I am trying to import this table to MySQL but nothing seems to work. I have tried the MySQL migration tool but that has a known issue with Access and OLE Objects. (The issue being it doesnt work and leaves the fields blank) I also tried the suggestion on this site
and while the data is imported it seems as though the image is getting corrupted in the transfer. When i try to preview the image i just get a binary view, if i save it on disk as a jpg image and try to open it i get an error stating the image is corrupt.
The images in Access are fine and can be previewed. Access is storing the data as an OLE Object and when i import it to MySql it is saved in a MediumBlob field.
Has anyone had this issue before and how did they resolve it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
还有 olefield - 用于从 Access 中的 OLE 对象字段中提取数据的 Python 模块。 我用它成功提取了BMP文件。 它可能适用于 jpeg 图像,但我还没有尝试过。
There's also olefield - Python module to extract data out of OLE object fields in Access. I successfully extracted BMP files with it. It could probably work with jpeg images, but I haven't tried it.
据我记得,微软“SQL Server Migration Assistant for Access" 将正确迁移 OLE 映像,但这仅适用于 Access->SQLServer。 但是,您可以使用它迁移到 SQLServer Express(免费下载),然后从 SQLServer 迁移到 MySQL。
As far as I remember, the Microsoft "SQL Server Migration Assistant for Access" will properly migrate OLE Images, but this is only for Access->SQLServer. However, what you can do is use this to migrate to SQLServer Express (free download) and then migrate from SQLServer to MySQL.
好吧,为了在这里公开发布我的肮脏代码,我想出了什么。
注意:这是一个设计为使用一次然后扔掉的黑客。
此方法采用包含访问表中的 1 行数据的数据行视图。 图像被封装在 OLE 序列化中,我并不完全熟悉它是如何工作的,但它是 Microsoft 应用程序如何允许任何对象嵌入到其他对象中的。 (例如将图像导入 Excel 单元格)。 我需要删除图像周围的序列化垃圾,因此我将整个字段作为字节数组加载,并在其中搜索 3 个并发条目 (FF D8 FF),它们代表字段内图像数据的开头。
然后就是将这些数据提取到位图中。 因此,对于访问表中的每一行,我提取位图,然后更新相应的 MySQL 条目。
它工作得很好,但我猜我可以用更好的方式删除序列化的东西,也许有一个 API 可以做到这一点。
Ok so in the interests of airing my dirty code in public here what i came up with.
Note : this is a hack designed to be used once and then thrown away.
This Method takes in a datarowview containing 1 row of data from the access table. The Images are wrapped in OLE serialization, im not entirely familiar with how this works but its how Microsoft apps allow any object to be embedded into something else. (eg images into Excel Cells). I needed to remove the serialization junk around the image so i loaded the entire field as a Byte array and searched through it for 3 concurrent entries (FF D8 FF) which represent the beginning of the image data within the field.
Then its a matter of pulling out this data into a bitmap. So for each row in the access table i extract the bitmap and then update the corresponding MySQL entry.
It worked fine but im guessing i could have removed the serialisation stuff in a better way, perhaps theres an API to do it.