~drizzle-trunk/drizzle/development

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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
16
/* Remove all rows from a MyISAM table */
17
/* This clears the status information and truncates files */
18
1130.3.28 by Monty Taylor
Moved heapdef.h and myisamdef.h to *_priv.h for easier filtering for include guard check.
19
#include "myisam_priv.h"
1 by brian
clean slate
20
21
int mi_delete_all_rows(MI_INFO *info)
22
{
482 by Brian Aker
Remove uint.
23
  uint32_t i;
1 by brian
clean slate
24
  MYISAM_SHARE *share=info->s;
25
  MI_STATE_INFO *state=&share->state;
26
27
  if (share->options & HA_OPTION_READ_ONLY_DATA)
28
  {
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
29
    return(errno=EACCES);
1 by brian
clean slate
30
  }
31
  if (_mi_readinfo(info,F_WRLCK,1))
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
32
    return(errno);
1 by brian
clean slate
33
  if (_mi_mark_file_changed(info))
34
    goto err;
35
36
  info->state->records=info->state->del=state->split=0;
37
  state->dellink = HA_OFFSET_ERROR;
365.2.9 by Monty Taylor
Got rid of all instances of ~0
38
  state->sortkey=  UINT16_MAX;
1 by brian
clean slate
39
  info->state->key_file_length=share->base.keystart;
40
  info->state->data_file_length=0;
41
  info->state->empty=info->state->key_empty=0;
42
  info->state->checksum=0;
43
44
  for (i=share->base.max_key_block_length/MI_MIN_KEY_BLOCK_LENGTH ; i-- ; )
45
    state->key_del[i]= HA_OFFSET_ERROR;
46
  for (i=0 ; i < share->base.keys ; i++)
47
    state->key_root[i]= HA_OFFSET_ERROR;
48
49
  /*
50
    If we are using delayed keys or if the user has done changes to the tables
51
    since it was locked then there may be key blocks in the key cache
52
  */
1689.2.15 by Brian Aker
Encapsulate the key cache object in myisam.
53
  flush_key_blocks(share->getKeyCache(), share->kfile, FLUSH_IGNORE_CHANGED);
30 by Brian Aker
Large file and ftruncate() support
54
  if (ftruncate(info->dfile, 0) || ftruncate(share->kfile, share->base.keystart))
1 by brian
clean slate
55
    goto err;
398.1.10 by Monty Taylor
Actually removed VOID() this time.
56
  _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
51.1.96 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
57
  return(0);
1 by brian
clean slate
58
59
err:
60
  {
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
61
    int save_errno=errno;
398.1.10 by Monty Taylor
Actually removed VOID() this time.
62
    _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
1 by brian
clean slate
63
    info->update|=HA_STATE_WRITTEN;	/* Buffer changed */
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
64
    return(errno=save_errno);
1 by brian
clean slate
65
  }
66
} /* mi_delete */