Board index » delphi » Initialising Integer Values with zero instead of null in trigger

Initialising Integer Values with zero instead of null in trigger


2006-05-31 08:45:59 AM
delphi17
Hi
I would like to create a common SP or UDF which I can call after insert to
initialise all integer values to zero instead of null.
Any examples or help would be greatly appreciated.
Kind regards
Craig
 
 

Re:Initialising Integer Values with zero instead of null in trigger

Craig Cookesley writes:
Quote

I would like to create a common SP or UDF which I can call after
insert to initialise all integer values to zero instead of null.

Any examples or help would be greatly appreciated.
Change the definition of your tables to include both a not null and default
value, e.g.
create table xxx (
somefield integer default 0 not null,
{...}
)
As far as I know there is no way to write a universal SP (or UDF) that can
do this for any arbitrary table because field names cannot be treated as
parameters in an SQL statement.
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: www.logicfundamentals.com/RADBooks.html
"The moment the idea is admitted into society that property is not as
sacred as the laws of God and there is not a force of law and public
justice to protect it, anarchy and tyranny commence." - John Adams
 

Re:Initialising Integer Values with zero instead of null in trigger

Thanks Wayne
I found that I can setup a domain with a default value of zero and set the
fields to the domain
Craig
"Craig Cookesley" <XXXX@XXXXX.COM>writes
Quote
Hi

I would like to create a common SP or UDF which I can call after insert to
initialise all integer values to zero instead of null.

Any examples or help would be greatly appreciated.

Kind regards

Craig

 

Re:Initialising Integer Values with zero instead of null in trigger

Quote

I found that I can setup a domain with a default value of zero and set the
fields to the domain
Mind you, a DEFAULT is only used when you don't supply that column
in the INSERT INTO statement. If you would be inserting NULL, for
example, NULL will be inserted (or attempted to insert on "required"
columns).
--
Martijn Tonies
Database Workbench - development tool for InterBase and more!
Upscene Productions
www.upscene.com
My thoughts:
blog.upscene.com/martijn/
Database development questions? Check the forum!
www.databasedevelopmentforum.com
 

Re:Initialising Integer Values with zero instead of null in trigger

Martijn Tonies writes:
Quote
>
>I found that I can setup a domain with a default value of zero and
>set the fields to the domain

Mind you, a DEFAULT is only used when you don't supply that column
in the INSERT INTO statement. If you would be inserting NULL, for
example, NULL will be inserted (or attempted to insert on "required"
columns).
Of course, if the columns are included in the INSERT statement with no
value provided you can still set the value to zero in a before insert
trigger.
--
Bill Todd (TeamB)
 

Re:Initialising Integer Values with zero instead of null in trigger

thankyou, you saved me some value time
Craig
"Martijn Tonies" <XXXX@XXXXX.COM>writes
Quote
>
>I found that I can setup a domain with a default value of zero and set
>the
>fields to the domain

Mind you, a DEFAULT is only used when you don't supply that column
in the INSERT INTO statement. If you would be inserting NULL, for
example, NULL will be inserted (or attempted to insert on "required"
columns).


--
Martijn Tonies
Database Workbench - development tool for InterBase and more!
Upscene Productions
www.upscene.com
My thoughts:
blog.upscene.com/martijn/
Database development questions? Check the forum!
www.databasedevelopmentforum.com