summaryrefslogtreecommitdiff
path: root/myisammrg
diff options
context:
space:
mode:
Diffstat (limited to 'myisammrg')
-rw-r--r--myisammrg/.cvsignore3
-rw-r--r--myisammrg/Makefile.am31
-rwxr-xr-xmyisammrg/make-ccc3
-rw-r--r--myisammrg/mymrgdef.h29
-rw-r--r--myisammrg/myrg_close.c40
-rw-r--r--myisammrg/myrg_create.c61
-rw-r--r--myisammrg/myrg_delete.c30
-rw-r--r--myisammrg/myrg_extra.c46
-rw-r--r--myisammrg/myrg_info.c59
-rw-r--r--myisammrg/myrg_locking.c35
-rw-r--r--myisammrg/myrg_open.c139
-rw-r--r--myisammrg/myrg_panic.c47
-rw-r--r--myisammrg/myrg_rrnd.c110
-rw-r--r--myisammrg/myrg_rsame.c30
-rw-r--r--myisammrg/myrg_static.c26
-rw-r--r--myisammrg/myrg_update.c26
16 files changed, 715 insertions, 0 deletions
diff --git a/myisammrg/.cvsignore b/myisammrg/.cvsignore
new file mode 100644
index 00000000000..e9955884756
--- /dev/null
+++ b/myisammrg/.cvsignore
@@ -0,0 +1,3 @@
+.deps
+Makefile
+Makefile.in
diff --git a/myisammrg/Makefile.am b/myisammrg/Makefile.am
new file mode 100644
index 00000000000..e51b9b52faf
--- /dev/null
+++ b/myisammrg/Makefile.am
@@ -0,0 +1,31 @@
+# Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+INCLUDES = @MT_INCLUDES@ -I$(srcdir)/../include -I../include
+pkglib_LIBRARIES = libmyisammrg.a
+noinst_HEADERS = mymrgdef.h
+libmyisammrg_a_SOURCES = myrg_open.c myrg_extra.c myrg_info.c myrg_locking.c \
+ myrg_rrnd.c myrg_update.c myrg_delete.c myrg_rsame.c \
+ myrg_panic.c myrg_close.c myrg_create.c myrg_static.c
+
+OMIT_DEPENDENCIES = pthread.h stdio.h __stdio.h stdlib.h __stdlib.h math.h\
+ __math.h time.h __time.h unistd.h __unistd.h types.h \
+ xtypes.h ac-types.h posix.h string.h __string.h \
+ errno.h socket.h inet.h dirent.h netdb.h \
+ cleanup.h cond.h debug_out.h fd.h kernel.h mutex.h \
+ prio_queue.h pthread_attr.h pthread_once.h queue.h\
+ sleep.h specific.h version.h pwd.h timers.h uio.h \
+ cdefs.h machdep.h signal.h __signal.h util.h
diff --git a/myisammrg/make-ccc b/myisammrg/make-ccc
new file mode 100755
index 00000000000..a7e3dfc3cdb
--- /dev/null
+++ b/myisammrg/make-ccc
@@ -0,0 +1,3 @@
+ccc -I./../include -I../include -DDBUG_OFF -fast -O3 -c myrg_close.c myrg_create.c myrg_delete.c myrg_extra.c myrg_info.c myrg_locking.c myrg_open.c myrg_panic.c myrg_rrnd.c myrg_rsame.c myrg_static.c myrg_update.c
+rm libmyisammrg.a
+ar -cr libmyisammrg.a myrg_close.o
diff --git a/myisammrg/mymrgdef.h b/myisammrg/mymrgdef.h
new file mode 100644
index 00000000000..794104fd8c8
--- /dev/null
+++ b/myisammrg/mymrgdef.h
@@ -0,0 +1,29 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/* This file is included by all myisam-merge files */
+
+#ifndef N_MAXKEY
+#include "../myisam/myisamdef.h"
+#endif
+
+#include "myisammrg.h"
+
+extern LIST *myrg_open_list;
+
+#ifdef THREAD
+extern pthread_mutex_t THR_LOCK_open;
+#endif
diff --git a/myisammrg/myrg_close.c b/myisammrg/myrg_close.c
new file mode 100644
index 00000000000..0b9acd921ae
--- /dev/null
+++ b/myisammrg/myrg_close.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/* close a isam-database */
+
+#include "mymrgdef.h"
+
+int myrg_close(info)
+register MYRG_INFO *info;
+{
+ int error=0,new_error;
+ MYRG_TABLE *file;
+ DBUG_ENTER("myrg_close");
+
+ for (file=info->open_tables ; file != info->end_table ; file++)
+ if ((new_error=mi_close(file->table)))
+ error=new_error;
+ pthread_mutex_lock(&THR_LOCK_open);
+ myrg_open_list=list_delete(myrg_open_list,&info->open_list);
+ pthread_mutex_unlock(&THR_LOCK_open);
+ my_free((gptr) info,MYF(0));
+ if (error)
+ {
+ DBUG_RETURN(my_errno=error);
+ }
+ DBUG_RETURN(0);
+}
diff --git a/myisammrg/myrg_create.c b/myisammrg/myrg_create.c
new file mode 100644
index 00000000000..e5f5b988d80
--- /dev/null
+++ b/myisammrg/myrg_create.c
@@ -0,0 +1,61 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/* Create a MYMERGE_-file */
+
+#include "mymrgdef.h"
+
+ /* create file named 'name' and save filenames in it
+ table_names should be NULL or a vector of string-pointers with
+ a NULL-pointer last
+ */
+
+int myrg_create(name,table_names)
+const char *name,**table_names;
+{
+ int save_errno;
+ uint errpos;
+ File file;
+ char buff[FN_REFLEN],*end;
+ DBUG_ENTER("myrg_create");
+
+ errpos=0;
+ if ((file = my_create(fn_format(buff,name,"",MYRG_NAME_EXT,4),0,
+ O_RDWR | O_TRUNC,MYF(MY_WME))) < 0)
+ goto err;
+ errpos=1;
+ if (table_names)
+ for ( ; *table_names ; table_names++)
+ {
+ strmov(buff,*table_names);
+ fn_same(buff,name,4);
+ *(end=strend(buff))='\n';
+ if (my_write(file,*table_names,(uint) (end-buff+1),
+ MYF(MY_WME | MY_NABP)))
+ goto err;
+ }
+ if (my_close(file,MYF(0)))
+ goto err;
+ DBUG_RETURN(0);
+
+err:
+ save_errno=my_errno ? my_errno : -1;
+ switch (errpos) {
+ case 1:
+ VOID(my_close(file,MYF(0)));
+ }
+ DBUG_RETURN(my_errno=save_errno);
+} /* myrg_create */
diff --git a/myisammrg/myrg_delete.c b/myisammrg/myrg_delete.c
new file mode 100644
index 00000000000..a470b4876cf
--- /dev/null
+++ b/myisammrg/myrg_delete.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/* Delete last read record */
+
+#include "mymrgdef.h"
+
+int myrg_delete(info,record)
+MYRG_INFO *info;
+const byte *record;
+{
+ if (!info->current_table)
+ {
+ return(my_errno=HA_ERR_NO_ACTIVE_RECORD);
+ }
+ return mi_delete(info->current_table->table,record);
+}
diff --git a/myisammrg/myrg_extra.c b/myisammrg/myrg_extra.c
new file mode 100644
index 00000000000..0927728e2c1
--- /dev/null
+++ b/myisammrg/myrg_extra.c
@@ -0,0 +1,46 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/*
+ Extra functions we want to do with a database
+ - All flags, exept record-cache-flags, are set in all used databases
+ record-cache-flags are set in myrg_rrnd when we are changing database.
+*/
+
+#include "mymrgdef.h"
+
+int myrg_extra(MYRG_INFO *info,enum ha_extra_function function)
+{
+ int error,save_error=0;
+ MYRG_TABLE *file;
+
+ if (function == HA_EXTRA_CACHE)
+ info->cache_in_use=1;
+ else
+ {
+ if (function == HA_EXTRA_NO_CACHE)
+ info->cache_in_use=0;
+ if (function == HA_EXTRA_RESET)
+ {
+ info->current_table=0;
+ info->last_used_table=info->open_tables;
+ }
+ for (file=info->open_tables ; file != info->end_table ; file++)
+ if ((error=mi_extra(file->table,function)))
+ save_error=error;
+ }
+ return save_error;
+}
diff --git a/myisammrg/myrg_info.c b/myisammrg/myrg_info.c
new file mode 100644
index 00000000000..959a34935fd
--- /dev/null
+++ b/myisammrg/myrg_info.c
@@ -0,0 +1,59 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#include "mymrgdef.h"
+
+ulonglong myrg_position(MYRG_INFO *info)
+{
+ MYRG_TABLE *current_table;
+
+ if (!(current_table = info->current_table) &&
+ info->open_tables != info->end_table)
+ current_table = info->open_tables;
+ return current_table ?
+ current_table->table->lastpos + current_table->file_offset :
+ ~(ulonglong) 0;
+}
+
+ /* If flag != 0 one only gets pos of last record */
+
+int myrg_status(MYRG_INFO *info,register MYMERGE_INFO *x,int flag)
+{
+ MYRG_TABLE *current_table;
+ DBUG_ENTER("myrg_status");
+
+ if (!(current_table = info->current_table) &&
+ info->open_tables != info->end_table)
+ current_table = info->open_tables;
+ x->recpos = info->current_table ?
+ info->current_table->table->lastpos + info->current_table->file_offset :
+ (ulong) -1L;
+ if (flag != HA_STATUS_POS)
+ {
+ x->records = info->records;
+ x->deleted = info->del;
+ x->data_file_length = info->data_file_length;
+ x->reclength = info->reclength;
+ if (current_table)
+ x->errkey = current_table->table->errkey;
+ else
+ { /* No tables in MRG */
+ x->errkey=0;
+ }
+ x->options = info->options;
+ }
+ DBUG_RETURN(0);
+}
diff --git a/myisammrg/myrg_locking.c b/myisammrg/myrg_locking.c
new file mode 100644
index 00000000000..fc03df9bf63
--- /dev/null
+++ b/myisammrg/myrg_locking.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/*
+ Lock databases against read or write.
+*/
+
+#include "mymrgdef.h"
+
+int myrg_lock_database(info,lock_type)
+MYRG_INFO *info;
+int lock_type;
+{
+ int error,new_error;
+ MYRG_TABLE *file;
+
+ error=0;
+ for (file=info->open_tables ; file != info->end_table ; file++)
+ if ((new_error=mi_lock_database(file->table,lock_type)))
+ error=new_error;
+ return(error);
+}
diff --git a/myisammrg/myrg_open.c b/myisammrg/myrg_open.c
new file mode 100644
index 00000000000..0606e0d7d88
--- /dev/null
+++ b/myisammrg/myrg_open.c
@@ -0,0 +1,139 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/* open a MYMERGE_-database */
+
+#include "mymrgdef.h"
+#include <stddef.h>
+#include <errno.h>
+#ifdef VMS
+#include "mrg_static.c"
+#endif
+
+/* open a MYMERGE_-database.
+
+ if handle_locking is 0 then exit with error if some database is locked
+ if handle_locking is 1 then wait if database is locked
+*/
+
+
+MYRG_INFO *myrg_open(name,mode,handle_locking)
+const char *name;
+int mode;
+int handle_locking;
+{
+ int save_errno,i,errpos;
+ uint files,dir_length;
+ ulonglong file_offset;
+ char name_buff[FN_REFLEN*2],buff[FN_REFLEN],*end;
+ MYRG_INFO info,*m_info;
+ FILE *file;
+ MI_INFO *isam,*last_isam;
+ DBUG_ENTER("myrg_open");
+
+ LINT_INIT(last_isam);
+ isam=0;
+ errpos=files=0;
+ bzero((gptr) &info,sizeof(info));
+ if (!(file=my_fopen(fn_format(name_buff,name,"",MYRG_NAME_EXT,4),
+ O_RDONLY | O_SHARE,MYF(0))))
+ goto err;
+ errpos=1;
+ dir_length=dirname_part(name_buff,name);
+ info.reclength=0;
+ while (fgets(buff,FN_REFLEN-1,file))
+ {
+ if ((end=strend(buff))[-1] == '\n')
+ end[-1]='\0';
+ if (buff[0]) /* Skipp empty lines */
+ {
+ last_isam=isam;
+ if (!test_if_hard_path(buff))
+ {
+ VOID(strmake(name_buff+dir_length,buff,
+ sizeof(name_buff)-1-dir_length));
+ VOID(cleanup_dirname(buff,name_buff));
+ }
+ if (!(isam=mi_open(buff,mode,test(handle_locking))))
+ goto err;
+ files++;
+ }
+ last_isam=isam;
+ if (info.reclength && info.reclength != isam->s->base.reclength)
+ {
+ my_errno=HA_ERR_WRONG_IN_RECORD;
+ goto err;
+ }
+ info.reclength=isam->s->base.reclength;
+ }
+ if (!(m_info= (MYRG_INFO*) my_malloc(sizeof(MYRG_INFO)+
+ files*sizeof(MYRG_TABLE),
+ MYF(MY_WME))))
+ goto err;
+ *m_info=info;
+ m_info->open_tables=(MYRG_TABLE *) (m_info+1);
+ m_info->tables=files;
+
+ for (i=files ; i-- > 0 ; )
+ {
+ m_info->open_tables[i].table=isam;
+ m_info->options|=isam->s->options;
+ m_info->records+=isam->state->records;
+ m_info->del+=isam->state->del;
+ m_info->data_file_length=isam->state->data_file_length;
+ if (i)
+ isam=(MI_INFO*) (isam->open_list.next->data);
+ }
+ /* Fix fileinfo for easyer debugging (actually set by rrnd) */
+ file_offset=0;
+ for (i=0 ; (uint) i < files ; i++)
+ {
+ m_info->open_tables[i].file_offset=(my_off_t) file_offset;
+ file_offset+=m_info->open_tables[i].table->state->data_file_length;
+ }
+ if (sizeof(my_off_t) == 4 && file_offset > (ulonglong) (ulong) ~0L)
+ {
+ my_errno=HA_ERR_RECORD_FILE_FULL;
+ my_free((char*) m_info,MYF(0));
+ goto err;
+ }
+
+ m_info->end_table=m_info->open_tables+files;
+ m_info->last_used_table=m_info->open_tables;
+
+ VOID(my_fclose(file,MYF(0)));
+ m_info->open_list.data=(void*) m_info;
+ pthread_mutex_lock(&THR_LOCK_open);
+ myrg_open_list=list_add(myrg_open_list,&m_info->open_list);
+ pthread_mutex_unlock(&THR_LOCK_open);
+ DBUG_RETURN(m_info);
+
+err:
+ save_errno=my_errno;
+ switch (errpos) {
+ case 1:
+ VOID(my_fclose(file,MYF(0)));
+ for (i=files ; i-- > 0 ; )
+ {
+ isam=last_isam;
+ if (i)
+ last_isam=(MI_INFO*) (isam->open_list.next->data);
+ mi_close(isam);
+ }
+ }
+ my_errno=save_errno;
+ DBUG_RETURN (NULL);
+}
diff --git a/myisammrg/myrg_panic.c b/myisammrg/myrg_panic.c
new file mode 100644
index 00000000000..8b6169c896b
--- /dev/null
+++ b/myisammrg/myrg_panic.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#include "mymrgdef.h"
+
+ /* if flag == HA_PANIC_CLOSE then all misam files are closed */
+ /* if flag == HA_PANIC_WRITE then all misam files are unlocked and
+ all changed data in single user misam is written to file */
+ /* if flag == HA_PANIC_READ then all misam files that was locked when
+ mi_panic(HA_PANIC_WRITE) was done is locked. A mi_readinfo() is
+ done for all single user files to get changes in database */
+
+
+int myrg_panic(flag)
+enum ha_panic_function flag;
+{
+ int error=0;
+ LIST *list_element,*next_open;
+ MYRG_INFO *info;
+ DBUG_ENTER("myrg_panic");
+
+ for (list_element=myrg_open_list ; list_element ; list_element=next_open)
+ {
+ next_open=list_element->next; /* Save if close */
+ info=(MYRG_INFO*) list_element->data;
+ if (flag == HA_PANIC_CLOSE && myrg_close(info))
+ error=my_errno;
+ }
+ if (myrg_open_list && flag != HA_PANIC_CLOSE)
+ DBUG_RETURN(mi_panic(flag));
+ if (error)
+ my_errno=error;
+ DBUG_RETURN(error);
+}
diff --git a/myisammrg/myrg_rrnd.c b/myisammrg/myrg_rrnd.c
new file mode 100644
index 00000000000..2e6b8faaa66
--- /dev/null
+++ b/myisammrg/myrg_rrnd.c
@@ -0,0 +1,110 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/*
+ Read a record with random-access. The position to the record must
+ get by myrg_info(). The next record can be read with pos= -1 */
+
+
+#include "mymrgdef.h"
+
+static MYRG_TABLE *find_table(MYRG_TABLE *start,MYRG_TABLE *end,ulonglong pos);
+
+/*
+ If filepos == HA_OFFSET_ERROR, read next
+ Returns same as mi_rrnd:
+ 0 = Ok.
+ HA_ERR_RECORD_DELETED = Record is deleted.
+ HA_ERR_END_OF_FILE = EOF.
+*/
+
+int myrg_rrnd(MYRG_INFO *info,byte *buf,ulonglong filepos)
+{
+ int error;
+ MI_INFO *isam_info;
+
+ if (filepos == HA_OFFSET_ERROR)
+ {
+ if (!info->current_table)
+ {
+ if (info->open_tables == info->end_table)
+ { /* No tables */
+ return (my_errno=HA_ERR_END_OF_FILE);
+ }
+ isam_info=(info->current_table=info->open_tables)->table;
+ if (info->cache_in_use)
+ mi_extra(isam_info,HA_EXTRA_CACHE);
+ filepos=isam_info->s->pack.header_length;
+ isam_info->lastinx= (uint) -1; /* Can't forward or backward */
+ }
+ else
+ {
+ isam_info=info->current_table->table;
+ filepos= isam_info->nextpos;
+ }
+
+ for (;;)
+ {
+ isam_info->update&= HA_STATE_CHANGED;
+ if ((error=(*isam_info->s->read_rnd)(isam_info,(byte*) buf,
+ (my_off_t) filepos,1)) !=
+ HA_ERR_END_OF_FILE)
+ return (error);
+ if (info->cache_in_use)
+ mi_extra(info->current_table->table,HA_EXTRA_NO_CACHE);
+ if (info->current_table+1 == info->end_table)
+ return(HA_ERR_END_OF_FILE);
+ info->current_table++;
+ info->last_used_table=info->current_table;
+ if (info->cache_in_use)
+ mi_extra(info->current_table->table,HA_EXTRA_CACHE);
+ info->current_table->file_offset=
+ info->current_table[-1].file_offset+
+ info->current_table[-1].table->state->data_file_length;
+
+ isam_info=info->current_table->table;
+ filepos=isam_info->s->pack.header_length;
+ isam_info->lastinx= (uint) -1;
+ }
+ }
+ info->current_table=find_table(info->open_tables,
+ info->last_used_table,filepos);
+ isam_info=info->current_table->table;
+ isam_info->update&= HA_STATE_CHANGED;
+ return ((*isam_info->s->read_rnd)(isam_info,(byte*) buf,
+ (ha_rows) (filepos -
+ info->current_table->file_offset),
+ 0));
+}
+
+
+ /* Find which table to use according to file-pos */
+
+static MYRG_TABLE *find_table(MYRG_TABLE *start, MYRG_TABLE *end,
+ ulonglong pos)
+{
+ MYRG_TABLE *mid;
+
+ while (start != end)
+ {
+ mid=start+((uint) (end-start)+1)/2;
+ if (mid->file_offset > pos)
+ end=mid-1;
+ else
+ start=mid;
+ }
+ return start;
+}
diff --git a/myisammrg/myrg_rsame.c b/myisammrg/myrg_rsame.c
new file mode 100644
index 00000000000..301b96e667b
--- /dev/null
+++ b/myisammrg/myrg_rsame.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#include "mymrgdef.h"
+
+int myrg_rsame(MYRG_INFO *info,byte *record,int inx)
+{
+ if (inx) /* not yet used, should be 0 */
+ {
+ return(my_errno=HA_ERR_WRONG_INDEX);
+ }
+ if (!info->current_table)
+ {
+ return(my_errno=HA_ERR_NO_ACTIVE_RECORD);
+ }
+ return mi_rsame(info->current_table->table,record,inx);
+}
diff --git a/myisammrg/myrg_static.c b/myisammrg/myrg_static.c
new file mode 100644
index 00000000000..88eb095382b
--- /dev/null
+++ b/myisammrg/myrg_static.c
@@ -0,0 +1,26 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/*
+ Static variables for pisam library. All definied here for easy making of
+ a shared library
+*/
+
+#ifndef stdin
+#include "mymrgdef.h"
+#endif
+
+LIST *myrg_open_list=0;
diff --git a/myisammrg/myrg_update.c b/myisammrg/myrg_update.c
new file mode 100644
index 00000000000..b75c6ea6f9b
--- /dev/null
+++ b/myisammrg/myrg_update.c
@@ -0,0 +1,26 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/* Update last read record */
+
+#include "mymrgdef.h"
+
+int myrg_update(register MYRG_INFO *info,const byte *oldrec, byte *newrec)
+{
+ if (!info->current_table)
+ return(my_errno=HA_ERR_NO_ACTIVE_RECORD);
+ return mi_update(info->current_table->table,oldrec,newrec);
+}