You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
2.9 KiB

Added NDB storage engine include/my_base.h: Added three new errorcodes to be returned by the handler sql/Makefile.am: Add new files discover.cc, ha_ndbcluster.cc and ha_ndbcluster.h Add include path of NDB files sql/handler.cc: Added variable for keeping track of number of "discovers" Added NDB to list of storage engines Added calls to NDB for commit, rollback etc. Added function ha_discover for discovering a table from handler sql/handler.h: Added NDB to list of storage engines Added vbariable in transaction for keeping a ndb transaction handle sql/lex.h: Changed AND to AND_SYM and OR to OR_SYM to avoid nameclash sql/mysql_priv.h: Added prototypes for new functions readfrm, writefrm and create_table_from_handler sql/mysqld.cc: Added NDB support Disable NDB with --skip-ndbcluster sql/set_var.cc: Add posibilty to show if NDB handler is supported sql/ha_ndbcluster.cc: Add ifdef for whole file for not compiling anything if NDB sholdn't be included Updated timestamp handling to use new vars timestamp_default_now and timestamp_on_update_now sql/sql_base.cc: If frm file is not found on disk, ask handler if it knows about the table. Then retry the open. This new functionality is called "discover" and can be used by any handler. sql/sql_class.h: Added variable for keeping a NDB connection handle sql/sql_table.cc: Before trying to create a table, ask handler if a table with that name already exists. If user said CREATE TABLE IF NOT EXISTS, disocver the table from handler sql/sql_yacc.yy: Add NDBCLUSTER_SYM Change AND to AND_SYM Change OR to OR_SYM sql/table.cc: Fixe for probelm when NullS is returned from bas_ext of a handler.
22 years ago
  1. /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  13. /* Functions for discover of frm file from handler */
  14. #include "mysql_priv.h"
  15. #include <my_dir.h>
  16. /*
  17. Read the contents of a .frm file
  18. SYNOPSIS
  19. readfrm()
  20. name path to table-file "db/name"
  21. frmdata frm data
  22. len length of the read frmdata
  23. RETURN VALUES
  24. 0 ok
  25. 1 Could not open file
  26. 2 Could not stat file
  27. 3 Could not allocate data for read
  28. Could not read file
  29. frmdata and len are set to 0 on error
  30. */
  31. int readfrm(const char *name,
  32. const void **frmdata, uint *len)
  33. {
  34. int error;
  35. char index_file[FN_REFLEN];
  36. File file;
  37. ulong read_len;
  38. char *read_data;
  39. MY_STAT state;
  40. DBUG_ENTER("readfrm");
  41. DBUG_PRINT("enter",("name: '%s'",name));
  42. *frmdata= NULL; // In case of errors
  43. *len= 0;
  44. error= 1;
  45. if ((file=my_open(fn_format(index_file,name,"",reg_ext,4),
  46. O_RDONLY | O_SHARE,
  47. MYF(0))) < 0)
  48. goto err_end;
  49. // Get length of file
  50. error= 2;
  51. if (my_fstat(file, &state, MYF(0)))
  52. goto err;
  53. read_len= state.st_size;
  54. // Read whole frm file
  55. error= 3;
  56. read_data= 0;
  57. if (read_string(file, &read_data, read_len))
  58. goto err;
  59. // Setup return data
  60. *frmdata= (void*) read_data;
  61. *len= read_len;
  62. error= 0;
  63. err:
  64. if (file > 0)
  65. VOID(my_close(file,MYF(MY_WME)));
  66. err_end: /* Here when no file */
  67. DBUG_RETURN (error);
  68. } /* readfrm */
  69. /*
  70. Write the content of a frm data pointer
  71. to a frm file
  72. SYNOPSIS
  73. writefrm()
  74. name path to table-file "db/name"
  75. frmdata frm data
  76. len length of the frmdata
  77. RETURN VALUES
  78. 0 ok
  79. 2 Could not write file
  80. */
  81. int writefrm(const char *name, const void *frmdata, uint len)
  82. {
  83. File file;
  84. char index_file[FN_REFLEN];
  85. int error;
  86. DBUG_ENTER("writefrm");
  87. DBUG_PRINT("enter",("name: '%s' len: %d ",name,len));
  88. //DBUG_DUMP("frmdata", (char*)frmdata, len);
  89. error= 0;
  90. if ((file=my_create(fn_format(index_file,name,"",reg_ext,4),
  91. CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0)
  92. {
  93. if (my_write(file,(byte*)frmdata,len,MYF(MY_WME | MY_NABP)))
  94. error= 2;
  95. }
  96. VOID(my_close(file,MYF(0)));
  97. DBUG_RETURN(error);
  98. } /* writefrm */