MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
myrg_create.c
1 /* Copyright (c) 2000, 2001, 2005-2007 MySQL AB, 2009 Sun Microsystems, Inc.
2  Use is subject to license terms.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16 
17 /* Create a MYMERGE_-file */
18 
19 #include "myrg_def.h"
20 
21  /* create file named 'name' and save filenames in it
22  table_names should be NULL or a vector of string-pointers with
23  a NULL-pointer last
24  */
25 
26 int myrg_create(const char *name, const char **table_names,
27  uint insert_method, my_bool fix_names)
28 {
29  int save_errno;
30  uint errpos;
31  File file;
32  char buff[FN_REFLEN],*end;
33  DBUG_ENTER("myrg_create");
34 
35  errpos=0;
36  if ((file= mysql_file_create(rg_key_file_MRG,
37  fn_format(buff, name, "", MYRG_NAME_EXT,
38  MY_UNPACK_FILENAME|MY_APPEND_EXT), 0,
39  O_RDWR | O_EXCL | O_NOFOLLOW, MYF(MY_WME))) < 0)
40  goto err;
41  errpos=1;
42  if (table_names)
43  {
44  for ( ; *table_names ; table_names++)
45  {
46  strmov(buff,*table_names);
47  if (fix_names)
48  fn_same(buff,name,4);
49  *(end=strend(buff))='\n';
50  end[1]=0;
51  if (mysql_file_write(file, (uchar*) buff, (uint) (end-buff+1),
52  MYF(MY_WME | MY_NABP)))
53  goto err;
54  }
55  }
56  if (insert_method != MERGE_INSERT_DISABLED)
57  {
58  end=strxmov(buff,"#INSERT_METHOD=",
59  get_type(&merge_insert_method,insert_method-1),"\n",NullS);
60  if (mysql_file_write(file, (uchar*) buff, (uint) (end-buff),
61  MYF(MY_WME | MY_NABP)))
62  goto err;
63  }
64  if (mysql_file_close(file, MYF(0)))
65  goto err;
66  DBUG_RETURN(0);
67 
68 err:
69  save_errno=my_errno ? my_errno : -1;
70  switch (errpos) {
71  case 1:
72  (void) mysql_file_close(file, MYF(0));
73  }
74  DBUG_RETURN(my_errno=save_errno);
75 } /* myrg_create */