mariadb/sql/discover.cc
unknown 5a46435678 WL1424 Multiple MySQL Servers: SHOW TABLES etc. should detect new and delete old tables.
include/my_base.h:
  Added new bit to table create options
  Removed old error code HA_ERR_OLD_METADAT and reused it for HA_ERR_NO_SUCH_TABLE.
mysql-test/r/ndb_autodiscover.result:
  Updated test cases
mysql-test/t/ndb_autodiscover.test:
  Updated test cases
mysql-test/t/ndb_autodiscover2.test:
  Updated test cases
sql/discover.cc:
  Moved function create_table_from_handler to handler.cc
sql/ha_ndbcluster.cc:
  Improved discover functionality
  Added .ndb file
  Changed error code mappings for a table that does not exist in engine
  Check for ndb object in THD
  Updated ndbcluster_discover, ndbcluster_list_tables and ndbcluster_can_discover
sql/ha_ndbcluster.h:
  Improved discover
sql/handler.cc:
  Added new error message mapping.
  Moved function ha_create_table_from_engine to handler level
  Added new functions ha_can_discover, ha_list_tables and ha_table_exists
sql/handler.h:
  Added new error message mapping.
  Moved function ha_create_table_from_engine to handler level
  Added new functions ha_can_discover, ha_list_tables and ha_table_exists
sql/mysql_priv.h:
  Removed create_table_from_handler, moved to handler.h
sql/sql_base.cc:
  Renamed function create_table_from_handler
sql/sql_show.cc:
  Added new function mysql_discover_files and mysql_list_files. 
  Modified mysql_find_files to discover new and delete "old" files/tables.
sql/sql_table.cc:
  Renamed create_table_from_handler
  Call ha_create_table_from_engine, in order to discover the the frm file before it can be dropped.
sql/table.cc:
  Added mapping of the error code HA_ERR_NO_SUCH_TABLE
2004-09-13 14:46:38 +02:00

128 lines
2.9 KiB
C++

/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* Functions for discover of frm file from handler */
#include "mysql_priv.h"
#include <my_dir.h>
/*
Read the contents of a .frm file
SYNOPSIS
readfrm()
name path to table-file "db/name"
frmdata frm data
len length of the read frmdata
RETURN VALUES
0 ok
1 Could not open file
2 Could not stat file
3 Could not allocate data for read
Could not read file
frmdata and len are set to 0 on error
*/
int readfrm(const char *name,
const void **frmdata, uint *len)
{
int error;
char index_file[FN_REFLEN];
File file;
ulong read_len;
char *read_data;
MY_STAT state;
DBUG_ENTER("readfrm");
DBUG_PRINT("enter",("name: '%s'",name));
*frmdata= NULL; // In case of errors
*len= 0;
error= 1;
if ((file=my_open(fn_format(index_file,name,"",reg_ext,4),
O_RDONLY | O_SHARE,
MYF(0))) < 0)
goto err_end;
// Get length of file
error= 2;
if (my_fstat(file, &state, MYF(0)))
goto err;
read_len= state.st_size;
// Read whole frm file
error= 3;
read_data= 0;
if (read_string(file, &read_data, read_len))
goto err;
// Setup return data
*frmdata= (void*) read_data;
*len= read_len;
error= 0;
err:
if (file > 0)
VOID(my_close(file,MYF(MY_WME)));
err_end: /* Here when no file */
DBUG_RETURN (error);
} /* readfrm */
/*
Write the content of a frm data pointer
to a frm file
SYNOPSIS
writefrm()
name path to table-file "db/name"
frmdata frm data
len length of the frmdata
RETURN VALUES
0 ok
2 Could not write file
*/
int writefrm(const char *name, const void *frmdata, uint len)
{
File file;
char index_file[FN_REFLEN];
int error;
DBUG_ENTER("writefrm");
DBUG_PRINT("enter",("name: '%s' len: %d ",name,len));
//DBUG_DUMP("frmdata", (char*)frmdata, len);
error= 0;
if ((file=my_create(fn_format(index_file,name,"",reg_ext,4),
CREATE_MODE,O_RDWR | O_TRUNC,MYF(MY_WME))) >= 0)
{
if (my_write(file,(byte*)frmdata,len,MYF(MY_WME | MY_NABP)))
error= 2;
}
VOID(my_close(file,MYF(0)));
DBUG_RETURN(error);
} /* writefrm */