Dear All,
I am working on a project requiring PDFs to be loaded into MySQL database (community edition). We can’t simply store PDFs in a file location to be reached by the client application as the client application is on a microsoft tablet, which is only allowed to communicate with a MySQL server (port 3306 is only open port).
I googled to below code together but keep on getting error message:
DB Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Blob) values ('aVCCT1J3MEtHZ29 …
I have tried different combinations in both the database and in the code:
NewRow.Column(“Blob”).StringValue=EncodeBase64(PDFString) NewRow.Column(“Blob”).BlobValue= …
Column “Blob” defined in table as Stringvalue as well as Blobvalue.
The error message is very consistent.
It seems that the following code and its translation to SQL to talk to MySQL is not compatible with Blobvalues: db.AddRow(“BlobTabel”,NewRow)
I have also tried to first create a new record in the table and then use Select query, with Rowsfound1.editrow Rowsfound1.column(“Blob”).blobvalue = EncodeBase64(PDFString) Rowsfound1.saverow
I also used it without EncodeBase64 as this is already done earlier in the function PDFToBlob (Included at the bottom).
I have downloaded the MBS add in but have not used it yet as I believe this should be possible to do with standard Xojo.
Can you please let me know how to resolve this issue?
Thanks and cheers,
GT
Code to pickup PDF from filesystem and saving it into MySQLCommunityServer database:
var PDFString as String Var f As FolderItem var db as new MySQLCommunityServer
var NewRow as new DatabaseRow
db.host = TifaCalcVariables.TFDataBaseServerGlobal db.port = TifaCalcVariables.TFDataBaseServerPortGlobal db.DatabaseName= TifaCalcVariables.TFDatabaseNameGlobal db.UserName = TifaCalcVariables.TFGebruikerGlobal db.Password = TifaCalcVariables.TFWachtWoordGlobal
db.TimeOut=15
db.Connect
f = folderitem.showopenfiledialog(“*.pdf”)
PDFString = app.PDFtoBlob(f)
NewRow.Column(“Blob”).StringValue=EncodeBase64(PDFString)
try
db.BeginTransaction db.AddRow(“BlobTabel”,NewRow)
db.CommitTransaction
Catch error As DatabaseException MessageBox("DB Error: " + error.Message) End Try
db.close
Function app.PDFtoBlob:
dim PDFContents as string = “” dim BS as BinaryStream = BinaryStream.open(f) dim SBlock as string = bs.Read(bs.length) bs.Close PDFContents = EncodeBase64(SBlock) SBlock=“” return PDFContents