ppxview.pp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. si: shortint;
  52. R : Double;
  53. c : char;
  54. begin
  55. I:=0;
  56. Buf:=GetMem(PX_get_recordSize(Doc));
  57. For I:=0 to px_get_num_records(Doc)-1 do
  58. begin
  59. Writeln('Record : ',I+1:4);
  60. Writeln('=============');
  61. PX_get_record(Doc,I, Buf);
  62. pxf:=PX_get_fields(Doc);
  63. fbuf:=Buf;
  64. For J:=0 to PX_get_num_fields(Doc)-1 do
  65. begin
  66. flen:=pxf^.px_flen;
  67. Case (pxf^.px_ftype) of
  68. pxfAlpha:
  69. if PX_get_data_alpha(Doc,fbuf,flen,@value)>0 then
  70. begin
  71. S:=Strpas(value);
  72. doc^.free(doc,value);
  73. end;
  74. pxfDate:
  75. if PX_get_data_long(Doc,fbuf,flen,@longv)>0 then
  76. begin
  77. {$ifdef windows}
  78. S:=DateToStr(Longv+1721425-2415019);
  79. {$else}
  80. PX_SdnToGregorian(longv+1721425,@Y,@M,@D);
  81. S:=DateToStr(EncodeDate(Y,M,D));
  82. {$endif}
  83. end;
  84. pxfShort:
  85. if PX_get_data_short(Doc,fbuf, flen, @si)>0 then
  86. S:=IntToStr(si);
  87. pxfAutoInc,
  88. pxfLong:
  89. if (PX_get_data_long(Doc,fbuf,flen,@longv)>0) then
  90. S:=IntToStr(Longv);
  91. pxfCurrency,
  92. pxfNumber:
  93. If (PX_get_data_double(Doc,FBuf,Flen,@R)>0) then
  94. S:=Format('%f',[R]);
  95. pxfLogical:
  96. if (PX_get_data_byte(Doc,FBuf,flen,@C)>0) then
  97. S:=BoolToStr(C<>#0);
  98. pxfMemoBLOb,
  99. pxfBLOb,
  100. pxfFmtMemoBLOb,
  101. pxfOLE,
  102. pxfGraphic,
  103. pxfBytes:
  104. begin
  105. S:='';
  106. if (pxf^.px_ftype=pxfGraphic) then
  107. Y:=PX_get_data_graphic(Doc,FBuf,FLen,@M,@D,@Value)
  108. else if (pxf^.px_ftype=pxfBytes) then
  109. Y:=PX_get_data_bytes(Doc,FBuf,FLen,@Value)
  110. else
  111. Y:=PX_get_data_blob(Doc,FBuf,FLen,@M,@D,@Value);
  112. If (Y>0) then
  113. If Assigned(Value) then
  114. begin
  115. S:='';
  116. If pxf^.px_ftype in [pxfMemoBLOb,pxfFmtMemoBLOb] then
  117. begin
  118. // Not null terminated.
  119. SetLength(S,D);
  120. Move(Value^,S[1],D);
  121. end
  122. else
  123. For K:=0 to D-1 do
  124. S:=S+' '+HexStr(Ord(Value[K]),2);
  125. doc^.free(doc,value);
  126. end
  127. else
  128. S:='<Null>';
  129. end;
  130. pxfTime:
  131. if (PX_get_data_long(Doc,fbuf,flen,@longv)>0) then
  132. S:=TimeToStr(longv/MSecsPerDay);
  133. pxfTimestamp:
  134. if (PX_get_data_double(Doc,fbuf,flen,@R)>0) then
  135. begin
  136. value:=PX_timestamp2string(Doc,R,'Y-m-d H:i:s');
  137. S:=Strpas(Value);
  138. doc^.free(doc,value);
  139. end;
  140. pxfBCD:
  141. if (PX_get_data_bcd(Doc,pcuchar(FBuf),pxf^.px_fdc,@Value)>0) then
  142. begin
  143. S:=strpas(value);
  144. doc^.free(doc,value);
  145. end;
  146. else
  147. S:=Format('Unknnown type (%d) (%d)',[pxf^.px_ftype, pxf^.px_flen]);
  148. end;
  149. WriteLn(strpas(pxf^.px_fname):18,' = ',S);
  150. Inc(fbuf,Flen);
  151. Inc(Pxf);
  152. end;
  153. end;
  154. FreeMem(Buf);
  155. end;
  156. Var
  157. Doc : PPX_Doc;
  158. FN,BFN : String;
  159. begin
  160. LoadPXlib(pxlibraryname);
  161. PX_Boot;
  162. try
  163. Doc:=px_new();
  164. Try
  165. FN:=ParamStr(1);
  166. BFN:=ChangeFileExt(FN,'.mb');
  167. px_open_file(Doc,Pchar(FN));
  168. try
  169. if FileExists(BFN) then
  170. PX_set_blob_file(Doc,PChar(BFN));
  171. DumpInfo(Doc);
  172. DumpRecords(Doc);
  173. Finally
  174. PX_close(Doc);
  175. end;
  176. Finally
  177. PX_Delete(Doc);
  178. end;
  179. finally
  180. PX_Shutdown;
  181. end;
  182. end.