mariadb/sql/discover.cc
unknown 9c7412cae8 WL#1324 table name to file name encoding
- Encoding itself, implemented as a charset
  "filename". Originally planned to use '.'
  as an escape character, but now changed to '@'
  for two reasons: "ls" does not return
  file names starting with '.' considering them
  as a kind of hidden files; some platforms
  do not allow several dots in a file name.
- replacing many calls of my_snprintf() and
  strnxmov() to the new build_table_filename().
- Adding MY_APPEND_EXT mysys flag, to append
  an extention rather that replace it.
- Replacing all numeric constants in fn_format
  flag arguments to their mysys definitions, e.g.
  MY_UNPACK_FILENAME,
- Predictability in several function/methods:
  when a table name can appear with or withot .frm
  extension. Some functions/methods were changed
  so accept names strictly with .frm, other - strictly
  without .frm extensions. Several DBUG_ASSERTs were
  added to check whether an extension is passed.
Many files:
  table name to file name encoding
mysql_priv.h:
  Prototypes for new table name encoding tools.
ctype-utf8.c:
  Implementing "filename" charset for
  table name to file name encoding.
row0mysql.c:
  Fixing table name prefix.
mf_format.c:
  Adding MY_APPEND_EXT processing.
Many files:
  Fixing tests.
my_sys.h:
  Adding new flag to append rather than replace an extension.
m_ctype.h:
  Adding "filename" charset definition.


include/m_ctype.h:
  Adding "filename" charset definition.
include/my_sys.h:
  Adding new flag to append rather than replace an extension.
mysql-test/t/alter_table.test:
  Fixing tests.
mysql-test/t/create.test:
  Fixing tests.
mysql-test/t/show_check.test:
  Fixing tests.
mysql-test/r/alter_table.result:
  Fixing tests.
mysql-test/r/create.result:
  Fixing tests.
mysql-test/r/mysqldump.result:
  Fixing tests.
mysys/mf_format.c:
  Adding MY_APPEND_EXT processing.
sql/discover.cc:
  table name to file name encoding
sql/ha_berkeley.cc:
  table name to file name encoding
sql/ha_innodb.cc:
  table name to file name encoding
sql/ha_myisam.cc:
  table name to file name encoding
sql/ha_myisammrg.cc:
  table name to file name encoding
sql/ha_ndbcluster.cc:
  table name to file name encoding
sql/ha_partition.cc:
  table name to file name encoding
sql/handler.cc:
  table name to file name encoding.
sql/init.cc:
  table name to file name encoding
sql/mysqld.cc:
  table name to file name encoding
sql/parse_file.cc:
  table name to file name encoding
sql/sql_acl.cc:
  table name to file name encoding
sql/sql_base.cc:
  table name to file name encoding
sql/sql_db.cc:
  table name to file name encoding
sql/sql_delete.cc:
  table name to file name encoding
sql/sql_rename.cc:
  table name to file name encoding
sql/sql_show.cc:
  table name to file name encoding
sql/sql_table.cc:
  table name to file name encoding
sql/sql_trigger.cc:
  table name to file name encoding
sql/sql_view.cc:
  table name to file name encoding
sql/strfunc.cc:
  table name to file name encoding
sql/table.cc:
  table name to file name encoding
sql/unireg.cc:
  table name to file name encoding
storage/innobase/row/row0mysql.c:
  Fixing table name prefix.
  ,
storage/myisam/mi_create.c:
  table name to file name encoding
storage/myisam/mi_delete_table.c:
  table name to file name encoding
storage/myisam/mi_open.c:
  table name to file name encoding
storage/myisam/mi_rename.c:
  table name to file name encoding
strings/ctype-utf8.c:
  Implementing "filename" charset for
  table name to file name encoding.
sql/mysql_priv.h:
  Prototypes for new table name encoding tools.
storage/myisammrg/myrg_create.c:
  table name to file name encoding
storage/myisammrg/myrg_open.c:
  table name to file name encoding
2005-12-31 09:01:26 +04:00

130 lines
3 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,
MY_UNPACK_FILENAME|MY_APPEND_EXT),
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,
MY_UNPACK_FILENAME|MY_APPEND_EXT),
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 */