Problem writing field using alias (MSQuery)

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
danilo.abranches
Posts: 8
Joined: Mon 08 Sep 2014 16:39

Problem writing field using alias (MSQuery)

Post by danilo.abranches » Mon 06 Oct 2014 19:05

Hello,

When i put a query in Msquery with a field using alias, it is not written.

Example:

Code: Select all

select upper(field) as field from table
Delphi:

Code: Select all

msQuery.Open;
msQuery.First;
msQuery.Edit;
msQuerycampo.AsString := 'test';
msQuery.Post;
Is that a problem? Know any solution?

Note: I'm replacing the use of TClientDataset by TMsquery

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Problem writing field using alias (MSQuery)

Post by azyk » Tue 14 Oct 2014 13:21

To generate an UPDATE SQL query, we use meta-information about a database object, that each field belongs to. For your SQL query, SQL Server doesn't return the name of the table containing the field. Therefore we don't use this field when auto-generating SQL queries in this case.

To solve the problem, you should manually generate an UPDATE SQL query for the TMSQuery.SQLUpdate.Text property. For example:

Code: Select all

  msQuery.SQLUpdate.Text :=
  ' UPDATE mytable1 ' +
  ' SET ' +
  '   MyField = :field ' +
  ' WHERE ' +
  '   id = :id ';

danilo.abranches
Posts: 8
Joined: Mon 08 Sep 2014 16:39

Re: Problem writing field using alias (MSQuery)

Post by danilo.abranches » Tue 14 Oct 2014 13:30

Thank you, i will do so.

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Problem writing field using alias (MSQuery)

Post by azyk » Thu 16 Oct 2014 07:23

Feel free to contact us if you have any further questions.

Post Reply