[fpc-pascal] EDatabaseError on SELECT

Michael Van Canneyt michael at freepascal.org
Wed Feb 10 16:58:22 CET 2016



On Wed, 10 Feb 2016, Felipe Monteiro de Carvalho wrote:

> Hello,
>
> Taking advantage that we are already talking about SQL .... how to
> upload the contents of a blob field?
>
> I tried using a SELECT to get the field +
> TBlobField(FQuery.FieldByName('Data')).LoadFromStream but it raises an
> exception that "Dataset is not in insert or edit mode"
>
> I see that I could write the data in hexadecimal in the SQL query, but
> that would be slow...
>
> So what is the proper way to use TBlobField.LoadFromStream?
>
> Or should I use params + an SQL statement with question mark:
>
> lSQL := Format('UPDATE %s SET ? WHERE ID=''%d''', [lTableName, AItemNr]);

Both ways are possible.

Qry.sql.text:='your select';
Qry.Open;
// Navigate to record you want to modify
Qry.Edit; // Go to edit mode.
TBlobField(FQuery.FieldByName('Data')).LoadFromStream(YourStream))
Qry.Post; // Save changes

Or

Qry.Sql.Text:='update tablename set (yourfield=:yourfield) where ID=something';
Qry.ParamByName('yourfield').LoadFromStream(YourStream)
Qry.ExecSQL;


Michael.



More information about the fpc-pascal mailing list