crind.c
上传用户:dgyhgb
上传日期:2007-01-07
资源大小:676k
文件大小:4k
源码类别:

SQL Server

开发平台:

Unix_Linux

  1. /*
  2.  *  crind.c  - create some DB table index
  3.  *              Kernel of GNU SQL-server  
  4.  *
  5.  * This file is a part of GNU SQL Server
  6.  *
  7.  *  Copyright (c) 1996, 1997, Free Software Foundation, Inc
  8.  *  Developed at the Institute of System Programming
  9.  *  This file is written by  Vera Ponomarenko
  10.  *
  11.  *  This program is free software; you can redistribute it and/or modify
  12.  *  it under the terms of the GNU General Public License as published by
  13.  *  the Free Software Foundation; either version 2 of the License, or
  14.  *  (at your option) any later version.
  15.  *
  16.  *  This program is distributed in the hope that it will be useful,
  17.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  *  GNU General Public License for more details.
  20.  *
  21.  *  You should have received a copy of the GNU General Public License
  22.  *  along with this program; if not, write to the Free Software
  23.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  24.  *
  25.  *  Contacts:   gss@ispras.ru
  26.  *
  27.  */
  28. /* $Id: crind.c,v 1.247 1997/04/15 11:45:41 vera Exp $ */
  29. #include "xmem.h"
  30. #include "destrn.h"
  31. #include "strml.h"
  32. #include "fdcltrn.h"
  33. extern i4_t ljmsize;
  34. extern struct ADBL adlj;
  35. extern char *pbuflj;
  36. struct ans_cind
  37. crind (struct id_rel *pidrel, i4_t prun, i4_t type, i4_t afsize, u2_t *arfn)
  38. {
  39.   u2_t *a, *b, rcorsize, newsize, disize, fn, dfn;
  40.   char *c, *cort, *nc;
  41.   struct d_r_t *desrel;
  42.   struct d_r_bd *drbd;
  43.   struct des_index *di;
  44.   struct ldesind *desind;
  45.   struct id_rel idr;
  46.   u2_t fnk, corsize, num, sn;
  47.   struct ans_cind ans;
  48.   i4_t n, size;
  49.   struct des_tid tid, ref_tid;
  50.   sn = pidrel->urn.segnum;
  51.   if (sn == NRSNUM)
  52.     {
  53.       ans.cpnci = NDI;
  54.       return (ans);
  55.     }
  56.   if ((ans.cpnci = cont_fir (pidrel, &desrel)) != OK)
  57.     return (ans);
  58.   drbd = &desrel->desrbd;
  59.   fn = drbd->fieldnum;
  60.   if (afsize > fn)
  61.     {
  62.       ans.cpnci = NCF;
  63.       return (ans);
  64.     } 
  65.   for (num = 0, a = arfn; num < afsize; num++)
  66.     {
  67.       fnk = *a++;    
  68.       if (fnk > fn)
  69. {
  70.   ans.cpnci = NCF;
  71.   return (ans);
  72. }
  73.       for (dfn = num + 1; dfn < afsize; dfn++)
  74. if (fnk == arfn [dfn])
  75.   {
  76.     ans.cpnci = NCF;
  77.     return (ans);
  78.   }
  79.     }  
  80.   if ((ans.cpnci = synind (sn, pidrel->urn.obnum)) != OK)
  81.     return (ans);
  82.   tid.tpn = pidrel->pagenum;
  83.   tid.tindex = pidrel->index;
  84.   cort = pbuflj + ljmsize;
  85.   if ((readcort (sn, &tid, cort, &corsize, &ref_tid)) != OK)
  86.     {
  87.       ans.cpnci = NDR;
  88.       return (ans);
  89.     }
  90.   n = uniqnm ();
  91.   dfn = afsize;
  92.   if ((dfn % 2) != 0)
  93.     dfn += 1;
  94.   desind = (struct ldesind *) xmalloc (ldisize + dfn * size2b + rfsize);
  95.   di = (struct des_index *) & desind->ldi;
  96.   di->unindex = n;
  97.   di->kifn = afsize;
  98.   if (prun == PRUN)
  99.     di->kifn |= UNIQ;
  100.   a = (u2_t *) (desind + 1);
  101.   for (b = a + afsize; a < b;)
  102.     *a++ = *arfn++;
  103.   disize = (char *) a - (char *) di;
  104.   rcorsize = getrc (drbd, cort);
  105.   nc = cort + corsize;
  106.   drbd->indnum += 1;
  107.   c = nc;
  108.   size = scscal (cort);
  109.   bcopy (cort, c, size);
  110.   c += size;
  111.   bcopy ((char *) drbd, c, drbdsize);
  112.   c += drbdsize;
  113.   cort += size + drbdsize;
  114.   size = rcorsize - size - drbdsize;
  115.   bcopy (cort, c, size);
  116.   c += size;
  117.   idr = *pidrel;
  118.   if ((ans.cpnci = synlsc (RSC, &idr, NULL, 0, fn, NULL)) != OK)
  119.     return (ans);  
  120.   modmes ();
  121.   crtid (desind, desrel);
  122.   crindci (desind);
  123.   dipack (di, disize, c);
  124.   c += disize;
  125.   if ((newsize = c - nc) < corsize)
  126.     newsize = corsize;
  127.   ans.idinci.irii = *pidrel;
  128.   idr.urn.obnum = RDRNUM;
  129.   wmlj (CRILJ, ljmsize + corsize + newsize, &adlj, &idr, &tid, 0);
  130.   ordmod (sn, RDRNUM, &tid, &ref_tid, corsize, nc, newsize);
  131.   fill_ind (desrel, desind);
  132.   ans.idinci.inii = n;
  133.   BUF_endop ();
  134.   return (ans);
  135. }
  136. void
  137. dipack (struct des_index *di, i4_t disize, char *pnt)
  138. {
  139.   bcopy ((char *) di, pnt, disize);
  140. }