summaryrefslogtreecommitdiff
path: root/merge
diff options
context:
space:
mode:
Diffstat (limited to 'merge')
-rw-r--r--merge/.cvsignore3
-rw-r--r--merge/Makefile.am31
-rw-r--r--merge/_locking.c35
-rw-r--r--merge/close.c41
-rw-r--r--merge/create.c62
-rw-r--r--merge/delete.c29
-rw-r--r--merge/extra.c46
-rw-r--r--merge/info.c60
-rwxr-xr-xmerge/make-ccc3
-rw-r--r--merge/mrgdef.h29
-rw-r--r--merge/open.c138
-rw-r--r--merge/panic.c47
-rw-r--r--merge/rrnd.c110
-rw-r--r--merge/rsame.c36
-rw-r--r--merge/static.c26
-rw-r--r--merge/update.c31
16 files changed, 727 insertions, 0 deletions
diff --git a/merge/.cvsignore b/merge/.cvsignore
new file mode 100644
index 00000000000..e9955884756
--- /dev/null
+++ b/merge/.cvsignore
@@ -0,0 +1,3 @@
+.deps
+Makefile
+Makefile.in
diff --git a/merge/Makefile.am b/merge/Makefile.am
new file mode 100644
index 00000000000..84e23f7cdb0
--- /dev/null
+++ b/merge/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 = libmerge.a
+noinst_HEADERS = mrgdef.h
+libmerge_a_SOURCES = open.c extra.c info.c _locking.c \
+ rrnd.c update.c delete.c rsame.c panic.c \
+ close.c create.c 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/merge/_locking.c b/merge/_locking.c
new file mode 100644
index 00000000000..f90b41e2375
--- /dev/null
+++ b/merge/_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 "mrgdef.h"
+
+int mrg_lock_database(info,lock_type)
+MRG_INFO *info;
+int lock_type;
+{
+ int error,new_error;
+ MRG_TABLE *file;
+
+ error=0;
+ for (file=info->open_tables ; file != info->end_table ; file++)
+ if ((new_error=nisam_lock_database(file->table,lock_type)))
+ error=new_error;
+ return(error);
+}
diff --git a/merge/close.c b/merge/close.c
new file mode 100644
index 00000000000..45aa889ef0c
--- /dev/null
+++ b/merge/close.c
@@ -0,0 +1,41 @@
+/* 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 "mrgdef.h"
+
+int mrg_close(info)
+register MRG_INFO *info;
+{
+ int error=0,new_error;
+ MRG_TABLE *file;
+ DBUG_ENTER("mrg_close");
+
+ for (file=info->open_tables ; file != info->end_table ; file++)
+ if ((new_error=nisam_close(file->table)))
+ error=new_error;
+ pthread_mutex_lock(&THR_LOCK_open);
+ mrg_open_list=list_delete(mrg_open_list,&info->open_list);
+ pthread_mutex_unlock(&THR_LOCK_open);
+ my_free((gptr) info,MYF(0));
+ if (error)
+ {
+ my_errno=error;
+ DBUG_RETURN(-1);
+ }
+ DBUG_RETURN(0);
+}
diff --git a/merge/create.c b/merge/create.c
new file mode 100644
index 00000000000..e7086210237
--- /dev/null
+++ b/merge/create.c
@@ -0,0 +1,62 @@
+/* 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 MERGE-file */
+
+#include "mrgdef.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 mrg_create(name,table_names)
+const char *name,**table_names;
+{
+ int save_errno;
+ uint errpos;
+ File file;
+ char buff[FN_REFLEN],*end;
+ DBUG_ENTER("mrg_create");
+
+ errpos=0;
+ if ((file = my_create(fn_format(buff,name,"",MRG_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;
+ switch (errpos) {
+ case 1:
+ VOID(my_close(file,MYF(0)));
+ }
+ my_errno=save_errno; /* Return right errocode */
+ DBUG_RETURN(-1);
+} /* mrg_create */
diff --git a/merge/delete.c b/merge/delete.c
new file mode 100644
index 00000000000..a4ee46eedc2
--- /dev/null
+++ b/merge/delete.c
@@ -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 */
+
+/* Delete last read record */
+
+#include "mrgdef.h"
+
+int mrg_delete(MRG_INFO *info,const byte *record)
+{
+ if (!info->current_table)
+ {
+ my_errno=HA_ERR_NO_ACTIVE_RECORD;
+ return(-1);
+ }
+ return nisam_delete(info->current_table->table,record);
+}
diff --git a/merge/extra.c b/merge/extra.c
new file mode 100644
index 00000000000..c20241228a2
--- /dev/null
+++ b/merge/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 mrg_rrnd when we are changing database.
+*/
+
+#include "mrgdef.h"
+
+int mrg_extra(info,function)
+MRG_INFO *info;
+enum ha_extra_function function;
+{
+ MRG_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++)
+ nisam_extra(file->table,function);
+ }
+ return 0;
+}
diff --git a/merge/info.c b/merge/info.c
new file mode 100644
index 00000000000..d44ada8e6e6
--- /dev/null
+++ b/merge/info.c
@@ -0,0 +1,60 @@
+/* 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 "mrgdef.h"
+
+ulong mrg_position(MRG_INFO *info)
+{
+ MRG_TABLE *current_table;
+
+ if (!(current_table = info->current_table) &&
+ info->open_tables != info->end_table)
+ current_table = info->open_tables;
+ return (current_table ?
+ (ulong) (current_table->table->lastpos +
+ current_table->file_offset) :
+ ~(ulong) 0);
+}
+
+ /* If flag != 0 one only gets pos of last record */
+
+int mrg_info(MRG_INFO *info,register MERGE_INFO *x,int flag)
+{
+ MRG_TABLE *current_table;
+ DBUG_ENTER("mrg_info");
+
+ 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/merge/make-ccc b/merge/make-ccc
new file mode 100755
index 00000000000..3f37c33638f
--- /dev/null
+++ b/merge/make-ccc
@@ -0,0 +1,3 @@
+ccc -I./../include -I../include -DDBUG_OFF -fast -O3 -c _locking.c close.c create.c delete.c extra.c info.c open.c panic.c rrnd.c rsame.c static.c update.c
+rm libmerge.a
+ar -cr libmerge.a _locking.o
diff --git a/merge/mrgdef.h b/merge/mrgdef.h
new file mode 100644
index 00000000000..3f22c83589a
--- /dev/null
+++ b/merge/mrgdef.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 */
+
+/* Denna fil includeras i alla merge-filer */
+
+#ifndef N_MAXKEY
+#include "../isam/isamdef.h"
+#endif
+
+#include "merge.h"
+
+extern LIST *mrg_open_list;
+
+#ifdef THREAD
+extern pthread_mutex_t THR_LOCK_open;
+#endif
diff --git a/merge/open.c b/merge/open.c
new file mode 100644
index 00000000000..18d3b53fa84
--- /dev/null
+++ b/merge/open.c
@@ -0,0 +1,138 @@
+/* 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 MERGE-database */
+
+#include "mrgdef.h"
+#include <stddef.h>
+#include <errno.h>
+#ifdef VMS
+#include "static.c"
+#endif
+
+/* open a MERGE-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
+*/
+
+
+MRG_INFO *mrg_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;
+ MRG_INFO info,*m_info;
+ FILE *file;
+ N_INFO *isam,*last_isam;
+ DBUG_ENTER("mrg_open");
+
+ LINT_INIT(last_isam);
+ isam=0;
+ errpos=files=0;
+ bzero((gptr) &info,sizeof(info));
+ if (!(file=my_fopen(fn_format(name_buff,name,"",MRG_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=nisam_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= (MRG_INFO*) my_malloc(sizeof(MRG_INFO)+files*sizeof(MRG_TABLE),
+ MYF(MY_WME))))
+ goto err;
+ *m_info=info;
+ m_info->open_tables=(MRG_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->base.options;
+ m_info->records+=isam->s->state.records;
+ m_info->del+=isam->s->state.del;
+ m_info->data_file_length=isam->s->state.data_file_length;
+ if (i)
+ isam=(N_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->s->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);
+ mrg_open_list=list_add(mrg_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=(N_INFO*) (isam->open_list.next->data);
+ nisam_close(isam);
+ }
+ }
+ my_errno=save_errno;
+ DBUG_RETURN (NULL);
+}
diff --git a/merge/panic.c b/merge/panic.c
new file mode 100644
index 00000000000..c3820fe468d
--- /dev/null
+++ b/merge/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 "mrgdef.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
+ nisam_panic(HA_PANIC_WRITE) was done is locked. A ni_readinfo() is
+ done for all single user files to get changes in database */
+
+
+int mrg_panic(flag)
+enum ha_panic_function flag;
+{
+ int error=0;
+ LIST *list_element,*next_open;
+ MRG_INFO *info;
+ DBUG_ENTER("mrg_panic");
+
+ for (list_element=mrg_open_list ; list_element ; list_element=next_open)
+ {
+ next_open=list_element->next; /* Save if close */
+ info=(MRG_INFO*) list_element->data;
+ if (flag == HA_PANIC_CLOSE && mrg_close(info))
+ error=my_errno;
+ }
+ if (mrg_open_list && flag != HA_PANIC_CLOSE)
+ DBUG_RETURN(nisam_panic(flag));
+ if (!error) DBUG_RETURN(0);
+ my_errno=error;
+ DBUG_RETURN(-1);
+}
diff --git a/merge/rrnd.c b/merge/rrnd.c
new file mode 100644
index 00000000000..15a50c0b89f
--- /dev/null
+++ b/merge/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 mrg_info(). The next record can be read with pos= -1 */
+
+
+#include "mrgdef.h"
+
+static MRG_TABLE *find_table(MRG_TABLE *start,MRG_TABLE *end,mrg_off_t pos);
+
+/*
+ If filepos == -1, read next
+ Returns same as nisam_rrnd:
+ 0 = Ok.
+ 1 = Record deleted.
+ -1 = EOF (or something, errno should be HA_ERR_END_OF_FILE)
+*/
+
+int mrg_rrnd(MRG_INFO *info,byte *buf,mrg_off_t filepos)
+{
+ int error;
+ N_INFO *isam_info;
+
+ if (filepos == ~(mrg_off_t) 0) /* Can't use HA_POS_ERROR */
+ {
+ if (!info->current_table)
+ {
+ if (info->open_tables == info->end_table)
+ { /* No tables */
+ my_errno=HA_ERR_END_OF_FILE;
+ return -1;
+ }
+ isam_info=(info->current_table=info->open_tables)->table;
+ if (info->cache_in_use)
+ nisam_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,
+ filepos,1)) >= 0 ||
+ my_errno != HA_ERR_END_OF_FILE)
+ return (error);
+ if (info->cache_in_use)
+ nisam_extra(info->current_table->table,HA_EXTRA_NO_CACHE);
+ if (info->current_table+1 == info->end_table)
+ return(-1);
+ info->current_table++;
+ info->last_used_table=info->current_table;
+ if (info->cache_in_use)
+ nisam_extra(info->current_table->table,HA_EXTRA_CACHE);
+ info->current_table->file_offset=
+ info->current_table[-1].file_offset+
+ info->current_table[-1].table->s->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,
+ (ulong) (filepos -
+ info->current_table->file_offset),
+ 0));
+}
+
+
+ /* Find which table to use according to file-pos */
+
+static MRG_TABLE *find_table(MRG_TABLE *start,MRG_TABLE *end,mrg_off_t pos)
+{
+ MRG_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/merge/rsame.c b/merge/rsame.c
new file mode 100644
index 00000000000..a18f1771c37
--- /dev/null
+++ b/merge/rsame.c
@@ -0,0 +1,36 @@
+/* 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 "mrgdef.h"
+
+
+int mrg_rsame(info,record,inx)
+MRG_INFO *info;
+byte *record;
+int inx; /* not used, should be 0 */
+{
+ if (inx)
+ {
+ my_errno=HA_ERR_WRONG_INDEX;
+ return(-1);
+ }
+ if (!info->current_table)
+ {
+ my_errno=HA_ERR_NO_ACTIVE_RECORD;
+ return(-1);
+ }
+ return nisam_rsame(info->current_table->table,record,inx);
+}
diff --git a/merge/static.c b/merge/static.c
new file mode 100644
index 00000000000..e5f95ef195a
--- /dev/null
+++ b/merge/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 "mrgdef.h"
+#endif
+
+LIST *mrg_open_list=0;
diff --git a/merge/update.c b/merge/update.c
new file mode 100644
index 00000000000..64900b82116
--- /dev/null
+++ b/merge/update.c
@@ -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 */
+
+/* Update last read record */
+
+#include "mrgdef.h"
+
+int mrg_update(info,oldrec,newrec)
+register MRG_INFO *info;
+const byte *oldrec,*newrec;
+{
+ if (!info->current_table)
+ {
+ my_errno=HA_ERR_NO_ACTIVE_RECORD;
+ return(-1);
+ }
+ return nisam_update(info->current_table->table,oldrec,newrec);
+}