How to insert this text in PostgreSQL?

0

I'm using a Delphi query and I need to insert the text below into a text type field

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fswiss\fprq2\fcharset0 Calibri;}{\f1\froman\fcharset0 Times New Roman;}{\f2\fnil\fcharset0 Tahoma;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\fi-11\qj\tx142\tx360\tx720\tx9700\cf1\lang1046\f0\fs18 ssssssss\par
\par
Cabe ao empregador quanto ao EPI, orientar e treinar o trabalhador sobre o uso adequado, guarda e conserva\'e7\'e3o.\par
\pard\fi-11\tx142\tx360\tx720\tx9700\par
\cf0\f1\fs24 CONTE\'daDO PROGRAM\'c1TICO\par
\cf1\b\i\f0\fs18\par
\b0\i0 - Utiliza\'e7\'e3o adequada\par
- Respons\'e1bilidade sobre Guarda e Conserva\'e7\'e3o\par
- Cumprir determina\'e7\'f5es do empregador sobre uso adequado \par
- Comunicar ao empregador qualquer altera\'e7\'e3o que torne impr\'f3prio para o uso \par
- C.A Certificado de aprova\'e7\'e3o  \par
\par
\par
Com Certificado para a Empresa e Lista de Presen\'e7a.\par
\par
\pard\sb100\sa100\qj\cf0\f1\fs24 c\sdc\par
\par
\pard\sb100\sa100\par
\pard\fi-11\tx142\tx360\tx720\tx9700\cf1\f0\fs18\par
\pard\cf0\f2\fs16\par
}

This text comes from an RTF file, so it has this crazy formatting, already tried with LoadFromFile, but when it writes it appears a lot of ???? instead of the text

The command used is:

...
Arquivo := Stream.LoadFromFile('arquivo.rtf');
S := Arquivo.DataString;

Query := TQuery.Create(nil);
... 
Query.SQL.Add('update tabela set campotext = '+QuotedStr(S)+'');
Query.ExecSQL;

The error:

SQL Error: ERROR:  unterminated quoted string at or near "'{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 \fnilTahoma;}}

\viewkind4\uc1\pard\qj\lang1046\f0\fs16\zdv\cxcv\par

\pard\par

}

"
LINE 2: texto = '{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\...
                           ^

I tried to put some leaks but no chance

    
asked by anonymous 27.06.2018 / 23:32

1 answer

1

Part of this question I already answered here RitchEdit Delphi text mess up while writing to PostgreSQL database

On writing blobs using SQL statements do so:

procedure TForm1.Button1Click(Sender: TObject);
var
  q: TFDQuery;
  s: TMemoryStream;
begin
  s := TMemoryStream.Create;
  RichEdit1.Lines.SaveToStream(s);

  s.Seek(0, soFromBeginning);

  q := TFDQuery.Create(Self);
  q.Connection := FDConnection1;
  q.SQL.Text := 'update tabela set campobytea = :b where (id = 1)';
  q.ParamByName('b').LoadFromStream(s, ftBlob);
  q.ExecSQL;
end;

This code is for illustration purposes only. Consider using TRY EXCEPT and TRY FINALY in the production code.

    
30.06.2018 / 06:28