drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
mi_info.cc
1/* Copyright (C) 2000-2001, 2003-2004 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15
16/* Return useful base information for an open table */
17
18#include "myisam_priv.h"
19#include <sys/stat.h>
20#include <drizzled/error.h>
21
22using namespace drizzled;
23
24 /* Get position to last record */
25
26internal::my_off_t mi_position(MI_INFO *info)
27{
28 return info->lastpos;
29}
30
31
32/* Get information about the table */
33/* if flag == 2 one get current info (no sync from database */
34
35int mi_status(MI_INFO *info, MI_ISAMINFO *x, uint32_t flag)
36{
37 struct stat state;
38 MYISAM_SHARE *share=info->s;
39
40 x->recpos = info->lastpos;
41 if (flag == HA_STATUS_POS)
42 return(0); /* Compatible with ISAM */
43 if (!(flag & HA_STATUS_NO_LOCK))
44 {
45 _mi_readinfo(info,F_RDLCK,0);
46 fast_mi_writeinfo(info);
47 }
48 if (flag & HA_STATUS_VARIABLE)
49 {
50 x->records = info->state->records;
51 x->deleted = info->state->del;
52 x->delete_length = info->state->empty;
53 x->data_file_length =info->state->data_file_length;
54 x->index_file_length=info->state->key_file_length;
55
56 x->keys = share->state.header.keys;
57 x->check_time = share->state.check_time;
58 x->mean_reclength= x->records ?
59 (uint32_t) ((x->data_file_length - x->delete_length) / x->records) :
60 (uint32_t) share->min_pack_length;
61 }
62 if (flag & HA_STATUS_ERRKEY)
63 {
64 x->errkey = info->errkey;
65 x->dupp_key_pos= info->dupp_key_pos;
66 }
67 if (flag & HA_STATUS_CONST)
68 {
69 x->reclength = share->base.reclength;
70 x->max_data_file_length=share->base.max_data_file_length;
71 x->max_index_file_length=info->s->base.max_key_file_length;
72 x->filenr = info->dfile;
73 x->options = share->options;
74 x->create_time=share->state.create_time;
75 x->reflength= mi_get_pointer_length(share->base.max_data_file_length, data_pointer_size);
76 x->record_offset= ((share->options &
77 (HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)) ?
78 0L : share->base.pack_reclength);
79 x->sortkey= -1; /* No clustering */
80 x->rec_per_key = share->state.rec_per_key_part;
81 x->key_map = share->state.key_map;
82 x->data_file_name = share->data_file_name;
83 x->index_file_name = share->index_file_name;
84 }
85 if ((flag & HA_STATUS_TIME) && !fstat(info->dfile,&state))
86 x->update_time=state.st_mtime;
87 else
88 x->update_time=0;
89 if (flag & HA_STATUS_AUTO)
90 {
91 x->auto_increment= share->state.auto_increment+1;
92 if (!x->auto_increment) /* This shouldn't happen */
93 x->auto_increment= ~(uint64_t) 0;
94 }
95 return(0);
96}
97
98
99/*
100 Write a message to the error log.
101
102 SYNOPSIS
103 mi_report_error()
104 file_name Name of table file (e.g. index_file_name).
105 errcode Error number.
106
107 DESCRIPTION
108 This function supplies my_error() with a table name. Most error
109 messages need one. Since string arguments in error messages are limited
110 to 64 characters by convention, we ensure that in case of truncation,
111 that the end of the index file path is in the message. This contains
112 the most valuable information (the table name and the database name).
113
114 RETURN
115 void
116*/
117
118void mi_report_error(int errcode, const char *file_name)
119{
120 mi_report_error(static_cast<drizzled::error_t>(errcode), file_name);
121}
122
123void mi_report_error(drizzled::error_t errcode, const char *file_name)
124{
125 size_t lgt;
126
127 if ((lgt= strlen(file_name)) > 64)
128 file_name+= lgt - 64;
129 my_error(errcode, MYF(ME_NOREFRESH), file_name);
130}
131
TODO: Rename this file - func.h is stupid.