testgdbm.pp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. {
  2. $Id$
  3. Copyright (c) 1999-2000 by Michael Van Canneyt, member of
  4. the Free Pascal development team
  5. Test raw gdbm header translations.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. program testgdbm;
  13. {$mode objfpc}
  14. {$h+}
  15. uses sysutils,gdbm;
  16. Var
  17. dbf : pgdbm_file;
  18. Key,Data : TDatum;
  19. A,B : String;
  20. i : longint;
  21. begin
  22. dbf:=gdbm_open('test.dat',512,GDBM_NEWDB,432,nil);
  23. If dbf=Nil then
  24. Writeln('Error when creating database');
  25. for I:=1 to 10 do
  26. begin
  27. A:=Format('data for string %d',[i]);
  28. B:=Format('string %d',[i]);
  29. Data.dptr:=Pchar(A);
  30. Data.dsize:=length(A);
  31. key.dptr:=pchar(B);
  32. key.dsize:=length(B);
  33. if gdbm_store(dbf,key,data,gdbm_insert)<>0 then
  34. Writeln('Error inserting data')
  35. else
  36. Writeln('Inserted string ',i)
  37. end;
  38. key:=gdbm_firstkey(dbf);
  39. I:=0;
  40. While key.dptr<>nil do
  41. begin
  42. inc(i);
  43. data:=gdbm_fetch(dbf,key);
  44. writeln('Data for key ',i,' (',key.dptr,') : ',data.dptr);
  45. key:=gdbm_nextkey(dbf,key);
  46. end;
  47. gdbm_close(dbf);
  48. end.
  49. {
  50. $Log$
  51. Revision 1.2 2001-03-02 11:54:02 michael
  52. + Merged from fixbranch
  53. Revision 1.1.2.1 2001/03/02 11:49:44 michael
  54. + Initial implementation
  55. }
  56. {
  57. $Log$
  58. Revision 1.2 2001-03-02 11:54:02 michael
  59. + Merged from fixbranch
  60. Revision 1.1.2.1 2001/03/02 11:49:44 michael
  61. + Initial implementation
  62. }
  63. {
  64. $Log$
  65. Revision 1.2 2001-03-02 11:54:02 michael
  66. + Merged from fixbranch
  67. Revision 1.1.2.1 2001/03/02 11:49:44 michael
  68. + Initial implementation
  69. }