<div dir="ltr">2013/8/29 silvioprog <span dir="ltr"><<a href="mailto:silvioprog@gmail.com" target="_blank">silvioprog@gmail.com</a>></span><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div dir="ltr"><div><div class="h5">2013/8/29 Michael Van Canneyt <span dir="ltr"><<a href="mailto:michael@freepascal.org" target="_blank">michael@freepascal.org</a>></span></div></div><div class="gmail_extra"><div>

<div class="h5"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div>
On Thu, 29 Aug 2013, silvioprog wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Hello,<br>
I'm trying to do something with a dataset, but I think that isn't possible.<br>
<br>
Assuming I have the following table:<br>
<br>
create table users (<br>
id serial not null primary key,<br>
email varchar(100),<br>
nickname varchar(20) not null<br>
);<br>
<br>
And the following records:<br>
<br>
id | email | nickname<br>
1 | <a href="mailto:user1@domain.com" target="_blank">user1@domain.com</a> | user1<br>
2 | <a href="mailto:user2@domain.com" target="_blank">user2@domain.com</a> | user2<br>
3 | <a href="mailto:user3@domain.com" target="_blank">user3@domain.com</a> | user3<br>
<br>
I want to clear the email of the second user, but using parameters:<br>
<br>
id | email | nickname<br>
1 | <a href="mailto:user1@domain.com" target="_blank">user1@domain.com</a> | user1<br>
2 | <null> | user2<br>
3 | <a href="mailto:user3@domain.com" target="_blank">user3@domain.com</a> | user3<br>
<br>
But when I try this:<br>
<br>
  SQLQuery1.SQL.Add('update users set email = :email');<br>
  SQLQuery1.SQL.Add('where id = :id');<br>
  SQLQuery1.ParamByName('id').<u></u>AsInteger := 2;<br>
  SQLQuery1.ParamByName('email')<u></u>.Clear;<br>
  SQLQuery1.ExecSQL;<br>
  SQLTransaction1.Commit;<br>
<br>
I got:<br>
<br>
"Project project1 raised exception class "EDatabaseError" with message:<br>
PQConnection1: Unknown fieldtype for parameter "email"."<br>
<br>
I know that I could solve easily via literal string, but I need to use parameters anyway.<br>
<br>
How I solve this?<br>
<br>
Here in Brazil, a friend suggested this:<br>
<br>
  VParam := SQLQuery1.ParamByName('email')<u></u>;<br>
  VParam.DataType := ftString;<br>
  VParam.Clear<br>
<br>
Is this the only way? '-'<br>
</blockquote>
<br></div></div>
Yes and no.<br>
<br>
In 2.6.2 this is the only way.<br>
<br>
There is a fix in SVN that allows you to simply do clear, and it will use then the "any"<br>
field type of postgres (or something similar).<span><font color="#888888"><br>
<br>
Michael.</font></span></blockquote></div><div><br></div></div></div><div>I'll try the trunk version. Thank you very much Michael! (y)</div></div></div></blockquote></div><div class="gmail_extra"><br></div><div class="gmail_extra">

<div class="gmail_extra">Other interesting feature is the property EmptyAsNull:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><a href="http://docwiki.embarcadero.com/VCL/XE/en/IBCustomDataSet.TIBStringField.EmptyAsNull">http://docwiki.embarcadero.com/VCL/XE/en/IBCustomDataSet.TIBStringField.EmptyAsNull</a></div>

<div class="gmail_extra"><br></div><div class="gmail_extra">It tests if field (ftString) is empty (f = ''), if yes, it set the field value to null (f.Clear).</div></div><div class="gmail_extra"><br></div>-- <br>Silvio Clécio<br>

My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a>
</div></div>