test-pp.nut 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. local pgsql_functions = [
  2. ["ConnStatusType", "PQstatus", "const PGconn *conn"],
  3. ["void", "PQfinish", "PGconn *conn"],
  4. ["PGresult *", "PQprepare", @"PGconn *conn,
  5. const char *stmtName,
  6. const char *query,
  7. int nParams,
  8. const Oid *paramTypes"],
  9. ["PGresult *", "PQdescribePrepared", "PGconn *conn, const char *stmtName"],
  10. ["int", "PQnparams", "const PGresult *res"],
  11. ["Oid", "PQparamtype", "const PGresult *res, int param_number"],
  12. ["PGresult *", "PQexecPrepared", @"PGconn *conn,
  13. const char *stmtName,
  14. int nParams,
  15. const char * const *paramValues,
  16. const int *paramLengths,
  17. const int *paramFormats,
  18. int resultFormat"],
  19. ["PGresult *", "PQexec", "PGconn *conn, const char *command"],
  20. ["const char*", "PQgetvalue", @"const PGresult *res,
  21. int row_number,
  22. int column_number"],
  23. ["int", "PQntuples", "const PGresult *res"],
  24. ["char *", "PQcmdTuples", "const PGresult *res"],
  25. ["int", "PQnfields", "const PGresult *res"],
  26. ["int", "PQgetisnull", @"const PGresult *res,
  27. int row_number,
  28. int column_number"],
  29. ["void", "PQclear", "const PGresult *res"],
  30. ["int", "PQfnumber", "const PGresult *res, const char *column_name"],
  31. ["char *", "PQfname", "const PGresult *res, int column_number"],
  32. ["ExecStatusType", "PQresultStatus", "const PGresult *res"],
  33. ["char *", "PQerrorMessage", "const PGconn *conn"],
  34. ["void", "PQreset", "PGconn *conn"],
  35. ["PGresult *", "PQgetResult", "PGconn *conn"],
  36. ["int", "PQsetnonblocking", "PGconn *conn, int arg"],
  37. ["Oid", "PQftype", "const PGresult *res, int column_number"],
  38. ["int", "PQserverVersion", "const PGconn *conn"],
  39. // Large-object access routines
  40. ["int", "lo_open", "PGconn *conn, Oid lobjId, int mode"],
  41. ["int", "lo_close", "PGconn *conn, int fd"],
  42. ["int", "lo_read", "PGconn *conn, int fd, char *buf, size_t len"],
  43. ["int", "lo_write", "PGconn *conn, int fd, const char *buf, size_t len"],
  44. ["int", "lo_lseek", "PGconn *conn, int fd, int offset, int whence"],
  45. ["Oid", "lo_creat", "PGconn *conn, int mode"],
  46. ["Oid", "lo_create", "PGconn *conn, Oid lobjId"],
  47. ["int", "lo_tell", "PGconn *conn, int fd"],
  48. ["int", "lo_truncate", "PGconn *conn, int fd, size_t len"],
  49. ["int", "lo_unlink", "PGconn *conn, Oid lobjId"],
  50. ["Oid", "lo_import", "PGconn *conn, const char *filename"],
  51. ["Oid", "lo_import_with_oid", "PGconn *conn, const char *filename, Oid lobjId"],
  52. ["int", "lo_export", "PGconn *conn, Oid lobjId, const char *filename"],
  53. //next entry should be the last one
  54. //to make valid the test made on load_libpq function
  55. ["PGconn *", "PQconnectdb", "const char *conninfo"],
  56. ];
  57. function write_pgsql_functions_declaration(){
  58. foreach(k,v in pgsql_functions) {
  59. putsnl("typedef " + v[1] + " (*" + v[2] + "_t)(" + v[3] + ");");
  60. putsnl("static " + v[2] + "_t dl" + v[2] + " = 0;");
  61. }
  62. }
  63. function write_pgsql_functions_load(){
  64. foreach(k,v in pgsql_functions){
  65. putsnl("dl" + v[2] + " = (" + v[2] + "_t) libpq.dlsym(\"" + v[2] + "\");");
  66. putsnl("if(!dl" + v[2] + ") return false;");
  67. }
  68. }