• Welcome to SQLitening Support Forum.
 

News:

Welcome to the SQLitening support forums!

Main Menu

Storing a PDF-file

Started by Fim, March 03, 2021, 10:03:27 AM

Previous topic - Next topic

Fim

Can a PDF file be stored in a database, if so how?
/Fim W.
Fim W

cj

#1
Yes, any file type can be insert into a blob column, but it may not be the best choice.
PDF files can be saved in a database, but client or I copy them "as is" into a folder for each client.
The client can click on them or do anything without having to save to a database and extract.
Chrome browser displays PDF files very well or SHELL "filename.pdf" to use default viewer for type "pdf".
Giving the client the option to open pdf folder allows them to select/display with a click.

#COMPILE EXE "SaveAnyFile"  'Save as "SaveAnyfile.Bas"
#INCLUDE "sqlitening.inc"
  
FUNCTION PBMAIN () AS LONG
 LOCAL sData AS STRING
 LOCAL sFileName AS STRING

 slOpen "junk.db3","C"
 slexe  "create table if not exists Table1(MyFile)"

 sFileName = "SaveAnyFile.bas"
 IF GetFileFromDisk(sFileName,sData) THEN EXIT FUNCTION
 slExeBind "insert into Table1 values(?)",slbuildbinddat(sData,"B")
 IF slGetChangeCount = 0 THEN ? "insert error":EXIT FUNCTION

 slsel "select rowid,Myfile from Table1"
 DO WHILE slGetRow
   ? CHR$("Rowid=",slfn("rowid"),$CR,$CR,slfn("MyFile"))
 LOOP
END FUNCTION

FUNCTION GetFileFromDisk(sFileName AS STRING,sData AS STRING) AS LONG
 sData = ""
 IF ISFILE(sFileName) = 0 THEN FUNCTION = 53:EXIT FUNCTION
 LOCAL hfile AS LONG
 hfile = FREEFILE
 OPEN sFileName FOR BINARY AS hFile
 IF ERR THEN FUNCTION = ERR:BEEP:EXIT FUNCTION
 GET$ hFile,LOF(hFile),sData
 IF ERR THEN FUNCTION = ERR
 CLOSE hFile
END FUNCTION

Fim

Many thanks for an exhaustive answer.
/Fim W.
Fim W