IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Requêtes PostgreSQL Discussion :

Evaluation d'une chaine en booléen [9.2]


Sujet :

Requêtes PostgreSQL

  1. #1
    Membre expert
    Avatar de alassanediakite
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2006
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Mali

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Août 2006
    Messages : 1 599
    Points : 3 591
    Points
    3 591
    Billets dans le blog
    8
    Par défaut Evaluation d'une chaine en booléen
    Salut
    Je cherche à évaluer en booléen une expression stockée en chaine (ex: '3<4').
    Si vous avez des solutions?
    Merci d'avance.

  2. #2
    Membre expert
    Avatar de alassanediakite
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2006
    Messages
    1 599
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Mali

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Août 2006
    Messages : 1 599
    Points : 3 591
    Points
    3 591
    Billets dans le blog
    8
    Par défaut
    Salut
    En attendant mieux, j'ai créé une fonction en plpgsql
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
     
    CREATE OR REPLACE FUNCTION verifier(strentry text)
      RETURNS boolean AS
    $BODY$
    declare
    strtemp text;
    i integer;
    gauche text;
    droite text;
    begin
    strtemp=btrim(strentry);
    If strtemp = '' Then
    return false;
    End If;
    if position('AND' in upper(strtemp))>0 then
    return verifier(btrim(left(strtemp,position('AND' in upper(strtemp))-1))) and verifier(btrim(right(strtemp,char_length(strtemp) - position('AND' in upper(strtemp))-3)));
    elsif position('OR' in upper(strtemp))>0 then
    return verifier(btrim(left(strtemp,position('OR' in upper(strtemp))-1))) OR verifier(btrim(right(strtemp,char_length(strtemp) - position('OR' in upper(strtemp))-2)));
    ELSE
    	i=1;
            While i < char_length(strtemp) loop
    		If position('<>' in strtemp) > 0 Then
    			gauche= left(strtemp,position('<>' in strtemp)-1);
    			droite= right(strtemp,char_length(strtemp)- position('<>' in strtemp)-1);
    			return (gauche::numeric <> droite::numeric)::boolean; 
    			exit;
    		ElsIf position('<=' in strtemp) > 0 Then
    			gauche= left(strtemp,position('<=' in strtemp)-1);
    			droite= right(strtemp,char_length(strtemp)- position('<=' in strtemp)-1);
    			return (gauche::numeric <= droite::numeric)::boolean;
    			exit;
    		elsIf position('>=' in strtemp) > 0 Then
    			gauche= left(strtemp,position('>=' in strtemp)-1);
    			droite= right(strtemp,char_length(strtemp)-  position('>=' in strtemp)-1);
    			return (gauche::numeric >= droite::numeric)::boolean;
    			exit;
    		elsIf position('>' in strtemp) > 0 Then
    			gauche= left(strtemp,position('>' in strtemp)-1);
    			droite= right(strtemp,char_length(strtemp)- position('>' in strtemp));
    			return (gauche::numeric > droite::numeric)::boolean;
    			exit;
    		elsIf position('<' in strtemp) > 0 Then
    			gauche= left(strtemp,position('<' in strtemp)-1);
    			droite= right(strtemp,char_length(strtemp)- position('<' in strtemp));
    			return (gauche::numeric < droite::numeric)::boolean;
    			exit;
    		elsIf position('=' in strtemp) > 0 Then
    			gauche= left(strtemp,position('=' in strtemp)-1);
    			droite= right(strtemp,char_length(strtemp)- position('=' in strtemp));
    			return (gauche::numeric = droite::numeric)::boolean;
    			exit;
    		else
    		i=i+1;
    		End If;
            end Loop;
    END IF;
    end
    $BODY$
      LANGUAGE plpgsql IMMUTABLE

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Evaluation d'une chaine de caractere
    Par kiwikiwi1 dans le forum Général Java
    Réponses: 2
    Dernier message: 18/04/2008, 10h46
  2. Evaluer la valeur d'une chaine (ex: 47+24*3)
    Par DJ Caësar 9114 dans le forum C
    Réponses: 4
    Dernier message: 24/05/2007, 12h12
  3. evaluation d'une chaine de caracteres
    Par nath8050 dans le forum Langage
    Réponses: 1
    Dernier message: 26/04/2007, 14h49
  4. evaluer une chaine
    Par mereyj dans le forum Général JavaScript
    Réponses: 7
    Dernier message: 11/12/2005, 15h11
  5. evaluation d'une chaine de caractere (2+3)*4/5%8
    Par ricardvince dans le forum Algorithmes et structures de données
    Réponses: 24
    Dernier message: 23/11/2005, 17h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo