使用 PowerShell 将 MySQL blob图像迁移到 FileMaker 容器

问题描述

搜索过程中,我发现了许多其他人尝试过,但都没有成功。

问题来了。我想将存储在 MysqL 服务器上的一堆图像以 blob 形式存储,然后将它们移动到 FileMaker 容器中。

我得到的最好的线索是 putas 命令。它看起来有点像 putas('$Image','JPEG')。

我的具体应用如下。 $DataSet.Image1 是一个 JPEG 文件,存储为“0xFFD8....”。这种格式的数据很可能是问题所在,但我不知道我需要先将其转换为什么。

$cmd.CommandText = "update Checklists set Image1 = PutAs('$($DataSet.Image1)','JPEG')"
$cmd.ExecuteNonQuery();

我一直得到的只是语法错误,但我已经尝试了许多不同的语法,无论我做什么都无法让它继续。

我非常希望看到有人在这方面取得成功来发布他们的示例。也欢迎任何其他想法或解决方法

编辑: 这是一些额外的信息。 Skeleton Key 的 Greg Lane 给出了这个例子,但我不知道如何将它翻译成 PowerShell。

import java.sql.*; import java.io.*;
def url = "jdbc:filemaker://localhost/fmserver_sample";
def driver = "com.filemaker.jdbc.Driver";
def user = "admin";
def password = "";
System.setProperty("jdbc.drivers",driver);
connection = DriverManager.getConnection (url,user,password);
filename = "/Users/Greg/Pictures/vacation/DSC_0202.jpg";
file = new File (filename);
inputstream = new FileInputStream (filename);
sql = "INSERT INTO english_nature (ID,img) VALUES (-1,PutAs(?,'JPEG'))";
pstatement = connection.prepareStatement ( sql );
pstatement.setBinaryStream (1,inputstream,(int)file.length ());
pstatement.execute ();
//cleanup
pstatement = null;
inputstream = null;
file = null;
connection.close();

解决方法

我想通了。对于未来的任何人,这就是您如何做到的。

$cmd.CommandText = "update Checklists set Image1 = PutAs(?,'JPEG') where serial = '$($DataSet.serial)' AND ChecklistNumber = 1"
$cmd.Parameters.Add('?',$DataSet.Image1)
$cmd.Prepare()
$cmd.ExecuteNonQuery();