Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-08

How to clear the value of a field in a table using parameters?

16 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

Hello,

I'm trying to do something with a dataset, but I think that isn't possible.

Assuming I have the following table:

create table users (
id serial not null primary key,
email varchar(100),
nickname varchar(20) not null
);

And the following records:

id | email | nickname
1 | | user1
2 | | user2
3 | | user3

I want to clear the email of the second user, but using parameters:

id | email | nickname
1 | | user1
2 | <null> | user2
3 | | user3

But when I try this:

  SQLQuery1.SQL.Add('update users set email = :email');
  SQLQuery1.SQL.Add('where id = :id');
  SQLQuery1.ParamByName('id').AsInteger := 2;
  SQLQuery1.ParamByName('email').Clear;
  SQLQuery1.ExecSQL;
  SQLTransaction1.Commit;

I got:

"Project project1 raised exception class "EDatabaseError" with message: PQConnection1: Unknown fieldtype for parameter "email"."

I know that I could solve easily via literal string, but I need to use parameters anyway.

How I solve this?

Here in Brazil, a friend suggested this:

  VParam := SQLQuery1.ParamByName('email');
  VParam.DataType := ftString;
  VParam.Clear

Is this the only way? '-'

Thank you!

Silvio Clécio My public projects - github.com/silvioprog
Michael Van Canneyt
to silvioprog
silvioprog wrote 50 lines
Hello, I'm trying to do something with a dataset, but I think that isn't possible. Assuming I have the following table: create table users ( id serial not null primary key, email varchar(100), nickname varchar(20) not null ); And the following records: id | email | nickname 1 |  | user1 2 |  | user2 3 |  | user3 I want to clear the email of the second user, but using parameters: id | email | nickname 1 |  | user1 2 | <null> | user2 3 |  | user3 But when I try this:   SQLQuery1.SQL.Add('update users set email = :email');   SQLQuery1.SQL.Add('where id = :id');   SQLQuery1.ParamByName('id').AsInteger := 2;   SQLQuery1.ParamByName('email').Clear;   SQLQuery1.ExecSQL;   SQLTransaction1.Commit; I got: "Project project1 raised exception class "EDatabaseError" with message: PQConnection1: Unknown fieldtype for parameter "email"." I know that I could solve easily via literal string, but I need to use parameters anyway. How I solve this? Here in Brazil, a friend suggested this:   VParam := SQLQuery1.ParamByName('email');   VParam.DataType := ftString;   VParam.Clear Is this the only way? '-'

Yes and no.

In 2.6.2 this is the only way.

There is a fix in SVN that allows you to simply do clear, and it will use then the "any" field type of postgres (or something similar).

Michael.

silvioprog
to Michael Van Canneyt

2013/8/29 Michael Van Canneyt

Show quoted text 65 lines
On Thu, 29 Aug 2013, silvioprog wrote: Hello, > I'm trying to do something with a dataset, but I think that isn't > possible. > > Assuming I have the following table: > > create table users ( > id serial not null primary key, > email varchar(100), > nickname varchar(20) not null > ); > > And the following records: > > id | email | nickname > 1 | | user1 > 2 | | user2 > 3 | | user3 > > I want to clear the email of the second user, but using parameters: > > id | email | nickname > 1 | | user1 > 2 | <null> | user2 > 3 | | user3 > > But when I try this: > > SQLQuery1.SQL.Add('update users set email = :email'); > SQLQuery1.SQL.Add('where id = :id'); > SQLQuery1.ParamByName('id').**AsInteger := 2; > SQLQuery1.ParamByName('email')**.Clear; > SQLQuery1.ExecSQL; > SQLTransaction1.Commit; > > I got: > > "Project project1 raised exception class "EDatabaseError" with message: > PQConnection1: Unknown fieldtype for parameter "email"." > > I know that I could solve easily via literal string, but I need to use > parameters anyway. > > How I solve this? > > Here in Brazil, a friend suggested this: > > VParam := SQLQuery1.ParamByName('email')**; > VParam.DataType := ftString; > VParam.Clear > > Is this the only way? '-' > Yes and no. In 2.6.2 this is the only way. There is a fix in SVN that allows you to simply do clear, and it will use then the "any" field type of postgres (or something similar). Michael.

I'll try the trunk version. Thank you very much Michael! (y)

Silvio Clécio My public projects - github.com/silvioprog
silvioprog
to silvioprog

2013/8/29 silvioprog

Show quoted text 71 lines
2013/8/29 Michael Van Canneyt > On Thu, 29 Aug 2013, silvioprog wrote: > > Hello, >> I'm trying to do something with a dataset, but I think that isn't >> possible. >> >> Assuming I have the following table: >> >> create table users ( >> id serial not null primary key, >> email varchar(100), >> nickname varchar(20) not null >> ); >> >> And the following records: >> >> id | email | nickname >> 1 | | user1 >> 2 | | user2 >> 3 | | user3 >> >> I want to clear the email of the second user, but using parameters: >> >> id | email | nickname >> 1 | | user1 >> 2 | <null> | user2 >> 3 | | user3 >> >> But when I try this: >> >> SQLQuery1.SQL.Add('update users set email = :email'); >> SQLQuery1.SQL.Add('where id = :id'); >> SQLQuery1.ParamByName('id').**AsInteger := 2; >> SQLQuery1.ParamByName('email')**.Clear; >> SQLQuery1.ExecSQL; >> SQLTransaction1.Commit; >> >> I got: >> >> "Project project1 raised exception class "EDatabaseError" with message: >> PQConnection1: Unknown fieldtype for parameter "email"." >> >> I know that I could solve easily via literal string, but I need to use >> parameters anyway. >> >> How I solve this? >> >> Here in Brazil, a friend suggested this: >> >> VParam := SQLQuery1.ParamByName('email')**; >> VParam.DataType := ftString; >> VParam.Clear >> >> Is this the only way? '-' >> > > Yes and no. > > In 2.6.2 this is the only way. > > There is a fix in SVN that allows you to simply do clear, and it will use > then the "any" > field type of postgres (or something similar). > > Michael. I'll try the trunk version. Thank you very much Michael! (y)

Other interesting feature is the property EmptyAsNull:

http://docwiki.embarcadero.com/VCL/XE/en/IBCustomDataSet.TIBStringField.EmptyAsNull

It tests if field (ftString) is empty (f = ''), if yes, it set the field value to null (f.Clear).

Silvio Clécio My public projects - github.com/silvioprog
Sven Barth
to Michael Van Canneyt
"Michael Van Canneyt" wrote 9 lines
On Thu, 29 Aug 2013, silvioprog wrote: > > Other interesting feature is the property EmptyAsNull: > >

http://docwiki.embarcadero.com/VCL/XE/en/IBCustomDataSet.TIBStringField.EmptyAsNull

> > It tests if field (ftString) is empty (f = ''), if yes, it set the field

value to null (f.Clear).

Show quoted text 5 lines
Apparently a IBX specific extension. I don't see the value of this. empty and null are different things.

Not everywhere. In Oracle empty strings are Null (which is why we have special code for this situation in our business application).

Regards,
Sven

Reinier Olislagers
to Sven Barth
Sven Barth wrote 9 lines
Am 29.08.2013 23:04 schrieb "Michael Van Canneyt" < >: > On Thu, 29 Aug 2013, silvioprog wrote: >> Other interesting feature is the property EmptyAsNull: http://docwiki.embarcadero.com/VCL/XE/en/IBCustomDataSet.TIBStringField.EmptyAsNull >> It tests if field (ftString) is empty (f = ''), if yes, it set the field value to null (f.Clear). > I don't see the value of this. empty and null are different things.

Neither do I.

Not everywhere. In Oracle empty strings are Null

Yes, apparently Oracle breaks the SQL standard here.

If you want functionality like this why not specify your column DEFAULT NULL and just not insert data into that column (yes, you'd still have to UPDATE to NULL sometimes, but IMO it shows much more clearly you're explicitly saying "the value of this field is unknown").

I suppose it also boils to how much one has been indoctrinated by relational database theory :)

Michael Van Canneyt
to Sven Barth: http://docwiki.embarcadero.com/VCL/XE/en/IBCustomDataSet.TIBStringField.EmptyAsNull value…
Sven Barth wrote 21 lines
Am 29.08.2013 23:04 schrieb "Michael Van Canneyt" : > > > > On Thu, 29 Aug 2013, silvioprog wrote: > >> >> Other interesting feature is the property EmptyAsNull: >> >> http://docwiki.embarcadero.com/VCL/XE/en/IBCustomDataSet.TIBStringField.EmptyAsNull >> >> It tests if field (ftString) is empty (f = ''), if yes, it set the field value to null (f.Clear). > > > Apparently a IBX specific extension. > > I don't see the value of this. empty and null are different things. Not everywhere. In Oracle empty strings are Null (which is why we have special code for this situation in our business application).

That's a deviation from the standard. NULL means "we don't know", empty means "we know it is empty"

Michael.

Mark Morgan Lloyd
to Michael Van Canneyt
Michael Van Canneyt wrote 6 lines
> Not everywhere. In Oracle empty strings are Null (which is why we have > special code for this situation in our business > application). That's a deviation from the standard. NULL means "we don't know", empty means "we know it is empty"

Actually, it means "we don't know and won't be told" since null or true -> null and so on.

A bit like some political movements, frankly :-)

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
silvioprog
to Michael Van Canneyt: Apparently a IBX specific extension. I don't see the value of this. empty and null are…

2013/8/29 Michael Van Canneyt

Show quoted text 17 lines
On Thu, 29 Aug 2013, silvioprog wrote: > Other interesting feature is the property EmptyAsNull: > > http://docwiki.embarcadero.**com/VCL/XE/en/IBCustomDataSet.** > TIBStringField.EmptyAsNull<http://docwiki.embarcadero.com/VCL/XE/en/IBCustomDataSet.TIBStringField.EmptyAsNull> > > It tests if field (ftString) is empty (f = ''), if yes, it set the field > value to null (f.Clear). > Apparently a IBX specific extension. I don't see the value of this. empty and null are different things. Michael.

Some Delphi components (Zeos, JvDBEdit) have this option.

Assuming this table:

test
id integer,
name varchar(10) not null unique

You can:

id|name
1| <null>
2| <null>

But:

1| <empty>
2| <empty> << error, unique key

I implemented "EmptyAsNull" directly in my project. It is very useful. In my webpages, if the user clear a input, I send a null value to the table.

Silvio Clécio My public projects - github.com/silvioprog
Stefan Fischer
to silvioprog

Hi,

a longer time ago, i've installed lazarus on my raspberry pi with wheezy. The fpc version was 2.6.0-xxx

I could compile without any problem.

Today I've downloaded fpc 2.6.2 and installed it.

But now I have problems with the linker:

Free Pascal Compiler version 2.6.2 [2013/02/15] for arm

Copyright (c) 1993-2012 by Florian Klaempfl and others

Target OS: Linux for ARMEL

Compiling rfm.pas

Assembling rfm

Linking rfm

/usr/bin/ld: warning: link.res contains output sections; did you forget -T?

/usr/lib/fpc/2.6.2/units/arm-linux/rtl/cprt0.o: In function `_haltproc_eabi':

(.text+0x88): undefined reference to `_fini'

/usr/lib/fpc/2.6.2/units/arm-linux/rtl/cprt0.o: In function `_haltproc_eabi':

(.text+0x90): undefined reference to `_init'

rfm.pas(136,4) Error: Error while linking
rfm.pas(136,4) Fatal: There were 1 errors compiling module, stopping

Fatal: Compilation aborted

Error: /usr/bin/ppcarm returned an error exitcode (normal if you did not specify a source file to be compiled)

Michael Van Canneyt
to silvioprog: 2013/8/29 Michael Van Canneyt Some Delphi components (Zeos, JvDBEdit) have this option.…
silvioprog wrote 39 lines
2013/8/29 Michael Van Canneyt On Thu, 29 Aug 2013, silvioprog wrote: Other interesting feature is the property EmptyAsNull: http://docwiki.embarcadero.com/VCL/XE/en/IBCustomDataSet.TIBStringField.EmptyAsNull It tests if field (ftString) is empty (f = ''), if yes, it set the field value to null (f.Clear). Apparently a IBX specific extension. I don't see the value of this. empty and null are different things. Michael. Some Delphi components (Zeos, JvDBEdit) have this option. Assuming this table: test   id integer,   name varchar(10) not null unique You can: id|name 1| <null> 2| <null> But: 1| <empty> 2| <empty> << error, unique key I implemented "EmptyAsNull" directly in my project. It is very useful. In my webpages, if the user clear a input, I send a null value to the table.

Good for you :)

Michael.

silvioprog
to Michael Van Canneyt

2013/8/30 Michael Van Canneyt

Show quoted text 49 lines
On Fri, 30 Aug 2013, silvioprog wrote: 2013/8/29 Michael Van Canneyt > On Thu, 29 Aug 2013, silvioprog wrote: > > > Other interesting feature is the property EmptyAsNull: > > http://docwiki.embarcadero.**com/VCL/XE/en/IBCustomDataSet.** > TIBStringField.EmptyAsNull<http://docwiki.embarcadero.com/VCL/XE/en/IBCustomDataSet.TIBStringField.EmptyAsNull> > > It tests if field (ftString) is empty (f = ''), if yes, it > set the field value to null (f.Clear). > > > Apparently a IBX specific extension. > > I don't see the value of this. empty and null are different things. > > Michael. > > > Some Delphi components (Zeos, JvDBEdit) have this option. > > Assuming this table: > > test > id integer, > name varchar(10) not null unique > > You can: > > id|name > 1| <null> > 2| <null> > > But: > > 1| <empty> > 2| <empty> << error, unique key > > I implemented "EmptyAsNull" directly in my project. It is very useful. In > my webpages, if the user clear a input, I send a > null value to the table. > Good for you :) Michael.

hehe... :D

Silvio Clécio My public projects - github.com/silvioprog
Henry Vermaak
to Stefan Fischer: a longer time ago, i've installed lazarus on my raspberry pi with wheezy. The fpc version…
Stefan Fischer wrote 24 lines
Hi, a longer time ago, i've installed lazarus on my raspberry pi with wheezy. The fpc version was 2.6.0-xxx I could compile without any problem. Today I've downloaded fpc 2.6.2 and installed it. But now I have problems with the linker: Free Pascal Compiler version 2.6.2 [2013/02/15] for arm Copyright (c) 1993-2012 by Florian Klaempfl and others Target OS: Linux for ARMEL Compiling rfm.pas Assembling rfm Linking rfm /usr/bin/ld: warning: link.res contains output sections; did you forget -T? /usr/lib/fpc/2.6.2/units/arm-linux/rtl/cprt0.o: In function `_haltproc_eabi': (.text+0x88): undefined reference to `_fini' /usr/lib/fpc/2.6.2/units/arm-linux/rtl/cprt0.o: In function `_haltproc_eabi': (.text+0x90): undefined reference to `_init'

This sounds like it may be a multiarch thing biting you. Those symbols are in crti.o, and perhaps fpc isn't finding it. I vaguely remember getting a problem like this and fixing it by adding -Fl/usr/lib/<arch-triplet>. You can use `locate` to check where it is.

Henry

Sven Barth
to silvioprog: 2013/8/29 Michael Van Canneyt Some Delphi components (Zeos, JvDBEdit) have this option.…
silvioprog wrote 40 lines
2013/8/29 Michael Van Canneyt < > On Thu, 29 Aug 2013, silvioprog wrote: Other interesting feature is the property EmptyAsNull: http://docwiki.embarcadero.__com/VCL/XE/en/IBCustomDataSet.__TIBStringField.EmptyAsNull <http://docwiki.embarcadero.com/VCL/XE/en/IBCustomDataSet.TIBStringField.EmptyAsNull> It tests if field (ftString) is empty (f = ''), if yes, it set the field value to null (f.Clear). Apparently a IBX specific extension. I don't see the value of this. empty and null are different things. Michael. Some Delphi components (Zeos, JvDBEdit) have this option. Assuming this table: test id integer, name varchar(10) not null unique You can: id|name 1| <null> 2| <null> But: 1| <empty> 2| <empty> << error, unique key

And again here is an exception of the rule: in SQL Server you can't have multiple NULL values in a unique key column *sigh*

Regards,
Sven

Fischer Stefan
to Henry Vermaak: This sounds like it may be a multiarch thing biting you. Those symbols are in crti.o,…

Hi,

I've compiled a program on a raspberry pi with Linux rpi2 3.6.11+ #538 PREEMPT Fri Aug 30 20:42:08 BST 2013 armv6l GNU/Linux on one raspberry pi, run it and it works.

I copied the binary program to another raspberry pi with the same kernel revision and I've got a segmentation fault.

What to do if I I want to compile the sources only on one machine, without copying the sources to any other machine ?

Thanks,
Stefan

Henry Vermaak wrote 35 lines
On Fri, Aug 30, 2013 at 03:44:35PM +0200, Stefan Fischer wrote: > Hi, > a longer time ago, i've installed lazarus on my raspberry pi with > wheezy. The fpc version was 2.6.0-xxx > > I could compile without any problem. > > Today I've downloaded fpc 2.6.2 and installed it. > > But now I have problems with the linker: > > Free Pascal Compiler version 2.6.2 [2013/02/15] for arm > Copyright (c) 1993-2012 by Florian Klaempfl and others > Target OS: Linux for ARMEL > Compiling rfm.pas > Assembling rfm > Linking rfm > /usr/bin/ld: warning: link.res contains output sections; did you forget > -T? > /usr/lib/fpc/2.6.2/units/arm-linux/rtl/cprt0.o: In function > `_haltproc_eabi': > (.text+0x88): undefined reference to `_fini' > /usr/lib/fpc/2.6.2/units/arm-linux/rtl/cprt0.o: In function > `_haltproc_eabi': > (.text+0x90): undefined reference to `_init' This sounds like it may be a multiarch thing biting you. Those symbols are in crti.o, and perhaps fpc isn't finding it. I vaguely remember getting a problem like this and fixing it by adding -Fl/usr/lib/<arch-triplet>. You can use `locate` to check where it is. Henry _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Mit freundlichen Gruessen,

Stefan Fischer
BASIS GmbH