Page 1 of 1
Imprimir imagen guardada en tabla SQL
Posted: Wed Dec 16, 2020 12:39 pm
by jpcavagnaro
Hola buen día, necesito imprimir una imagen guardada en una tabla sql, que la guarde así:
oRsFoto:Fields( "Foto" ):Value := STRTOHEX( MEMOREAD( aFiles[ i ] ) )
Estoy tratando de imprimirla así: ImprimirFoto( oRsFoto:Fields( "Foto" ):Value )
Function ImprimirFoto(wfoto)
PRINT oPrn PREVIEW MODAL
PAGE
oPrn:SayImage(0,0, wfoto, oPrn:nHorzRes(), oPrn:nVertRes() , nil, .t. )
ENDPAGE
ENDPRINT
retu .t.
No da error, pero muestra una hoja en blanco.
Saludos
Jorge
Re: Imprimir imagen guardada en tabla SQL
Posted: Mon Dec 21, 2020 12:10 pm
by nageswaragunupudi
This should work, if you created the table with FOTO as BLOB datatype.
Re: Imprimir imagen guardada en tabla SQL
Posted: Tue Dec 22, 2020 2:00 pm
by Rick Lipkin
Rao
I am using MS Sql Server .. there is no "Blob Type" .. however VarBinary(max) works for me ..
Rick Lipkin
Re: Imprimir imagen guardada en tabla SQL
Posted: Wed Dec 23, 2020 10:21 pm
by jpcavagnaro
Hola la imagen está como VarBinary (max) y no funciona.
Lo solucione guardando la imagen en un temporal.jpg e imprimir desde ese temporal y funciona perfecto.
Saludos.
Jorge
Re: Imprimir imagen guardada en tabla SQL
Posted: Thu Dec 24, 2020 4:03 pm
by nageswaragunupudi
Can you please let us know if you are using MySql or MSSQL and also the version of FWH you are using?
Re: Imprimir imagen guardada en tabla SQL
Posted: Fri Dec 25, 2020 2:27 pm
by nageswaragunupudi
jpcavagnaro wrote:Hola la imagen está como VarBinary (max) y no funciona.
Lo solucione guardando la imagen en un temporal.jpg e imprimir desde ese temporal y funciona perfecto.
Saludos.
Jorge
Not necessary.
This is an example for MSSQL.
This sample uses MSSQL server in the cloud provided by FiveTech for demonstration purposes.
Please copy the sample to \fwh\samples folder and build with buildx.bat or buildh.bat
Code: Select all
#include "fivewin.ch"
function Main()
local oCn, nVer, cSql, oRs, oPrn
oCn := FW_OpenAdoConnection( { "MSSQL", "208.91.198.196", "gnraore3_", "fwhmsdemo", "fwh@2000#" }, .t. )
if oCn == nil
? "Connect fail"
return nil
end
nVer := Val( oCn:Properties( "DBMS Version" ):Value )
// CREATE TABLE
TRY
oCn:Execute( "DROP TABLE [adoimage]" )
CATCH
END
if nVer < 9
//
TEXT INTO cSql
CREATE TABLE [adoimage] (
[ID] INT IDENTITY( 1, 1 ) PRIMARY KEY,
[NAME] VARCHAR ( 10 ),
[FOTO] IMAGE
)
ENDTEXT
//
else
//
TEXT INTO cSql
CREATE TABLE [adoimage] (
[ID] INT IDENTITY( 1, 1 ) PRIMARY KEY,
[NAME] VARCHAR ( 10 ),
[FOTO] VARBINARY(max)
)
ENDTEXT
//
endif
oCn:Execute( cSql )
// ADD ONE RECORD TO THE TABLE
oRs := FW_OpenRecordSet( oCn, "adoimage" )
oRs:AddNew()
oRs:Fields( "NAME" ):Value := "OLGA1"
oRs:Fields( "FOTO" ):Value := STRTOHEX( MEMOREAD( "c:\fwh\bitmaps\olga1.jpg" ) )
oRs:Update()
oRs:Close()
// OPEN THE TABLE AND PRINT
oRs := FW_OpenRecordSet( oCn, "adoimage" )
PRINT oPrn PREVIEW
PAGE
oPrn:SayImage(0,0, oRs:Fields( "FOTO" ):Value, 1800, 2400, nil, .t. )
ENDPAGE
ENDPRINT
oRs:Close()
oCn:Close()
return nil
Re: Imprimir imagen guardada en tabla SQL
Posted: Fri Dec 25, 2020 3:38 pm
by nageswaragunupudi
Hola la imagen está como VarBinary (max) y no funciona.
This depends on the MSSQL server version.
For versions less than 9.0, we need to use
and for later versions, we can use
Please see the sample above.
Re: Imprimir imagen guardada en tabla SQL
Posted: Fri Dec 25, 2020 4:12 pm
by nageswaragunupudi
We have seen that the SQL statement required to create a table can be different for different versions of MSSQL. Naturally it is different for different RDBMS like MSSQL, MYSQL, ORACLE, etc.
For example the SQL for the same table can be:
Code: Select all
CREATE TABLE `adoimage` (
`ID` INT AUTO_INCREMENT PRIMARY KEY,
`NAME` VARCHAR ( 10 ),
`FOTO` LONGBLOB
)
For MSACCESS:
Code: Select all
CREATE TABLE [adoimage] (
[ID] AUTOINCREMENT PRIMARY KEY,
[NAME] VARCHAR ( 10 ),
[FOTO] LONGBINARY
)
Instead of writing SQL statements for creation of tables on our own, we recommend using FWH function
Code: Select all
FWAdoCreateTable( cTable, aStruct, oCn, [lAddAutoInc := .t.] )
aStruct is a normal DBF style structure array we are all very familiar with. Data type "M" creates a long text field and datatype "m" creates a long binary field.
This function internally creates an sql statement appropriate for the RDBMS and its version and we are relieved from the trouble of finding the correct datatype.
The next sample demonstrates using this function for MSSQL, MYSQL and MSACCESS. Using FWH provided ADO functions, we can write code that works with different RDBMS (also versions) without changing our application code:
Code: Select all
#include "fivewin.ch"
function Main()
local nCh, oCn, oRs, oPrn
local cTable := "adoimage"
local aImages := { "c:\fwh\bitmaps\olga1.jpg", "c:\fwh\bitmaps\sea.bmp" }
nCh := Alert( "RDMBS", { "MySQL", "MSSQL", "MSACCESS" }, "Select" )
if nCh == 1
oCn := FW_OpenAdoConnection( { "MYSQL", "54.37.60.32", "fwh", "fwhuser", "fwh202006" }, .t. )
elseif nCh == 2
oCn := FW_OpenAdoConnection( { "MSSQL", "208.91.198.196", "gnraore3_", "fwhmsdemo", "fwh@2000#" }, .t. )
elseif nCh == 3
oCn := FW_OpenAdoConnection( "xbrtest.mdb" )
else
return nil
endif
if oCn == nil
? "Connection error"
return nil
endif
TRY
oCn:Execute( "DROP TABLE " + cTable )
CATCH
END
FWAdoCreateTable( cTable, { { "NAME", "C", 10, 0 }, { "FOTO", "m", 8, 0 } }, oCn )
oRs := FW_OpenRecordSet( oCn, cTable )
// Append one image
oRs:AddNew()
oRs:Fields( "NAME" ):Value := Upper( cFileNoExt( aImages[ 1 ] ) )
oRs:Fields( "FOTO" ):Value := STRTOHEX( MEMOREAD( aImages[ 1 ] ) ) // Harbour: HB_STRTOHEX(...)
oRs:Update()
// Append second image. Simpler method
oRs:AddNew( { "NAME", "FOTO" }, { Upper( cFileNoExt( aImages[ 2 ] ) ), HB_STRTOHEX( MEMOREAD( aImages[ 2 ] ) ) } )
oRs:Close()
oRs := FW_OpenRecordSet( oCn, cTable )
XBROWSER oRs
oRs:MoveFirst()
PRINT oPrn PREVIEW
PAGE
@ 1,1 PRINT TO oPrn IMAGE oRs:Fields( "FOTO" ):Value SIZE 6,4 INCHES
oRs:MoveNext()
@ 6,1 PRINT TO oPrn IMAGE oRs:Fields( "FOTO" ):Value SIZE 6,4 INCHES
ENDPAGE
ENDPRINT
oRs:Close()
return nil
For all RDBMSs it is the same code and same result:
Re: Imprimir imagen guardada en tabla SQL
Posted: Sat Dec 26, 2020 4:58 am
by richard-service
nageswaragunupudi wrote:Hola la imagen está como VarBinary (max) y no funciona.
This depends on the MSSQL server version.
For versions less than 9.0, we need to use
and for later versions, we can use
Please see the sample above.
Mr.Rao
MySQL v8.0.13 same as support it.
Re: Imprimir imagen guardada en tabla SQL
Posted: Sat Dec 26, 2020 2:04 pm
by Rick Lipkin
Rao
I have looked for LONGBINARY in the field selections of Ms Access.mdb and .ACCDB and that data type is not an option .....
I am using ole object a field to store pictures in Ms Access ....
???
Thanks
Rick Lipkin
Re: Imprimir imagen guardada en tabla SQL
Posted: Mon Dec 28, 2020 9:58 pm
by nageswaragunupudi
richard-service wrote:nageswaragunupudi wrote:Hola la imagen está como VarBinary (max) y no funciona.
This depends on the MSSQL server version.
For versions less than 9.0, we need to use
and for later versions, we can use
Please see the sample above.
Mr.Rao
MySQL v8.0.13 same as support it.
The discussion about field types IMAGE and VARBINARY(max) are for MSSQL ( Micorosoft SQL Server ) but not for MySQL.
Because you are using MySQL, this does not apply to you.
Re: Imprimir imagen guardada en tabla SQL
Posted: Mon Dec 28, 2020 10:03 pm
by nageswaragunupudi
Rick Lipkin wrote:Rao
I have looked for LONGBINARY in the field selections of Ms Access.mdb and .ACCDB and that data type is not an option .....
I am using ole object a field to store pictures in Ms Access ....
???
Thanks
Rick Lipkin
https://docs.microsoft.com/en-us/sql/od ... rver-ver15
You can choose OLE and then store any binary data in the field. But when we create the table using SQL, better we use the datatype VARBINARY or LONGBINARY.
Also see
https://codekabinett.com/rdumps.php?Lan ... s-database