~drizzle-trunk/drizzle/development

1 by brian
clean slate
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
/* Return useful base information for an open table */
17
18
#include "myisamdef.h"
19
#ifdef	__WIN__
20
#include <sys/stat.h>
21
#endif
22
23
	/* Get position to last record */
24
25
my_off_t mi_position(MI_INFO *info)
26
{
27
  return info->lastpos;
28
}
29
30
31
/* Get information about the table */
32
/* if flag == 2 one get current info (no sync from database */
33
482 by Brian Aker
Remove uint.
34
int mi_status(MI_INFO *info, register MI_ISAMINFO *x, uint32_t flag)
1 by brian
clean slate
35
{
15 by brian
Fix for stat, NETWARE removal
36
  struct stat state;
1 by brian
clean slate
37
  MYISAM_SHARE *share=info->s;
38
39
  x->recpos  = info->lastpos;
40
  if (flag == HA_STATUS_POS)
51.1.100 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
41
    return(0);				/* Compatible with ISAM */
1 by brian
clean slate
42
  if (!(flag & HA_STATUS_NO_LOCK))
43
  {
44
    pthread_mutex_lock(&share->intern_lock);
398.1.10 by Monty Taylor
Actually removed VOID() this time.
45
    _mi_readinfo(info,F_RDLCK,0);
1 by brian
clean slate
46
    fast_mi_writeinfo(info);
47
    pthread_mutex_unlock(&share->intern_lock);
48
  }
49
  if (flag & HA_STATUS_VARIABLE)
50
  {
51
    x->records	 	= info->state->records;
52
    x->deleted	 	= info->state->del;
53
    x->delete_length	= info->state->empty;
54
    x->data_file_length	=info->state->data_file_length;
55
    x->index_file_length=info->state->key_file_length;
56
57
    x->keys	 	= share->state.header.keys;
58
    x->check_time	= share->state.check_time;
59
    x->mean_reclength= x->records ?
304 by Brian Aker
ulong cleanup, remove log code from myisam.
60
      (uint32_t) ((x->data_file_length - x->delete_length) / x->records) :
61
      (uint32_t) share->min_pack_length;
1 by brian
clean slate
62
  }
63
  if (flag & HA_STATUS_ERRKEY)
64
  {
65
    x->errkey	 = info->errkey;
66
    x->dupp_key_pos= info->dupp_key_pos;
67
  }
68
  if (flag & HA_STATUS_CONST)
69
  {
70
    x->reclength	= share->base.reclength;
71
    x->max_data_file_length=share->base.max_data_file_length;
72
    x->max_index_file_length=info->s->base.max_key_file_length;
73
    x->filenr	 = info->dfile;
74
    x->options	 = share->options;
75
    x->create_time=share->state.create_time;
76
    x->reflength= mi_get_pointer_length(share->base.max_data_file_length,
77
                                        myisam_data_pointer_size);
78
    x->record_offset= ((share->options &
79
			(HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)) ?
80
		       0L : share->base.pack_reclength);
81
    x->sortkey= -1;				/* No clustering */
82
    x->rec_per_key	= share->state.rec_per_key_part;
83
    x->key_map	 	= share->state.key_map;
84
    x->data_file_name   = share->data_file_name;
85
    x->index_file_name  = share->index_file_name;
86
  }
15 by brian
Fix for stat, NETWARE removal
87
  if ((flag & HA_STATUS_TIME) && !fstat(info->dfile,&state))
1 by brian
clean slate
88
    x->update_time=state.st_mtime;
89
  else
90
    x->update_time=0;
91
  if (flag & HA_STATUS_AUTO)
92
  {
93
    x->auto_increment= share->state.auto_increment+1;
94
    if (!x->auto_increment)			/* This shouldn't happen */
151 by Brian Aker
Ulonglong to uint64_t
95
      x->auto_increment= ~(uint64_t) 0;
1 by brian
clean slate
96
  }
51.1.100 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
97
  return(0);
1 by brian
clean slate
98
}
99
100
101
/*
102
  Write a message to the error log.
103
104
  SYNOPSIS
105
    mi_report_error()
106
    file_name                   Name of table file (e.g. index_file_name).
107
    errcode                     Error number.
108
109
  DESCRIPTION
110
    This function supplies my_error() with a table name. Most error
111
    messages need one. Since string arguments in error messages are limited
112
    to 64 characters by convention, we ensure that in case of truncation,
113
    that the end of the index file path is in the message. This contains
114
    the most valuable information (the table name and the database name).
115
116
  RETURN
117
    void
118
*/
119
120
void mi_report_error(int errcode, const char *file_name)
121
{
122
  size_t        lgt;
123
124
  if ((lgt= strlen(file_name)) > 64)
125
    file_name+= lgt - 64;
126
  my_error(errcode, MYF(ME_NOREFRESH), file_name);
51.1.100 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
127
  return;
1 by brian
clean slate
128
}
129