~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
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
16
/* Return useful base information for an open table */
17
1130.3.28 by Monty Taylor
Moved heapdef.h and myisamdef.h to *_priv.h for easier filtering for include guard check.
18
#include "myisam_priv.h"
1 by brian
clean slate
19
#include <sys/stat.h>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
20
#include <drizzled/error.h>
1 by brian
clean slate
21
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
22
using namespace drizzled;
23
1 by brian
clean slate
24
	/* Get position to last record */
25
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
26
internal::my_off_t mi_position(MI_INFO *info)
1 by brian
clean slate
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
482 by Brian Aker
Remove uint.
35
int mi_status(MI_INFO *info, register MI_ISAMINFO *x, uint32_t flag)
1 by brian
clean slate
36
{
15 by brian
Fix for stat, NETWARE removal
37
  struct stat state;
1 by brian
clean slate
38
  MYISAM_SHARE *share=info->s;
39
40
  x->recpos  = info->lastpos;
41
  if (flag == HA_STATUS_POS)
51.1.100 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
42
    return(0);				/* Compatible with ISAM */
1 by brian
clean slate
43
  if (!(flag & HA_STATUS_NO_LOCK))
44
  {
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
  }
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 ?
304 by Brian Aker
ulong cleanup, remove log code from myisam.
59
      (uint32_t) ((x->data_file_length - x->delete_length) / x->records) :
60
      (uint32_t) share->min_pack_length;
1 by brian
clean slate
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;
790 by Brian Aker
More myisam plugin conversion.
75
    x->reflength= mi_get_pointer_length(share->base.max_data_file_length, data_pointer_size);
1 by brian
clean slate
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
  }
15 by brian
Fix for stat, NETWARE removal
85
  if ((flag & HA_STATUS_TIME) && !fstat(info->dfile,&state))
1 by brian
clean slate
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 */
151 by Brian Aker
Ulonglong to uint64_t
93
      x->auto_increment= ~(uint64_t) 0;
1 by brian
clean slate
94
  }
51.1.100 by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE
95
  return(0);
1 by brian
clean slate
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
118
void mi_report_error(int errcode, const char *file_name)
119
{
2041.3.13 by Brian Aker
Merge in changes such that we are strict with error type.
120
  mi_report_error(errcode, file_name);
121
}
122
2054.1.2 by Brian Aker
Rename of the Loooongggggg error type over to simply drizzled::error_t
123
void mi_report_error(drizzled::error_t errcode, const char *file_name)
2041.3.13 by Brian Aker
Merge in changes such that we are strict with error type.
124
{
1 by brian
clean slate
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