mysql_ps.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License, version 2.0,
  4. as published by the Free Software Foundation.
  5. This program is also distributed with certain software (including
  6. but not limited to OpenSSL) that is licensed under separate terms,
  7. as designated in a particular file or component or in included license
  8. documentation. The authors of MySQL hereby grant you an additional
  9. permission to link the program and your derivative works with the
  10. separately licensed software that they have included with MySQL.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License, version 2.0, for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  18. #ifndef MYSQL_PS_H
  19. #define MYSQL_PS_H
  20. /**
  21. @file mysql/psi/mysql_ps.h
  22. Instrumentation helpers for prepared statements.
  23. */
  24. #include "mysql/psi/psi.h"
  25. #ifndef PSI_PS_CALL
  26. #define PSI_PS_CALL(M) PSI_DYNAMIC_CALL(M)
  27. #endif
  28. #ifdef HAVE_PSI_PS_INTERFACE
  29. #define MYSQL_CREATE_PS(IDENTITY, ID, LOCKER, NAME, NAME_LENGTH, SQLTEXT, SQLTEXT_LENGTH) \
  30. inline_mysql_create_prepared_stmt(IDENTITY, ID, LOCKER, NAME, NAME_LENGTH, SQLTEXT, SQLTEXT_LENGTH)
  31. #define MYSQL_EXECUTE_PS(LOCKER, PREPARED_STMT) \
  32. inline_mysql_execute_prepared_stmt(LOCKER, PREPARED_STMT)
  33. #define MYSQL_DESTROY_PS(PREPARED_STMT) \
  34. inline_mysql_destroy_prepared_stmt(PREPARED_STMT)
  35. #define MYSQL_REPREPARE_PS(PREPARED_STMT) \
  36. inline_mysql_reprepare_prepared_stmt(PREPARED_STMT)
  37. #define MYSQL_SET_PS_TEXT(PREPARED_STMT, SQLTEXT, SQLTEXT_LENGTH) \
  38. inline_mysql_set_prepared_stmt_text(PREPARED_STMT, SQLTEXT, SQLTEXT_LENGTH)
  39. #else
  40. #define MYSQL_CREATE_PS(IDENTITY, ID, LOCKER, NAME, NAME_LENGTH, SQLTEXT, SQLTEXT_LENGTH) \
  41. NULL
  42. #define MYSQL_EXECUTE_PS(LOCKER, PREPARED_STMT) \
  43. do {} while (0)
  44. #define MYSQL_DESTROY_PS(PREPARED_STMT) \
  45. do {} while (0)
  46. #define MYSQL_REPREPARE_PS(PREPARED_STMT) \
  47. do {} while (0)
  48. #define MYSQL_SET_PS_TEXT(PREPARED_STMT, SQLTEXT, SQLTEXT_LENGTH) \
  49. do {} while (0)
  50. #endif
  51. #ifdef HAVE_PSI_PS_INTERFACE
  52. static inline struct PSI_prepared_stmt*
  53. inline_mysql_create_prepared_stmt(void *identity, uint stmt_id,
  54. PSI_statement_locker *locker,
  55. const char *stmt_name, size_t stmt_name_length,
  56. const char *sqltext, size_t sqltext_length)
  57. {
  58. if (locker == NULL)
  59. return NULL;
  60. return PSI_PS_CALL(create_prepared_stmt)(identity, stmt_id,
  61. locker,
  62. stmt_name, stmt_name_length,
  63. sqltext, sqltext_length);
  64. }
  65. static inline void
  66. inline_mysql_execute_prepared_stmt(PSI_statement_locker *locker,
  67. PSI_prepared_stmt* prepared_stmt)
  68. {
  69. if (prepared_stmt != NULL && locker != NULL)
  70. PSI_PS_CALL(execute_prepared_stmt)(locker, prepared_stmt);
  71. }
  72. static inline void
  73. inline_mysql_destroy_prepared_stmt(PSI_prepared_stmt *prepared_stmt)
  74. {
  75. if (prepared_stmt != NULL)
  76. PSI_PS_CALL(destroy_prepared_stmt)(prepared_stmt);
  77. }
  78. static inline void
  79. inline_mysql_reprepare_prepared_stmt(PSI_prepared_stmt *prepared_stmt)
  80. {
  81. if (prepared_stmt != NULL)
  82. PSI_PS_CALL(reprepare_prepared_stmt)(prepared_stmt);
  83. }
  84. static inline void
  85. inline_mysql_set_prepared_stmt_text(PSI_prepared_stmt *prepared_stmt,
  86. const char *text,
  87. uint text_len)
  88. {
  89. if (prepared_stmt != NULL)
  90. {
  91. PSI_PS_CALL(set_prepared_stmt_text)(prepared_stmt, text, text_len);
  92. }
  93. }
  94. #endif
  95. #endif