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

Firebird Discussion :

Extraire un champ BLOB vers un fichier sur le serveur


Sujet :

Firebird

  1. #1
    Membre régulier Avatar de ALEX77
    Profil pro
    Inscrit en
    Juillet 2002
    Messages
    138
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2002
    Messages : 138
    Points : 76
    Points
    76
    Par défaut Extraire un champ BLOB vers un fichier sur le serveur
    Bonjour

    J'ai une procédure stockée à laquelle je passe un champ BLOB en paramètre d'entrée.

    A l'intérieur de cette procédure je souhaiterais récupérer le contenu du BLOB pour le stocker dans un fichier sur le serveur.

    Comment puis-je faire cela ? J'ai pensé aux UDF mais je ne vois pas comment.

    Merci pour votre aide.


  2. #2
    Membre expert

    Homme Profil pro
    Consultant spécialité Firebird
    Inscrit en
    Mai 2002
    Messages
    2 342
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France

    Informations professionnelles :
    Activité : Consultant spécialité Firebird
    Secteur : Conseil

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 342
    Points : 3 715
    Points
    3 715
    Par défaut
    tout dépend du type du blob
    les blob de type texte sont maintenant manipulables comme des varchar
    Philippe Makowski
    IBPhoenix - Firebird
    Membre de l'April

  3. #3
    Membre régulier Avatar de ALEX77
    Profil pro
    Inscrit en
    Juillet 2002
    Messages
    138
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2002
    Messages : 138
    Points : 76
    Points
    76
    Par défaut
    C'est un BLOB binaire (images, fichiers Excel, word, etc...).

    Comment récupérer le contenu du BLOB et l'enregistrer dans un fichier sur le serveur ?

  4. #4
    Membre expert

    Homme Profil pro
    Consultant spécialité Firebird
    Inscrit en
    Mai 2002
    Messages
    2 342
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France

    Informations professionnelles :
    Activité : Consultant spécialité Firebird
    Secteur : Conseil

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 342
    Points : 3 715
    Points
    3 715
    Par défaut
    écrire une udf ou un petit programme pour cela
    Philippe Makowski
    IBPhoenix - Firebird
    Membre de l'April

  5. #5
    Membre régulier Avatar de ALEX77
    Profil pro
    Inscrit en
    Juillet 2002
    Messages
    138
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2002
    Messages : 138
    Points : 76
    Points
    76
    Par défaut
    Citation Envoyé par makowski Voir le message
    écrire une udf ou un petit programme pour cela
    D'accord mais comment ?

  6. #6
    Membre expert

    Homme Profil pro
    Consultant spécialité Firebird
    Inscrit en
    Mai 2002
    Messages
    2 342
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France

    Informations professionnelles :
    Activité : Consultant spécialité Firebird
    Secteur : Conseil

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 342
    Points : 3 715
    Points
    3 715
    Par défaut
    il y a plein d'udf avec les sources dont certaines qui traitent les blob
    et une petite recherche sur ton moteur préféré sera certainement efficace
    à commencer par celui intégré a ce site qui te renvoi entre autre ceci :
    http://esibert.developpez.com/firebird/udf-kylix/
    Philippe Makowski
    IBPhoenix - Firebird
    Membre de l'April

  7. #7
    Membre régulier Avatar de ALEX77
    Profil pro
    Inscrit en
    Juillet 2002
    Messages
    138
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2002
    Messages : 138
    Points : 76
    Points
    76
    Par défaut
    J'ai déjà trouvé comment passer des blob dans les UDF le problème est de récupérer le contenu binaire et de le sauvegarder dans un fichier.

    Voici le code source de mon unité :

    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
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
     
    library mon_udf;
     
    uses
      classes,
      Windows,
      ib_util;
     
    type
      Int                  = LongInt; // 32 bit signed
      UInt                 = DWord;   // 32 bit unsigned
      Long                 = LongInt; // 32 bit signed
      ULong                = DWord;   // 32 bit unsigned
      Short                = SmallInt;// 16 bit signed
      UShort               = Word;    // 16 bit unsigned
      Float                = Single;  // 32 bit
      UChar                = Byte;    // 8 bit unsigned
      ISC_LONG             = Long;    // 32 bit signed
      UISC_LONG            = ULong;   // 32 bit unsigned
      ISC_STATUS           = Long;    // 32 bit signed
      UISC_STATUS          = ULong;   // 32 bit unsigned
      Void                 = Pointer;
      // Delphi "Pointer types"
      PPChar               = ^PChar;
      PSmallInt            = ^SmallInt;
      PInt                 = ^Int;
      PInteger             = ^Integer;
      PShort               = ^Short;
      PUShort              = ^UShort;
      PLong                = ^Long;
      PULong               = ^ULong;
      PFloat               = ^Float;
      PUChar               = ^UChar;
      PVoid                = ^Pointer;
      PDouble              = ^Double;
      PISC_LONG            = ^ISC_LONG;
      PUISC_LONG           = ^UISC_LONG;
      PISC_STATUS          = ^ISC_STATUS;
      PPISC_STATUS         = ^PISC_STATUS;
      PUISC_STATUS         = ^UISC_STATUS;
     
      TISC_BlobGetSegment = function(BlobHandle: PInt;
                                     Buffer: PChar;
                                     BufferSize: Long;
                                     var ResultLength: Long): Short; cdecl;
      TISC_BlobPutSegment = procedure(BlobHandle: PInt;
                                      Buffer: PChar;
                                      BufferLength: Short); cdecl;
      TBlob = record
        GetSegment         : TISC_BlobGetSegment;
        BlobHandle         : PInt;
        SegmentCount       : Long;
        MaxSegmentLength   : Long;
        TotalSize          : Long;
        PutSegment         : TISC_BlobPutSegment;
      end;
      PBlob = ^TBlob;
     
    function ReadBlob(Blob : PBlob) : integer; cdecl;
    var bytes_read, bytes_left, total_bytes_read: Long;
        st : String;
     
        fs : TFileStream;
     
        l : TStrings;
     
    //    total_written : long;
     
    begin
     
     
     
     Result := 0;
     with Blob^ do
     begin
      SetString(st, nil, TotalSize);
      total_bytes_read := 0;                  // total bytes read is 0.
      bytes_left := TotalSize;                // I have TotalSize bytes to read.
      if (bytes_left > 0) then
      begin
       repeat
        // Using BlobHandle, store at most "bytes_left" bytes in
        //   the buffer starting where I last left off
        GetSegment(BlobHandle, @st[total_bytes_read + 1], bytes_left, bytes_read);
        // Increment total_bytes_read by the number of bytes actually read.
        Inc(total_bytes_read, bytes_read);
        // Decrement bytes_left by the number of bytes actually read.
        Dec(bytes_left, bytes_read);
       until bytes_left <= 0;
     
       fs:= TFileStream.Create('c:\fileblob.dat',fmCreate);
       fs.Size := Blob^.TotalSize;
       fs.Write(st,Blob^.TotalSize);
       fs.Free;
     
       l:= TStringList.Create;
       l.Text:= st;
       l.SaveToFile('c:\fileblob.txt');
       l.Free;
     
       Result := 1;
      end;
     end;
    end;
     
    exports
      ReadBlob;
     
    end.
    Dans ma déclaration UDF j'ai mis :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    DECLARE EXTERNAL FUNCTION FILEBLOB
    BLOB
    RETURNS INTEGER BY VALUE 
    ENTRY_POINT 'ReadBlob' MODULE_NAME 'mon_udf.dll';
    Pour tester ma fonction je lance une requête :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    select FILEBLOB(PHOTO) from ARTICLES
    where code = '0001'
    Ce qui normalement doit me créer un fichier contenant la photo (au format BMP) de mon article (c:\fileblob.dat).

    Pour l'instant avec le fichier .dat j'obtiens n'importe quoi et avec le fichier .txt j'obtiens le début du blob mais comme j'utilise un TStrings ça marche pas non plus.

    Donc si quelqu'un a une idée là-dessus...

  8. #8
    Expert éminent
    Avatar de qi130
    Homme Profil pro
    Expert Processus IT
    Inscrit en
    Mars 2003
    Messages
    3 911
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France

    Informations professionnelles :
    Activité : Expert Processus IT
    Secteur : Finance

    Informations forums :
    Inscription : Mars 2003
    Messages : 3 911
    Points : 6 032
    Points
    6 032
    Par défaut
    Puisque tu sembles coder en Delphi, je suggère la FAQ : http://delphi.developpez.com/faq/?pa...ichierdansblob
    "Il n'y a pas de bonnes réponses à une mauvaise question." (M. Godet)
    -----------------------
    Pensez à cloturer votre sujet - Aucune réponse aux sollicitations techniques par MP
    Usus magister est optimus

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

Discussions similaires

  1. Champ BLOB vers fichier XML
    Par pada62 dans le forum MS SQL Server
    Réponses: 11
    Dernier message: 27/04/2011, 16h08
  2. Extraire Un BLOB vers un fichier
    Par exempleinfo dans le forum SQL
    Réponses: 6
    Dernier message: 04/06/2008, 11h31
  3. Exporter le schemas vers un fichier sur le disque dur
    Par Bayoro dans le forum Administration
    Réponses: 1
    Dernier message: 10/10/2007, 14h51
  4. extraire un champ blob
    Par tipon dans le forum SQL
    Réponses: 1
    Dernier message: 06/08/2007, 10h42
  5. JSF - Lien vers un fichier sur le DD
    Par Loizo dans le forum JSF
    Réponses: 3
    Dernier message: 26/07/2007, 15h52

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