Subject | Re: [firebird-support] Delphi + Firebird + BLOB + MSWord document + Stream |
---|---|
Author | Thomas Clarke |
Post date | 2012-09-25T20:53:18Z |
On Tue, Sep 25, 2012 at 11:45 AM, emailx45 <emailx45@...> wrote:
This is a solution I implemented to store PDF files as blob fields in
Firebird. It uses the the FIBPlus components.
function TdmConnect.WriteScanToDatabase(FileName: TFileName): Integer;
begin
Result := 0;
try
try
sqlScan.Open;
sqlScan.Insert;
TBlobField(sqlScan.FieldByName('document')).LoadFromFile(FileName);
sqlScan.Post;
Result := sqlScan.FieldByName('scan_id').AsInteger;
except
Result := 0;
raise;
end;
finally
sqlScan.Close;
end
end;
The sqlScan SQL from the DFM file:
object sqlScan: TpFIBDataSet
UpdateSQL.Strings = (
'UPDATE SCANS'
'SET '
' SCAN_ID = :SCAN_ID,'
' DOCUMENT = :DOCUMENT'
'WHERE'
' SCAN_ID = :OLD_SCAN_ID'
' ')
DeleteSQL.Strings = (
'DELETE FROM'
' SCANS'
'WHERE'
' SCAN_ID = :OLD_SCAN_ID'
' ')
InsertSQL.Strings = (
'INSERT INTO SCANS('
' SCAN_ID,'
' DOCUMENT'
')'
'VALUES('
' :SCAN_ID,'
' :DOCUMENT'
') returning (scan_id)')
RefreshSQL.Strings = (
'SELECT'
' SCAN_ID,'
' DOCUMENT'
'FROM'
' SCANS '
''
' WHERE '
' SCANS.SCAN_ID = :OLD_SCAN_ID'
' ')
SelectSQL.Strings = (
'SELECT'
' SCAN_ID,'
' DOCUMENT'
'FROM'
' SCANS '
'where'
' scan_id = :ScanId')
AutoUpdateOptions.UseReturningFields = [rfKeyFields]
Transaction = trnRead
I hope this helps.
Regards.
Thomas Clarke
Cyber Sea Incorporated
Barbados
voice: (246) 234-9692
email: tclarke@...
web: http://cybersea.biz
[Non-text portions of this message have been removed]
> **Hi there,
>
>
> Dear friends,
>
> I would like to know, if its possible, a help of you!
>
> I need to know how to save one file MS Word Doc or Docx in a BLOB and read
> it by stream, but, dont to use save in disk before!
>
> I search in internet for a long time, but, only found the same procedure...
>
> Can you help me?
>
> Scenary:
> -- Delphi xe2
> -- Firebird 2.5
> -- FIBPLus 7.3
> -- Windows 7
>
> I know how to save the file (doc. jpg, etc...) in a BLOB field (binary
> type)
> I know how to read (using save in disk and read the file)
>
> But, I need read the BLOB content by STREAM, or be, read portions of file
> into BLOB
>
> Thanks for you!
>
> Note: If you can not help me, please if you can show me Some site or user
> who can give me a hint about this problem!
>
>
>
This is a solution I implemented to store PDF files as blob fields in
Firebird. It uses the the FIBPlus components.
function TdmConnect.WriteScanToDatabase(FileName: TFileName): Integer;
begin
Result := 0;
try
try
sqlScan.Open;
sqlScan.Insert;
TBlobField(sqlScan.FieldByName('document')).LoadFromFile(FileName);
sqlScan.Post;
Result := sqlScan.FieldByName('scan_id').AsInteger;
except
Result := 0;
raise;
end;
finally
sqlScan.Close;
end
end;
The sqlScan SQL from the DFM file:
object sqlScan: TpFIBDataSet
UpdateSQL.Strings = (
'UPDATE SCANS'
'SET '
' SCAN_ID = :SCAN_ID,'
' DOCUMENT = :DOCUMENT'
'WHERE'
' SCAN_ID = :OLD_SCAN_ID'
' ')
DeleteSQL.Strings = (
'DELETE FROM'
' SCANS'
'WHERE'
' SCAN_ID = :OLD_SCAN_ID'
' ')
InsertSQL.Strings = (
'INSERT INTO SCANS('
' SCAN_ID,'
' DOCUMENT'
')'
'VALUES('
' :SCAN_ID,'
' :DOCUMENT'
') returning (scan_id)')
RefreshSQL.Strings = (
'SELECT'
' SCAN_ID,'
' DOCUMENT'
'FROM'
' SCANS '
''
' WHERE '
' SCANS.SCAN_ID = :OLD_SCAN_ID'
' ')
SelectSQL.Strings = (
'SELECT'
' SCAN_ID,'
' DOCUMENT'
'FROM'
' SCANS '
'where'
' scan_id = :ScanId')
AutoUpdateOptions.UseReturningFields = [rfKeyFields]
Transaction = trnRead
I hope this helps.
Regards.
Thomas Clarke
Cyber Sea Incorporated
Barbados
voice: (246) 234-9692
email: tclarke@...
web: http://cybersea.biz
[Non-text portions of this message have been removed]