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