Recent

Author Topic: [SOLVED] HOW TO CHECK A FIREBIRD VARCHAR() FIELD IS EMPTY ?  (Read 5239 times)

finalist

  • Jr. Member
  • **
  • Posts: 84
[SOLVED] HOW TO CHECK A FIREBIRD VARCHAR() FIELD IS EMPTY ?
« on: January 07, 2016, 03:20:53 pm »
FOR FIREBIRD TRIGGER
IS THIS CORRECT:
Code: Pascal  [Select]
  1. IF FIELDofVARCHAR = ´´ THEN
  2. BEGIN
  3. /* .......*/
  4. END
OR THIS IS CORRECT:
Code: Pascal  [Select]
  1. IF FIELDofVARCHAR is NULL THEN
  2. BEGIN
  3. /* .......*/
  4. END
« Last Edit: January 07, 2016, 04:52:46 pm by finalist »

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: HOW TO CHECK A FIREBIRD VARCHAR() FIELD IS EMPTY ?
« Reply #1 on: January 07, 2016, 03:48:15 pm »
FOR FIREBIRD TRIGGER
IS THIS CORRECT:
Code: Pascal  [Select]
  1. IF FIELDofVARCHAR = ´´ THEN
  2. BEGIN
  3. /* .......*/
  4. ENS
OR THIS IS CORRECT:
Code: Pascal  [Select]
  1. IF FIELDofVARCHAR is NULL THEN
  2. BEGIN
  3. /* .......*/
  4. ENS
Both are correct and possible. In a new record with the field set to allow nulls and no value inserted yet the value will always be null. nothing is stopping you from passing and empty string to the varchar to empty it and not being null at the same time though. So which trigger are you talking about and how is this field defined/created?
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Zoran

  • Hero Member
  • *****
  • Posts: 1457
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: HOW TO CHECK A FIREBIRD VARCHAR() FIELD IS EMPTY ?
« Reply #2 on: January 07, 2016, 03:48:53 pm »
Depending on what you actually want, they are both correct in PSQL (when you put the condition in parenthesis and change the last line from ENS to END).

It is important that in Firebird (and, as far as I know, in all other RDBMS-s except Oracle), empty string ('') and null value are two different things.
So... it really depends on what you actually want... To better understand null, read Firebird Null Guide

If you want to catch both nulls and empty strings, then do this:
Code: SQL  [Select]
  1. IF (FieldOfVarchar IS NULL OR FieldOfVarchar = '') THEN
  2.