client-capabilities.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. 'use strict';
  2. const Capabilities = require('../../const/capabilities');
  3. /**
  4. * Initialize client capabilities according to options and server capabilities
  5. *
  6. * @param opts options
  7. * @param info information
  8. */
  9. module.exports.init = function (opts, info) {
  10. let capabilities =
  11. Capabilities.IGNORE_SPACE |
  12. Capabilities.PROTOCOL_41 |
  13. Capabilities.TRANSACTIONS |
  14. Capabilities.SECURE_CONNECTION |
  15. Capabilities.MULTI_RESULTS |
  16. Capabilities.PS_MULTI_RESULTS |
  17. Capabilities.SESSION_TRACK |
  18. Capabilities.PLUGIN_AUTH_LENENC_CLIENT_DATA;
  19. if ((info.serverCapabilities & Capabilities.MYSQL) === BigInt(0)) {
  20. capabilities |= Capabilities.MARIADB_CLIENT_EXTENDED_TYPE_INFO;
  21. }
  22. if (info.serverCapabilities & Capabilities.PLUGIN_AUTH) {
  23. capabilities |= Capabilities.PLUGIN_AUTH;
  24. }
  25. if (opts.connectAttributes && info.serverCapabilities & Capabilities.CONNECT_ATTRS) {
  26. capabilities |= Capabilities.CONNECT_ATTRS;
  27. }
  28. if (opts.foundRows) {
  29. capabilities |= Capabilities.FOUND_ROWS;
  30. }
  31. if (opts.permitLocalInfile) {
  32. capabilities |= Capabilities.LOCAL_FILES;
  33. }
  34. if (opts.multipleStatements) {
  35. capabilities |= Capabilities.MULTI_STATEMENTS;
  36. }
  37. info.eofDeprecated = (info.serverCapabilities & Capabilities.DEPRECATE_EOF) > 0;
  38. if (info.eofDeprecated) {
  39. capabilities |= Capabilities.DEPRECATE_EOF;
  40. }
  41. if (opts.database && info.serverCapabilities & Capabilities.CONNECT_WITH_DB) {
  42. capabilities |= Capabilities.CONNECT_WITH_DB;
  43. }
  44. // use compression only if requested by client and supported by server
  45. if (opts.compress) {
  46. if (info.serverCapabilities & Capabilities.COMPRESS) {
  47. capabilities |= Capabilities.COMPRESS;
  48. } else {
  49. opts.compress = false;
  50. }
  51. }
  52. if (opts.bulk) {
  53. if (info.serverCapabilities & Capabilities.MARIADB_CLIENT_STMT_BULK_OPERATIONS) {
  54. capabilities |= Capabilities.MARIADB_CLIENT_STMT_BULK_OPERATIONS;
  55. }
  56. }
  57. if (opts.permitConnectionWhenExpired) {
  58. capabilities |= Capabilities.CAN_HANDLE_EXPIRED_PASSWORDS;
  59. }
  60. info.clientCapabilities = capabilities;
  61. };