testib40.pp 3.5 KB

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