Page 1 of 1

Issue when posting this SQL Statement (assign TStringList.Text to a field)

Posted: Mon 30 Jan 2006 17:37
by swierzbicki
Hi Ikar,

I'm having an issue when opening a TMYquery having this SQL Statement :

I'm storing some preferences into a mediumTExt field (Proprietes field).
It contains datas structured like this :
DernierCodeTournee=0000

Code: Select all

  //Query is automatically created then freed
MyTmpQuery:=TMyQuery.create(nil);
MyTmpQuery.Connection:= fmdatamodule.MyConnection;
try
  fmdatamodule.MyConnection.StartTransaction;
  try
   MyTmpQuery.close;
   MyTmpQuery.text:=
   'Select Proprietes From Preferences where Section = "SIA_Parametres" FOR UPDATE'
   MyTmpQuery.open;
   AValue.Text := MyTmpQuery.fieldbyname('Proprietes').AsString;
   AValue.ValueFromIndex[Prorietes.IndexOfName('DernierCodeTournee')]:= '0001';
   
   MyTmpQuery.edit;
   MyTmpQuery.fieldbyname('Proprietes').AsString := Trim(AValue.text) ;
   MyTmpQuery.post; 

UPDATE Preferences
SET
  Proprietes = :1
WHERE
instead of

Code: Select all

UPDATE Preferences
SET
  Proprietes = 'DernierCodeTournee=0001'
WHERE Section = 'SIA_Parametres'
Here is the Mysql SQL Script to generate the Table :

Code: Select all

CREATE TABLE `preferences` (
  `Section` VARCHAR(25) COLLATE latin1_swedish_ci NOT NULL,
  `Proprietes` MEDIUMTEXT,
  `Descriptif` MEDIUMTEXT,
  PRIMARY KEY (`Section`))TYPE=InnoDB;

COMMIT;

INSERT INTO `preferences` (`Section`, `Proprietes`, `Descriptif`) VALUES 
  ('SIA_Parametres','DernierCodeTournee=0000',NULL);

INSERT INTO `preferences` (`Section`, `Proprietes`, `Descriptif`) VALUES 
  ('VERSION_Parametres','Version=0.3.0.0\r\nMiseAJour=SIAFCI_0.3.0.0.exe\r\nDate=23/01/2004',NULL);

COMMIT;
MySQL server version: 4.1.14-nt
MySQL client version: Direct
Borland BDS 2006 Update 1
MyDAC 4.30.0.10

Any idea ?

Posted: Mon 30 Jan 2006 21:52
by GEswin
Perhaps it's a fault when pasting example, but I noticed:

Code: Select all

MyTmpQuery.text:=
   'Select Proprietes From Preferences where Section = "SIA_Parametres" FOR UPDATE'
   MyTmpQuery.open;
   AValue.Text := MyTmpQuery.fieldbyname('Settings').AsString; 
On third line you refer to field "Settings" that isn't selected in first line.

Posted: Tue 31 Jan 2006 08:03
by swierzbicki
Hi Geswin,

Yes, this was a tipo in my example. I will edit my post and correct it.
The problem still exists

Posted: Wed 01 Feb 2006 07:35
by swierzbicki
Any Feedback from Crlab support ?

Posted: Fri 03 Feb 2006 10:32
by swierzbicki
:?: :?: :?:

Posted: Fri 03 Feb 2006 15:46
by Ikar
SQL generator tries to generate UPDATE query using fields that appear in the SELECT clause of SQL statement. If you want to update BLOB fields correctly, you should request key field(s) from the table in you SELECT statement.

Posted: Mon 06 Feb 2006 10:41
by swierzbicki
It is working when adding the Key fieldname.
thank you