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, name, 0, |
37 | O_RDWR | O_EXCL | O_NOFOLLOW, MYF(MY_WME))) < 0) |
38 | goto err; |
39 | errpos=1; |
40 | if (table_names) |
41 | { |
42 | for ( ; *table_names ; table_names++) |
43 | { |
44 | strmov(buff,*table_names); |
45 | if (fix_names) |
46 | fn_same(buff,name,4); |
47 | *(end=strend(buff))='\n'; |
48 | end[1]=0; |
49 | if (mysql_file_write(file, (uchar*) buff, (uint) (end-buff+1), |
50 | MYF(MY_WME | MY_NABP))) |
51 | goto err; |
52 | } |
53 | } |
54 | if (insert_method != MERGE_INSERT_DISABLED) |
55 | { |
56 | end=strxmov(buff,"#INSERT_METHOD=" , |
57 | get_type(&merge_insert_method,insert_method-1),"\n" ,NullS); |
58 | if (mysql_file_write(file, (uchar*) buff, (uint) (end-buff), |
59 | MYF(MY_WME | MY_NABP))) |
60 | goto err; |
61 | } |
62 | if (mysql_file_close(file, MYF(0))) |
63 | goto err; |
64 | DBUG_RETURN(0); |
65 | |
66 | err: |
67 | save_errno=my_errno ? my_errno : -1; |
68 | switch (errpos) { |
69 | case 1: |
70 | (void) mysql_file_close(file, MYF(0)); |
71 | } |
72 | DBUG_RETURN(my_errno=save_errno); |
73 | } /* myrg_create */ |
74 | |