testgdbm.pp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.1 2002-01-29 17:55:03 peter
  52. * splitted to base and extra
  53. Revision 1.2 2001/03/02 11:54:02 michael
  54. + Merged from fixbranch
  55. Revision 1.1.2.1 2001/03/02 11:49:44 michael
  56. + Initial implementation
  57. }
  58. {
  59. $Log$
  60. Revision 1.1 2002-01-29 17:55:03 peter
  61. * splitted to base and extra
  62. Revision 1.2 2001/03/02 11:54:02 michael
  63. + Merged from fixbranch
  64. Revision 1.1.2.1 2001/03/02 11:49:44 michael
  65. + Initial implementation
  66. }
  67. {
  68. $Log$
  69. Revision 1.1 2002-01-29 17:55:03 peter
  70. * splitted to base and extra
  71. Revision 1.2 2001/03/02 11:54:02 michael
  72. + Merged from fixbranch
  73. Revision 1.1.2.1 2001/03/02 11:49:44 michael
  74. + Initial implementation
  75. }