testib60.pp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. {
  2. $Id$
  3. }
  4. program testib;
  5. {$IFDEF Unix}
  6. {$LINKLIB dl}
  7. {$ENDIF}
  8. uses Ibase60, strings;
  9. {$h-}
  10. Const
  11. { Change to YOUR database server }
  12. ServerDb : pchar = 'testdb.gdb';
  13. { CHange to YOUR username and password. These may be empty }
  14. username = '';
  15. PWD = '';
  16. { Don't edit after this }
  17. dbinfo : array [1..3] of byte
  18. = (isc_info_page_size,isc_info_num_buffers,isc_info_end);
  19. query : pchar = 'select * from FPDev;';
  20. flag : array[0..2] of shortint = (0,0,0);
  21. Type
  22. TStatusArray = Array[0..19] of ISC_Status;
  23. Var
  24. DB : Tisc_db_handle;
  25. TA : TISC_tr_handle;
  26. statement : TISC_stmt_handle;
  27. DPB : String;
  28. Status : TStatusArray;
  29. sqlda : PXSQLDA;
  30. name,email : String;
  31. i,id : longint;
  32. fs : longint;
  33. Function CheckIBstatus (Const Status : TStatusArray) : Boolean;
  34. begin
  35. CheckIBstatus:=Not ((Status[0]=1) and (status[1]<>0))
  36. end;
  37. Procedure DoError (Const status : TStatusArray);
  38. begin
  39. Writeln ('Failed:');
  40. isc_print_status(@status);
  41. halt(1);
  42. end;
  43. begin
  44. db:=Nil;
  45. dpb:=chr(isc_dpb_version1);
  46. If UserName<>'' then
  47. begin
  48. dpb:=dpb+chr(isc_dpb_user_name)+chr(length(UserName))+username;
  49. If pwd<>'' then
  50. dpb:=dpb+chr(isc_dpb_password)+chr(length(pwd))+pwd;
  51. end;
  52. Write ('Connecting to ',serverdb,': ');
  53. isc_attach_database(@Status[0],strlen(serverdb),serverdb,@db,length(dpb),@dpb[1]);
  54. if Not CheckIBStatus(Status) then
  55. DoError(status)
  56. else
  57. Writeln ('OK.');
  58. Write ('Starting Transaction : ');
  59. If ISC_start_transaction (@status[0],@ta,1,[@db,0,Nil])<>0 then
  60. DoError(Status)
  61. else
  62. Writeln ('OK.');
  63. getmem (sqlda,XSQLDA_Length(3));
  64. sqlda^.sqln:=3;
  65. sqlda^.sqld:=3;
  66. sqlda^.version:=1;
  67. Write('Allocating statement : ');
  68. If isc_dsql_allocate_statement(@status ,@db,@statement)<>0 then
  69. DoError(Status)
  70. else
  71. Writeln ('OK.');
  72. Write ('Preparing statement : ');
  73. if ISC_dsql_prepare(@status,@ta,@statement,0,query,1,sqlda)<>0 then
  74. DoError(Status)
  75. else
  76. Writeln ('OK.');
  77. I:=0;
  78. With sqlda^.sqlvar[i] do
  79. begin
  80. sqldata := @id;
  81. sqltype := sql_long;
  82. sqlind := @flag[0];
  83. end;
  84. inc(i);
  85. With sqlda^.sqlvar[i] do
  86. begin
  87. sqldata := @name[1];
  88. sqltype := sql_text;
  89. sqlind := @flag[1];
  90. end;
  91. inc(i);
  92. With sqlda^.sqlvar[i] do
  93. begin
  94. sqldata := @email[1];
  95. sqltype := sql_text;
  96. sqlind := @flag[2];
  97. end;
  98. Write ('Executing statement : ');
  99. if isc_dsql_execute(@status,@ta,@statement,1,Nil)<>0 then
  100. DoError(Status)
  101. else
  102. Writeln ('OK.');
  103. Writeln ('Fetching rows :');
  104. Repeat
  105. FS:=isc_dsql_fetch(@status,@statement,1,sqlda);
  106. If FS=0 then
  107. begin
  108. I:=255;
  109. While Name[I]=' ' do Dec(i);
  110. setlength(Name,i);
  111. I:=255;
  112. While Email[I]=' ' do Dec(i);
  113. setlength(email,i);
  114. Writeln ('(',ID,',',name,',',email,')');
  115. end;
  116. until FS<>0;
  117. If FS<>100 then
  118. DoError(status)
  119. else
  120. Writeln ('At end.');
  121. Write ('Freeing statement : ');
  122. if isc_dsql_free_statement(@status,@statement,DSQL_Close)<>0 then
  123. DoError(Status)
  124. else
  125. Writeln ('OK.');
  126. Write ('Committing transaction : ');
  127. If ISC_Commit_transaction(@status,@ta)<>0 then
  128. doerror(status)
  129. else
  130. Writeln ('OK.');
  131. Write ('Disconnecting from database: ');
  132. isc_detach_database(@status,@db);
  133. If CheckIBStatus (Status) Then
  134. Writeln ('OK.')
  135. else
  136. doerror(status);
  137. end.
  138. {
  139. $Log$
  140. Revision 1.2 2002-09-07 15:42:52 peter
  141. * old logs removed and tabs fixed
  142. Revision 1.1 2002/01/29 17:54:53 peter
  143. * splitted to base and extra
  144. }