Imprimir imagen guardada en tabla SQL
-
- Posts: 35
- Joined: Tue Oct 11, 2016 1:02 pm
Imprimir imagen guardada en tabla SQL
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
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
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Imprimir imagen guardada en tabla SQL
This should work, if you created the table with FOTO as BLOB datatype.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Rick Lipkin
- Posts: 2397
- Joined: Fri Oct 07, 2005 1:50 pm
- Location: Columbia, South Carolina USA
Re: Imprimir imagen guardada en tabla SQL
Rao
I am using MS Sql Server .. there is no "Blob Type" .. however VarBinary(max) works for me ..
Rick Lipkin
I am using MS Sql Server .. there is no "Blob Type" .. however VarBinary(max) works for me ..
Rick Lipkin
-
- Posts: 35
- Joined: Tue Oct 11, 2016 1:02 pm
Re: Imprimir imagen guardada en tabla SQL
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
Lo solucione guardando la imagen en un temporal.jpg e imprimir desde ese temporal y funciona perfecto.
Saludos.
Jorge
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Imprimir imagen guardada en tabla SQL
Can you please let us know if you are using MySql or MSSQL and also the version of FWH you are using?
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Imprimir imagen guardada en tabla SQL
Not necessary.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
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
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Imprimir imagen guardada en tabla SQL
This depends on the MSSQL server version.Hola la imagen está como VarBinary (max) y no funciona.
For versions less than 9.0, we need to use
Code: Select all
[FOTO] IMAGE
Code: Select all
[FOTO] VARBINARY(max)
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Imprimir imagen guardada en tabla SQL
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:
For MSACCESS:
Instead of writing SQL statements for creation of tables on our own, we recommend using FWH function
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:
For all RDBMSs it is the same code and same result:
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
)
Code: Select all
CREATE TABLE [adoimage] (
[ID] AUTOINCREMENT PRIMARY KEY,
[NAME] VARCHAR ( 10 ),
[FOTO] LONGBINARY
)
Code: Select all
FWAdoCreateTable( cTable, aStruct, oCn, [lAddAutoInc := .t.] )
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
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- richard-service
- Posts: 583
- Joined: Tue Oct 16, 2007 8:57 am
- Location: New Taipei City, Taiwan
- Contact:
Re: Imprimir imagen guardada en tabla SQL
Mr.Raonageswaragunupudi wrote:This depends on the MSSQL server version.Hola la imagen está como VarBinary (max) y no funciona.
For versions less than 9.0, we need to useand for later versions, we can useCode: Select all
[FOTO] IMAGE
Please see the sample above.Code: Select all
[FOTO] VARBINARY(max)
MySQL v8.0.13 same as support it.
Regards,
Richard
Harbour 3.2.0dev (r1904111533)/xHarbour 1.2.3 Intl. (SimpLex) (Build 20180818) => Borland C++ v7.4
xHarbour 0.99.71 (SimpLex) => Borland C++ v5.5
MySQL v5.7 /ADS v12
Harbour 3.2.0dev (r1603181642) => Borland C++ v7.4 64bit
Richard
Harbour 3.2.0dev (r1904111533)/xHarbour 1.2.3 Intl. (SimpLex) (Build 20180818) => Borland C++ v7.4
xHarbour 0.99.71 (SimpLex) => Borland C++ v5.5
MySQL v5.7 /ADS v12
Harbour 3.2.0dev (r1603181642) => Borland C++ v7.4 64bit
- Rick Lipkin
- Posts: 2397
- Joined: Fri Oct 07, 2005 1:50 pm
- Location: Columbia, South Carolina USA
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Imprimir imagen guardada en tabla SQL
The discussion about field types IMAGE and VARBINARY(max) are for MSSQL ( Micorosoft SQL Server ) but not for MySQL.richard-service wrote:Mr.Raonageswaragunupudi wrote:This depends on the MSSQL server version.Hola la imagen está como VarBinary (max) y no funciona.
For versions less than 9.0, we need to useand for later versions, we can useCode: Select all
[FOTO] IMAGE
Please see the sample above.Code: Select all
[FOTO] VARBINARY(max)
MySQL v8.0.13 same as support it.
Because you are using MySQL, this does not apply to you.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Imprimir imagen guardada en tabla SQL
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
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India