ppxview.pp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. {$mode objfpc}
  2. {$h+}
  3. program ppxview;
  4. uses sysutils,pxlib, ctypes;
  5. procedure DumpInfo (Doc : PPX_Doc);
  6. Var
  7. I : Integer;
  8. S : String;
  9. pxf : Ppxfield_t;
  10. begin
  11. I:=1;
  12. pxf:=PX_get_fields(Doc);
  13. While I<=PX_get_num_fields(Doc) do
  14. begin
  15. Write('Field ',I:3,': ',strpas(pxf^.px_fname):18,' : ');
  16. S:='';
  17. Case (pxf^.px_ftype) of
  18. pxfAlpha: S:=Format('char(%d)',[pxf^.px_flen]);
  19. pxfDate: S:=Format('date(%d)',[pxf^.px_flen]);
  20. pxfShort: S:=Format('int(%d)',[pxf^.px_flen]);
  21. pxfLong: S:=Format('int(%d)',[pxf^.px_flen]);
  22. pxfCurrency: S:=Format('currency(%d)',[pxf^.px_flen]);
  23. pxfNumber: S:=Format('double(%d)',[pxf^.px_flen]);
  24. pxfLogical: S:=Format('boolean(%d)',[pxf^.px_flen]);
  25. pxfMemoBLOb: S:=Format('memoblob(%d)',[pxf^.px_flen]);
  26. pxfBLOb: S:=Format('blob(%d)',[pxf^.px_flen]);
  27. pxfFmtMemoBLOb: S:=Format('fmtmemoblob(%d)',[pxf^.px_flen]);
  28. pxfOLE: S:=Format('ole(%d)',[pxf^.px_flen]);
  29. pxfGraphic: S:=Format('graphic(%d)',[pxf^.px_flen]);
  30. pxfTime: S:=Format('time(%d)',[pxf^.px_flen]);
  31. pxfTimestamp: S:=Format('timestamp(%d)',[pxf^.px_flen]);
  32. pxfAutoInc: S:=Format('autoinc(%d)',[pxf^.px_flen]);
  33. pxfBCD: S:=Format('decimal(%d,%d)',[pxf^.px_flen*2, pxf^.px_fdc]);
  34. pxfBytes: S:=Format('bytes(%d)',[pxf^.px_flen]);
  35. else
  36. S:=Format('Unknnown type (%d) (%d)',[pxf^.px_ftype, pxf^.px_flen]);
  37. end;
  38. Writeln(S);
  39. Inc(I);
  40. Inc(pxf);
  41. end;
  42. end;
  43. Procedure DumpRecords(Doc : PPX_Doc);
  44. var
  45. I,J,K,flen : Integer;
  46. pxf : Ppxfield_t;
  47. s : string;
  48. buf, fbuf,value : Pchar;
  49. longv : clong;
  50. y,m,d : cint;
  51. R : Double;
  52. c : char;
  53. begin
  54. I:=0;
  55. Buf:=GetMem(PX_get_recordSize(Doc));
  56. For I:=0 to px_get_num_records(Doc)-1 do
  57. begin
  58. Writeln('Record : ',I+1:4);
  59. Writeln('=============');
  60. PX_get_record(Doc,I, Buf);
  61. pxf:=PX_get_fields(Doc);
  62. fbuf:=Buf;
  63. For J:=0 to PX_get_num_fields(Doc)-1 do
  64. begin
  65. flen:=pxf^.px_flen;
  66. Case (pxf^.px_ftype) of
  67. pxfAlpha:
  68. if PX_get_data_alpha(Doc,fbuf,flen,@value)>0 then
  69. begin
  70. S:=Strpas(value);
  71. doc^.free(doc,value);
  72. end;
  73. pxfDate:
  74. if PX_get_data_long(Doc,fbuf,flen,@longv)>0 then
  75. begin
  76. {$ifdef windows}
  77. S:=DateToStr(Longv+1721425-2415019);
  78. {$else}
  79. PX_SdnToGregorian(longv+1721425,@Y,@M,@D);
  80. S:=DateToStr(EncodeDate(Y,M,D));
  81. {$endif}
  82. end;
  83. pxfShort:
  84. if PX_get_data_short(Doc,fbuf, flen, @D)>0 then
  85. S:=IntToStr(D);
  86. pxfAutoInc,
  87. pxfLong:
  88. if (PX_get_data_long(Doc,fbuf,flen,@longv)>0) then
  89. S:=IntToStr(Longv);
  90. pxfCurrency,
  91. pxfNumber:
  92. If (PX_get_data_double(Doc,FBuf,Flen,@R)>0) then
  93. S:=Format('%f',[R]);
  94. pxfLogical:
  95. if (PX_get_data_byte(Doc,FBuf,flen,@C)>0) then
  96. S:=BoolToStr(C<>#0);
  97. pxfMemoBLOb,
  98. pxfBLOb,
  99. pxfFmtMemoBLOb,
  100. pxfOLE,
  101. pxfGraphic,
  102. pxfBytes:
  103. begin
  104. S:='';
  105. if (pxf^.px_ftype=pxfGraphic) then
  106. Y:=PX_get_data_graphic(Doc,FBuf,FLen,@M,@D,@Value)
  107. else if (pxf^.px_ftype=pxfBytes) then
  108. Y:=PX_get_data_bytes(Doc,FBuf,FLen,@Value)
  109. else
  110. Y:=PX_get_data_blob(Doc,FBuf,FLen,@M,@D,@Value);
  111. If (Y>0) then
  112. If Assigned(Value) then
  113. begin
  114. S:='';
  115. If pxf^.px_ftype in [pxfMemoBLOb,pxfFmtMemoBLOb] then
  116. begin
  117. // Not null terminated.
  118. SetLength(S,D);
  119. Move(Value^,S[1],D);
  120. end
  121. else
  122. For K:=0 to D-1 do
  123. S:=S+' '+HexStr(Ord(Value[K]),2);
  124. doc^.free(doc,value);
  125. end
  126. else
  127. S:='<Null>';
  128. end;
  129. pxfTime:
  130. if (PX_get_data_long(Doc,fbuf,flen,@longv)>0) then
  131. S:=TimeToStr(longv/MSecsPerDay);
  132. pxfTimestamp:
  133. if (PX_get_data_double(Doc,fbuf,flen,@R)>0) then
  134. begin
  135. value:=PX_timestamp2string(Doc,R,'Y-m-d H:i:s');
  136. S:=Strpas(Value);
  137. doc^.free(doc,value);
  138. end;
  139. pxfBCD:
  140. if (PX_get_data_bcd(Doc,pcuchar(FBuf),pxf^.px_fdc,@Value)>0) then
  141. begin
  142. S:=strpas(value);
  143. doc^.free(doc,value);
  144. end;
  145. else
  146. S:=Format('Unknnown type (%d) (%d)',[pxf^.px_ftype, pxf^.px_flen]);
  147. end;
  148. WriteLn(strpas(pxf^.px_fname):18,' = ',S);
  149. Inc(fbuf,Flen);
  150. Inc(Pxf);
  151. end;
  152. end;
  153. end;
  154. Var
  155. Doc : PPX_Doc;
  156. FN,BFN : String;
  157. begin
  158. LoadPXlib(pxlibraryname);
  159. PX_Boot;
  160. try
  161. Doc:=px_new();
  162. Try
  163. FN:=ParamStr(1);
  164. BFN:=ChangeFileExt(FN,'.mb');
  165. px_open_file(Doc,Pchar(FN));
  166. try
  167. if FileExists(BFN) then
  168. PX_set_blob_file(Doc,PChar(BFN));
  169. DumpInfo(Doc);
  170. DumpRecords(Doc);
  171. Finally
  172. PX_close(Doc);
  173. end;
  174. Finally
  175. PX_Delete(Doc);
  176. end;
  177. finally
  178. PX_Shutdown;
  179. end;
  180. end.