Cette fonction traduit une adresse IPV4 en LongIP dans FirebirdSQL 3.

 

   1:  CREATE Function fnIPTOLONGIP(IP VARCHAR(15))
   2:  returns NUMERIC(11, 0)
   3:  as
   4:  declare function localIPTOLONG( LIP VARCHAR(15),  BLOCK1 SMALLINT,
   5:    BLOCK2 SMALLINT,
   6:    BLOCK3 SMALLINT,
   7:    BLOCK4 SMALLINT,
   8:    PAR1 VARCHAR(8),
   9:    PAR2 VARCHAR(8),
  10:    pos1 INTEGER)
  11:  returns NUMERIC(11)
  12:  AS
  13:  begin
  14:  pos1 = position('.',LIP,position('.',LIP)+1);
  15:   
  16:  par1 = substring(LIP from 1 for pos1-1);
  17:  par2 = substring(LIP from pos1+1 for 15);
  18:   
  19:  block1 = substring(par1 from 1 for position('.',par1));
  20:  block2 = substring(par1 from position('.',par1)+1 for 8);
  21:  block3 = substring(par2 from 1 for position('.',par2));
  22:  block4 = substring(par2 from position('.',par2)+1 for 8);
  23:   
  24:  return  bin_shl(block1,24)+bin_shl(block2,16)+bin_shl(block3,8)+block4;
  25:   
  26:   
  27:  end
  28:   begin
  29:   
  30:   return  localIPTOLONG(IP,0,0,0,0,'','',0);
  31:   
  32:   end;
View User Profile for Norbert Saint Georges
Envoié par Norbert Saint Georges dimanche 2 février 2014 15:08:32 Categories: FirebirdSQL
Tetrasys Oy
Évaluer ce contenu Voix 0

Commentaires

Les commentaires sont fermés pour ce message.