Drizzled Public API Documentation

mi_info.cc

00001 /* Copyright (C) 2000-2001, 2003-2004 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 /* Return useful base information for an open table */
00017 
00018 #include "myisam_priv.h"
00019 #include <sys/stat.h>
00020 #include <drizzled/error.h>
00021 
00022 using namespace drizzled;
00023 
00024   /* Get position to last record */
00025 
00026 internal::my_off_t mi_position(MI_INFO *info)
00027 {
00028   return info->lastpos;
00029 }
00030 
00031 
00032 /* Get information about the table */
00033 /* if flag == 2 one get current info (no sync from database */
00034 
00035 int mi_status(MI_INFO *info, register MI_ISAMINFO *x, uint32_t flag)
00036 {
00037   struct stat state;
00038   MYISAM_SHARE *share=info->s;
00039 
00040   x->recpos  = info->lastpos;
00041   if (flag == HA_STATUS_POS)
00042     return(0);        /* Compatible with ISAM */
00043   if (!(flag & HA_STATUS_NO_LOCK))
00044   {
00045     _mi_readinfo(info,F_RDLCK,0);
00046     fast_mi_writeinfo(info);
00047   }
00048   if (flag & HA_STATUS_VARIABLE)
00049   {
00050     x->records    = info->state->records;
00051     x->deleted    = info->state->del;
00052     x->delete_length  = info->state->empty;
00053     x->data_file_length =info->state->data_file_length;
00054     x->index_file_length=info->state->key_file_length;
00055 
00056     x->keys   = share->state.header.keys;
00057     x->check_time = share->state.check_time;
00058     x->mean_reclength= x->records ?
00059       (uint32_t) ((x->data_file_length - x->delete_length) / x->records) :
00060       (uint32_t) share->min_pack_length;
00061   }
00062   if (flag & HA_STATUS_ERRKEY)
00063   {
00064     x->errkey  = info->errkey;
00065     x->dupp_key_pos= info->dupp_key_pos;
00066   }
00067   if (flag & HA_STATUS_CONST)
00068   {
00069     x->reclength  = share->base.reclength;
00070     x->max_data_file_length=share->base.max_data_file_length;
00071     x->max_index_file_length=info->s->base.max_key_file_length;
00072     x->filenr  = info->dfile;
00073     x->options   = share->options;
00074     x->create_time=share->state.create_time;
00075     x->reflength= mi_get_pointer_length(share->base.max_data_file_length, data_pointer_size);
00076     x->record_offset= ((share->options &
00077       (HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)) ?
00078            0L : share->base.pack_reclength);
00079     x->sortkey= -1;       /* No clustering */
00080     x->rec_per_key  = share->state.rec_per_key_part;
00081     x->key_map    = share->state.key_map;
00082     x->data_file_name   = share->data_file_name;
00083     x->index_file_name  = share->index_file_name;
00084   }
00085   if ((flag & HA_STATUS_TIME) && !fstat(info->dfile,&state))
00086     x->update_time=state.st_mtime;
00087   else
00088     x->update_time=0;
00089   if (flag & HA_STATUS_AUTO)
00090   {
00091     x->auto_increment= share->state.auto_increment+1;
00092     if (!x->auto_increment)     /* This shouldn't happen */
00093       x->auto_increment= ~(uint64_t) 0;
00094   }
00095   return(0);
00096 }
00097 
00098 
00099 /*
00100   Write a message to the error log.
00101 
00102   SYNOPSIS
00103     mi_report_error()
00104     file_name                   Name of table file (e.g. index_file_name).
00105     errcode                     Error number.
00106 
00107   DESCRIPTION
00108     This function supplies my_error() with a table name. Most error
00109     messages need one. Since string arguments in error messages are limited
00110     to 64 characters by convention, we ensure that in case of truncation,
00111     that the end of the index file path is in the message. This contains
00112     the most valuable information (the table name and the database name).
00113 
00114   RETURN
00115     void
00116 */
00117 
00118 void mi_report_error(int errcode, const char *file_name)
00119 {
00120   mi_report_error(errcode, file_name);
00121 }
00122 
00123 void mi_report_error(drizzled::error_t errcode, const char *file_name)
00124 {
00125   size_t        lgt;
00126 
00127   if ((lgt= strlen(file_name)) > 64)
00128     file_name+= lgt - 64;
00129   my_error(errcode, MYF(ME_NOREFRESH), file_name);
00130 }
00131