Guest User

Untitled

a guest
Feb 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. {$mode objfpc}
  2.  
  3. program test;
  4.  
  5. uses mysql50, SysUtils;
  6.  
  7. var
  8. db : PMYSQL;
  9. res : PMYSQL_RES;
  10. fields : PMYSQL_FIELD;
  11. idx, cnt : integer;
  12.  
  13. procedure ExitNicely(err : integer);
  14. begin
  15. WriteLn(mysql_error(db));
  16. mysql_close(db);
  17. Halt(err);
  18. end;
  19.  
  20. begin
  21. db := mysql_init(nil);
  22. mysql_real_connect(db, nil, PChar(ParamStr(1)), nil, PChar('test'), 0, nil, 0);
  23. if mysql_errno(db) <> 0
  24. then ExitNicely(1);
  25.  
  26. mysql_query(db, 'DROP TABLE people');
  27. mysql_query(db, 'CREATE TABLE people (id serial, name varchar(20))');
  28. mysql_query(db, 'INSERT INTO people (name) VALUES (''John''), (''Jef'')');
  29.  
  30. if mysql_query(db, 'SELECT id, name FROM people') <> 0
  31. then ExitNicely(2);
  32.  
  33. res := mysql_store_result(db);
  34. cnt := mysql_field_count(db);
  35. fields := mysql_fetch_fields(res);
  36.  
  37. WriteLn('Field count = ' + IntToStr(cnt));
  38.  
  39. for idx := 0 to (cnt-1) do
  40. WriteLn('Name="' + fields[idx].name + '"');
  41.  
  42. mysql_close(db);
  43. end.
Add Comment
Please, Sign In to add comment