test100params.pp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. program test100params;
  2. {$mode objfpc}{$H+}
  3. uses
  4. {$IFDEF UNIX}{$IFDEF UseCThreads}
  5. cthreads,
  6. {$ENDIF}{$ENDIF}
  7. Classes, SysUtils,
  8. db, sqldb, pqconnection;
  9. var
  10. Conn: TPQConnection;
  11. Tran: TSQLTransaction;
  12. Q: TSQLQuery;
  13. sql: string;
  14. i: integer;
  15. begin
  16. Conn:=TPQConnection.Create(nil);
  17. Conn.HostName:='localhost';
  18. Conn.DatabaseName:='postgres';
  19. Conn.UserName:='postgres';
  20. Conn.Password:='postgres';
  21. Tran:=TSQLTransaction.Create(nil);
  22. Tran.DataBase:=Conn;
  23. Q:=TSQLQuery.Create(nil);
  24. Q.DataBase:=Conn;
  25. Conn.Open;
  26. writeln('Connected');
  27. sql:='';
  28. for i:=1 to 101 do
  29. begin
  30. if sql<>'' then sql:=sql+',';
  31. sql:=sql+format('f%d integer', [i]);
  32. end;
  33. Conn.ExecuteDirect(format('CREATE TEMPORARY TABLE t (%s)', [sql]));
  34. writeln('Table created');
  35. sql:='';
  36. for i:=1 to 101 do
  37. begin
  38. if sql<>'' then sql:=sql+',';
  39. sql:=sql+format(':f%d', [i]);
  40. end;
  41. Q.SQL.Text:=format('INSERT INTO t VALUES(%s)', [sql]);
  42. for i:=1 to 101 do
  43. begin
  44. Q.ParamByName('f'+inttostr(i)).AsInteger:=i;
  45. end;
  46. Q.ExecSQL;
  47. Q.SQL.Text:='SELECT * FROM t';
  48. Q.Open;
  49. for i:=90 to 101 do
  50. writeln(Q.FieldByName('f'+inttostr(i)).AsInteger, ',');
  51. Q.Close;
  52. //END
  53. Tran.Commit;
  54. Conn.Close;
  55. Q.Free;
  56. Tran.Free;
  57. Conn.Free;
  58. writeln('End. Press any key');
  59. readln;
  60. end.