Précédent   Forum des professionnels en informatique > Bases de données > Firebird
Firebird Forum d'entraide sur le SGBD Firebird. Avant de poster -> F.A.Q Firebird, Tutoriels
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 23/09/2007, 19h59   #1
Nouveau Membre du Club
 
Avatar de ALEX77
 
Inscription : juillet 2002
Messages : 99
Détails du profil
Informations forums :
Inscription : juillet 2002
Messages : 99
Points : 36
Points : 36
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.

ALEX77 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/09/2007, 13h28   #2
Expert Confirmé

 
Homme Philippe Makowski
Consultant spécialité Firebird
Inscription : mai 2002
Messages : 2 215
Détails du profil
Informations personnelles :
Nom : Homme Philippe Makowski
Âge : 49
Localisation : France

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

Informations forums :
Inscription : mai 2002
Messages : 2 215
Points : 3 318
Points : 3 318
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
makowski est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/09/2007, 13h38   #3
Nouveau Membre du Club
 
Avatar de ALEX77
 
Inscription : juillet 2002
Messages : 99
Détails du profil
Informations forums :
Inscription : juillet 2002
Messages : 99
Points : 36
Points : 36
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 ?
ALEX77 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/09/2007, 15h24   #4
Expert Confirmé

 
Homme Philippe Makowski
Consultant spécialité Firebird
Inscription : mai 2002
Messages : 2 215
Détails du profil
Informations personnelles :
Nom : Homme Philippe Makowski
Âge : 49
Localisation : France

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

Informations forums :
Inscription : mai 2002
Messages : 2 215
Points : 3 318
Points : 3 318
écrire une udf ou un petit programme pour cela
__________________
Philippe Makowski
IBPhoenix - Firebird
Membre de l'April
makowski est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/09/2007, 15h34   #5
Nouveau Membre du Club
 
Avatar de ALEX77
 
Inscription : juillet 2002
Messages : 99
Détails du profil
Informations forums :
Inscription : juillet 2002
Messages : 99
Points : 36
Points : 36
Citation:
Envoyé par makowski Voir le message
écrire une udf ou un petit programme pour cela
D'accord mais comment ?
ALEX77 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/09/2007, 17h57   #6
Expert Confirmé

 
Homme Philippe Makowski
Consultant spécialité Firebird
Inscription : mai 2002
Messages : 2 215
Détails du profil
Informations personnelles :
Nom : Homme Philippe Makowski
Âge : 49
Localisation : France

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

Informations forums :
Inscription : mai 2002
Messages : 2 215
Points : 3 318
Points : 3 318
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
makowski est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/09/2007, 20h04   #7
Nouveau Membre du Club
 
Avatar de ALEX77
 
Inscription : juillet 2002
Messages : 99
Détails du profil
Informations forums :
Inscription : juillet 2002
Messages : 99
Points : 36
Points : 36
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 :
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 :
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 :
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...
ALEX77 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/09/2007, 21h24   #8
Expert Confirmé Sénior
 
Avatar de qi130
 
Homme Pierre
Ingénieur qualité méthodes
Inscription : mars 2003
Messages : 3 726
Détails du profil
Informations personnelles :
Nom : Homme Pierre
Âge : 51
Localisation : France

Informations professionnelles :
Activité : Ingénieur qualité méthodes
Secteur : Finance

Informations forums :
Inscription : mars 2003
Messages : 3 726
Points : 4 739
Points : 4 739
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
qi130 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 23h52.


 
 
 
 
Partenaires

Hébergement Web