loadlibdemo.pp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. program loadlibdemo;
  2. {$mode objfpc}{$H+}
  3. uses
  4. {$IFDEF UNIX}{$IFDEF UseCThreads}
  5. cthreads,
  6. {$ENDIF}{$ENDIF}
  7. sysutils, Classes, sqldb,sqldblib,
  8. pqconnection,
  9. ibconnection,
  10. mysql55conn,
  11. mysql51conn,
  12. mysql50conn,
  13. mysql41conn,
  14. mysql40conn;
  15. Procedure List;
  16. Var
  17. S : TStringList;
  18. I : Integer;
  19. begin
  20. S:=TStringList.Create;
  21. try
  22. getConnectionList(S);
  23. Writeln('Available connection types:');
  24. For I:=0 to S.Count-1 do
  25. Writeln(S[i],', Default library name: ',GetConnectionDef(S[i]).DefaultLibraryName);
  26. finally
  27. S.free;
  28. end;
  29. end;
  30. Procedure LoadLib(CT,LN : String);
  31. Var
  32. D : String;
  33. begin
  34. With TSQLDBLibraryLoader.Create(Nil) do
  35. try
  36. ConnectionType:=CT;
  37. D:=LibraryName;
  38. if (LN<>'') then
  39. LibraryName:=LN;
  40. Writeln('Loading library for connector',ct,' (default: ',D,', actual:', LibraryName,')');
  41. try
  42. LoadLibrary;
  43. except
  44. On E : Exception do
  45. begin
  46. Writeln('Error loading library : ',E.Message);
  47. Exit;
  48. end;
  49. end;
  50. Writeln('UnLoading library for connector',ct,' (default: ',D,', actual:', LibraryName,')');
  51. try
  52. UnLoadLibrary;
  53. except
  54. On E : Exception do
  55. Writeln('Error unloading library : ',E.Message);
  56. end;
  57. finally
  58. Free;
  59. end;
  60. end;
  61. begin
  62. if (ParamCount<1) or (paramcount>2) then
  63. begin
  64. Writeln('Usage : ');
  65. Writeln('loadlibdemo list');
  66. Writeln(' - lists all connection types');
  67. Writeln('loadlibdemo conntype');
  68. Writeln(' - Load default library for given connection type');
  69. Writeln('loadlibdemo conntype libname');
  70. Writeln(' - Load alternative library for given connection type');
  71. end
  72. else if (ParamStr(1)='list') then
  73. List
  74. else
  75. LoadLib(Paramstr(1),ParamStr(2));
  76. end.