1
by brian
clean slate |
1 |
/* Copyright (C) 2000-2003, 2005 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
/* Remove all rows from a MyISAM table */
|
|
17 |
/* This clears the status information and truncates files */
|
|
18 |
||
19 |
#include "myisamdef.h" |
|
20 |
||
21 |
int mi_delete_all_rows(MI_INFO *info) |
|
22 |
{
|
|
23 |
uint i; |
|
24 |
MYISAM_SHARE *share=info->s; |
|
25 |
MI_STATE_INFO *state=&share->state; |
|
26 |
DBUG_ENTER("mi_delete_all_rows"); |
|
27 |
||
28 |
if (share->options & HA_OPTION_READ_ONLY_DATA) |
|
29 |
{
|
|
30 |
DBUG_RETURN(my_errno=EACCES); |
|
31 |
}
|
|
32 |
if (_mi_readinfo(info,F_WRLCK,1)) |
|
33 |
DBUG_RETURN(my_errno); |
|
34 |
if (_mi_mark_file_changed(info)) |
|
35 |
goto err; |
|
36 |
||
37 |
info->state->records=info->state->del=state->split=0; |
|
38 |
state->dellink = HA_OFFSET_ERROR; |
|
39 |
state->sortkey= (ushort) ~0; |
|
40 |
info->state->key_file_length=share->base.keystart; |
|
41 |
info->state->data_file_length=0; |
|
42 |
info->state->empty=info->state->key_empty=0; |
|
43 |
info->state->checksum=0; |
|
44 |
||
45 |
for (i=share->base.max_key_block_length/MI_MIN_KEY_BLOCK_LENGTH ; i-- ; ) |
|
46 |
state->key_del[i]= HA_OFFSET_ERROR; |
|
47 |
for (i=0 ; i < share->base.keys ; i++) |
|
48 |
state->key_root[i]= HA_OFFSET_ERROR; |
|
49 |
||
50 |
myisam_log_command(MI_LOG_DELETE_ALL,info,(uchar*) 0,0,0); |
|
51 |
/*
|
|
52 |
If we are using delayed keys or if the user has done changes to the tables
|
|
53 |
since it was locked then there may be key blocks in the key cache
|
|
54 |
*/
|
|
55 |
flush_key_blocks(share->key_cache, share->kfile, FLUSH_IGNORE_CHANGED); |
|
56 |
#ifdef HAVE_MMAP
|
|
57 |
if (share->file_map) |
|
58 |
_mi_unmap_file(info); |
|
59 |
#endif
|
|
30
by Brian Aker
Large file and ftruncate() support |
60 |
if (ftruncate(info->dfile, 0) || ftruncate(share->kfile, share->base.keystart)) |
1
by brian
clean slate |
61 |
goto err; |
62 |
VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE)); |
|
63 |
#ifdef HAVE_MMAP
|
|
64 |
/* Map again */
|
|
65 |
if (share->file_map) |
|
66 |
mi_dynmap_file(info, (my_off_t) 0); |
|
67 |
#endif
|
|
68 |
DBUG_RETURN(0); |
|
69 |
||
70 |
err: |
|
71 |
{
|
|
72 |
int save_errno=my_errno; |
|
73 |
VOID(_mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE)); |
|
74 |
info->update|=HA_STATE_WRITTEN; /* Buffer changed */ |
|
75 |
DBUG_RETURN(my_errno=save_errno); |
|
76 |
}
|
|
77 |
} /* mi_delete */ |