1/* Copyright (C) 2006 MySQL AB & MySQL Finland AB & TCX DataKonsult 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 Street, Fifth Floor, Boston, MA 02111-1301 USA */
15
16/* Return useful base information for an open table */
17
18#include "maria_def.h"
19#ifdef __WIN__
20#include <sys/stat.h>
21#endif
22
23 /* Get position to last record */
24
25MARIA_RECORD_POS maria_position(MARIA_HA *info)
26{
27 return info->cur_row.lastpos;
28}
29
30
31uint maria_max_key_length()
32{
33 uint tmp= (_ma_max_key_length() - 8 - HA_MAX_KEY_SEG*3);
34 return MY_MIN(HA_MAX_KEY_LENGTH, tmp);
35}
36
37/* Get information about the table */
38/* if flag == 2 one get current info (no sync from database */
39
40int maria_status(MARIA_HA *info, register MARIA_INFO *x, uint flag)
41{
42 MY_STAT state;
43 MARIA_SHARE *share= info->s;
44 DBUG_ENTER("maria_status");
45 DBUG_PRINT("info", ("records: %lld", info->state->records));
46
47 x->recpos= info->cur_row.lastpos;
48 if (flag == HA_STATUS_POS)
49 DBUG_RETURN(0); /* Compatible with ISAM */
50 if (!(flag & HA_STATUS_NO_LOCK))
51 {
52 mysql_mutex_lock(&share->intern_lock);
53 _ma_readinfo(info,F_RDLCK,0);
54 fast_ma_writeinfo(info);
55 mysql_mutex_unlock(&share->intern_lock);
56 }
57 if (flag & HA_STATUS_VARIABLE)
58 {
59 x->records = info->state->records;
60 x->deleted = share->state.state.del;
61 x->delete_length = share->state.state.empty;
62 x->data_file_length = share->state.state.data_file_length;
63 x->index_file_length= share->state.state.key_file_length;
64
65 x->keys = share->state.header.keys;
66 x->check_time = share->state.check_time;
67 x->mean_reclength = x->records ?
68 (ulong) ((x->data_file_length - x->delete_length) /x->records) :
69 (ulong) share->min_pack_length;
70 }
71 if (flag & HA_STATUS_ERRKEY)
72 {
73 x->errkey= info->errkey;
74 x->dup_key_pos= info->dup_key_pos;
75 }
76 if (flag & HA_STATUS_CONST)
77 {
78 x->reclength = share->base.reclength;
79 x->max_data_file_length=share->base.max_data_file_length;
80 x->max_index_file_length=info->s->base.max_key_file_length;
81 x->filenr = info->dfile.file;
82 x->options = share->options;
83 x->create_time=share->state.create_time;
84 x->reflength= maria_get_pointer_length(share->base.max_data_file_length,
85 maria_data_pointer_size);
86 x->record_offset= (info->s->data_file_type == STATIC_RECORD ?
87 share->base.pack_reclength: 0);
88 x->sortkey= -1; /* No clustering */
89 x->rec_per_key = share->state.rec_per_key_part;
90 x->key_map = share->state.key_map;
91 x->data_file_name = share->data_file_name.str;
92 x->index_file_name = share->index_file_name.str;
93 x->data_file_type = share->data_file_type;
94 }
95 if ((flag & HA_STATUS_TIME) && !my_fstat(info->dfile.file, &state, MYF(0)))
96 x->update_time=state.st_mtime;
97 else
98 x->update_time=0;
99 if (flag & HA_STATUS_AUTO)
100 {
101 x->auto_increment= share->state.auto_increment+1;
102 if (!x->auto_increment) /* This shouldn't happen */
103 x->auto_increment= ~(ulonglong) 0;
104 }
105 DBUG_RETURN(0);
106}
107
108
109/*
110 Write a message to the error log.
111
112 SYNOPSIS
113 _ma_report_error()
114 file_name Name of table file (e.g. index_file_name).
115 errcode Error number.
116
117 DESCRIPTION
118 This function supplies my_error() with a table name. Most error
119 messages need one. Since string arguments in error messages are limited
120 to 64 characters by convention, we ensure that in case of truncation,
121 that the end of the index file path is in the message. This contains
122 the most valuable information (the table name and the database name).
123
124 RETURN
125 void
126*/
127
128void _ma_report_error(int errcode, const LEX_STRING *name)
129{
130 size_t length;
131 const char *file_name= name->str;
132 DBUG_ENTER("_ma_report_error");
133 DBUG_PRINT("enter",("errcode %d, table '%s'", errcode, file_name));
134
135 if ((length= name->length) > 64)
136 {
137 /* we first remove the directory */
138 size_t dir_length= dirname_length(file_name);
139 file_name+= dir_length;
140 if ((length-= dir_length) > 64)
141 {
142 /* still too long, chop start of table name */
143 file_name+= length - 64;
144 }
145 }
146
147 my_error(errcode, MYF(ME_NOREFRESH), file_name);
148 DBUG_VOID_RETURN;
149}
150