Jump to content
Registration disabled at the moment Read more... ×
Sign in to follow this  
dormky

MyDAC blob from PDF

Recommended Posts

query := TMyQuery.Create(nil);
query.Connection := conn;
query.SQL.Text := 'INSERT INTO documents (key, document) VALUES (:pkey, :pdocument)';
query.ParamByName('pkey').Value := 'key';
query.ParamByName('pdocument').AsBytes := TFile.ReadAllBytes('dummy_1.pdf');
query.Execute();
query.Free();
CREATE TABLE `documents` (
  `key` VARCHAR(255) NOT NULL,
  `document` MEDIUMBLOB);

The pdf file https://www.cte.iup.edu/cte/Resources/PDF_TestPage.pdf

 

For some reason, without the key field this works perfectly fine, but with it I get the error :

EMySqlException with message '#42000You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key, document) VALUES ('key', '%PDF-1.4\n%äüöß\n2 0 obj\n<</Length 3 0 R/Fil' at line 1'.

 

Does anyone have any idea of what forsaken bullshit is going on ?

It doesn't look like an escape character issue AFAIK as the problem occurs whether the key parameter is in front of the document parameters or after it.

I think it's because delphi is casting the pdf file as text but I'm not sure.

 

Edit : I'm blind. Since MyDAC forces you to write SQL statements by hand, I forgot about the `. Gotta hate on bad error messages 🙂

Edited by dormky

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×