How to insert NULL with TMyScript?

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
starhu
Posts: 34
Joined: Thu 13 Aug 2009 12:13

How to insert NULL with TMyScript?

Post by starhu » Wed 24 Mar 2010 11:39

Hello,

I use TMyScript to insert data from an Excel table.

With MyScript Do
begin

Sql.Clear;

Sql.Add('insert into mytable');
Sql.Add('(');
Sql.Add('field1,field2');

Sql.Add(')'); // tagok_ezevben_fizetett_osszes_tagdij tagok_hatralek

Sql.Add('values');

Sql.Add('(');
Sql.Add('&field1,&field2');


Sql.Add(')');

Sql.Add('ON DUPLICATE KEY UPDATE ');

Sql.Add('field2=&field2');


end; // With AdatForm.MyScript Do

Then later in a for loop (processing every Excel

MyScript.MacroByName('field2').AsString := SomeValue;



The problem is that "field2" is a Date field in MySql, and sometimes it is not filled in the Excel table, so obviously I got an error: "Incorrect date value".

I though if SomeValue='' then I would use
MyScript.MacroByName('field2').AsString := 'NULL', but this doesn't work, because TMyScript passes this as a string: 'NULL'.

So the question is : how can I insert NULL with TMyScript?

Thank you in advance.

eduardosic
Posts: 387
Joined: Fri 18 Nov 2005 00:26
Location: Brazil

Re: How to insert NULL with TMyScript?

Post by eduardosic » Wed 24 Mar 2010 13:19

starhu wrote:Hello,

I use TMyScript to insert data from an Excel table.

With MyScript Do
begin

Sql.Clear;

Sql.Add('insert into mytable');
Sql.Add('(');
Sql.Add('field1,field2');

Sql.Add(')'); // tagok_ezevben_fizetett_osszes_tagdij tagok_hatralek

Sql.Add('values');

Sql.Add('(');
Sql.Add('&field1,&field2');


Sql.Add(')');

Sql.Add('ON DUPLICATE KEY UPDATE ');

Sql.Add('field2=&field2');


end; // With AdatForm.MyScript Do

Then later in a for loop (processing every Excel

MyScript.MacroByName('field2').AsString := SomeValue;



The problem is that "field2" is a Date field in MySql, and sometimes it is not filled in the Excel table, so obviously I got an error: "Incorrect date value".

I though if SomeValue='' then I would use
MyScript.MacroByName('field2').AsString := 'NULL', but this doesn't work, because TMyScript passes this as a string: 'NULL'.

So the question is : how can I insert NULL with TMyScript?

Thank you in advance.
try this,,

MyScript.MacroByName('field2').VALUE := 'NULL';

MacroByName works with Value.

starhu
Posts: 34
Joined: Thu 13 Aug 2009 12:13

Post by starhu » Wed 24 Mar 2010 13:54

Thank you very much!

It worked!

Post Reply