Sure! Below you will find the code which did the job. We build a little SQL example, but i´m not an SQL expert either, so watch out
This code is capable of transfering JPGs with a maximum size of 256 kB. If you want to transfer larger pictures, just increase the number of columns, i. e. add ImgVarChar8, ImgVarChar9 etc.
Maybe you can help me with my follow up question here?
Cheers!
-------------- SQL Code Start --------------
CREATE TABLE tIMG(
ID INT identity primary Key,
Img VARBINARY(MAX)
)
GO
INSERT INTO tIMG(Img) SELECT BulkColumn FROM
OPENROWSET(BULK 'C:\Test\test.jpg', SINGLE_BLOB) AS InsertIMG
GO
CREATE VIEW vImg AS
SELECT convert(varchar(max),substring(Img,0,32000),2) ImgVarChar0
,convert(varchar(max),substring(Img,32000,32000),2) ImgVarChar1
,convert(varchar(max),substring(Img,64000,32000),2) ImgVarChar2
,convert(varchar(max),substring(Img,96000,32000),2) ImgVarChar3
,convert(varchar(max),substring(Img,128000,32000),2) ImgVarChar4
,convert(varchar(max),substring(Img,160000,32000),2) ImgVarChar5
,convert(varchar(max),substring(Img,192000,32000),2) ImgVarChar6
,convert(varchar(max),substring(Img,224000,32000),2) ImgVarChar7
FROM [dbo].[tIMG]
GO
-------------- SQL Code End --------------
-------------- JMP Code Start --------------
// SQL Query to get the hex data (strings) from the database.
// The strings are stored in different columns in the data table "JPG_Query".
New SQL Query(
Connection(
"Your connection"
),
QueryName( "JPG_Query" ),
Select( Column( "ImgVarChar0", "t1" ), Column( "ImgVarChar1", "t1" ) ,
Column( "ImgVarChar2", "t1" ) ,Column( "ImgVarChar3", "t1" ),
Column( "ImgVarChar4", "t1" ) ,Column( "ImgVarChar5", "t1" ),
Column( "ImgVarChar6", "t1" ) ,Column( "ImgVarChar7", "t1" ) ),
From( Table( "vImg", Schema( "dbo" ), Alias( "t1" ) ) ),
) << Run;
// Loop to build the JPG image from the hex-strings and show the picture (maybe there is some redundant code...)
switch = 0;
count_try = 0;
max_try = 200;
hexcode = "";
While(switch == 0 & count_try < max_try,
count_try++;
Try(
hexcode1 = DataTable("JPG_Query"):Name("ImgVarChar0")[1];
hexcode2 = DataTable("JPG_Query"):Name("ImgVarChar1")[1];
hexcode3 = DataTable("JPG_Query"):Name("ImgVarChar2")[1];
hexcode4 = DataTable("JPG_Query"):Name("ImgVarChar3")[1];
hexcode5 = DataTable("JPG_Query"):Name("ImgVarChar4")[1];
hexcode6 = DataTable("JPG_Query"):Name("ImgVarChar5")[1];
hexcode7 = DataTable("JPG_Query"):Name("ImgVarChar6")[1];
hexcode8 = DataTable("JPG_Query"):Name("ImgVarChar7")[1];
hexcode = hexcode1||hexcode2||hexcode3||hexcode4||hexcode5||hexcode6||hexcode7||hexcode8;
picture = Open(Hex to Blob(hexcode), "jpg");
If ( Is Missing(hexcode) == 0 & Is Scriptable( Data Table("JPG_Query") ) == 1 ,
New Window( "JPG Image", picture );
hexcode = "";
switch = 1;
Close(Data Table("JPG_Query") , NoSave);
);
,
Wait(0.01);
If (count_try == max_try ,
Throw("Error!");
);
); // Close Try
); // Close While
-------------- JMP Code End --------------