Drizzled Public API Documentation

mi_delete_all.cc

00001 /* Copyright (C) 2000-2003, 2005 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00015 
00016 /* Remove all rows from a MyISAM table */
00017 /* This clears the status information and truncates files */
00018 
00019 #include "myisam_priv.h"
00020 
00021 int mi_delete_all_rows(MI_INFO *info)
00022 {
00023   uint32_t i;
00024   MYISAM_SHARE *share=info->s;
00025   MI_STATE_INFO *state=&share->state;
00026 
00027   if (share->options & HA_OPTION_READ_ONLY_DATA)
00028   {
00029     return(errno=EACCES);
00030   }
00031   if (_mi_readinfo(info,F_WRLCK,1))
00032     return(errno);
00033   if (_mi_mark_file_changed(info))
00034     goto err;
00035 
00036   info->state->records=info->state->del=state->split=0;
00037   state->dellink = HA_OFFSET_ERROR;
00038   state->sortkey=  UINT16_MAX;
00039   info->state->key_file_length=share->base.keystart;
00040   info->state->data_file_length=0;
00041   info->state->empty=info->state->key_empty=0;
00042   info->state->checksum=0;
00043 
00044   for (i=share->base.max_key_block_length/MI_MIN_KEY_BLOCK_LENGTH ; i-- ; )
00045     state->key_del[i]= HA_OFFSET_ERROR;
00046   for (i=0 ; i < share->base.keys ; i++)
00047     state->key_root[i]= HA_OFFSET_ERROR;
00048 
00049   /*
00050     If we are using delayed keys or if the user has done changes to the tables
00051     since it was locked then there may be key blocks in the key cache
00052   */
00053   flush_key_blocks(share->getKeyCache(), share->kfile, FLUSH_IGNORE_CHANGED);
00054   if (ftruncate(info->dfile, 0) || ftruncate(share->kfile, share->base.keystart))
00055     goto err;
00056   _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
00057   return(0);
00058 
00059 err:
00060   {
00061     int save_errno=errno;
00062     _mi_writeinfo(info,WRITEINFO_UPDATE_KEYFILE);
00063     info->update|=HA_STATE_WRITTEN; /* Buffer changed */
00064     return(errno=save_errno);
00065   }
00066 } /* mi_delete */