NCBI C Toolkit Cross Reference

C/biostruc/Entrez_active.scr


  1 /*
  2  * $Id: Entrez_active.scr,v 6.6 1999/07/01 21:41:36 kimelman Exp $
  3  * 
  4  * This file contains the additions to PubStruct Database on Public 
  5  * Entrez Servers
  6  *
  7  * $Log: Entrez_active.scr,v $
  8  * Revision 6.6  1999/07/01 21:41:36  kimelman
  9  * post_index fixed to trust user data
 10  * at_insert fixed to keep entry in SatKeyFlags for every row in Struct
 11  *
 12  * Revision 6.5  1999/05/11 21:38:41  kimelman
 13  * bugfix in post_index
 14  *
 15  * Revision 6.4  1999/05/03 14:47:47  kimelman
 16  * spaces
 17  *
 18  * Revision 6.3  1999/04/22 01:50:43  kimelman
 19  * moved 'entrez indexing procs' to _active DB only
 20  *
 21  * Revision 6.2  1999/03/16 16:56:28  kimelman
 22  * new ID fixes
 23  *
 24  * Revision 6.1  1998/07/14 20:24:44  kimelman
 25  * FT schema & smart load
 26  *
 27  * Log: PubStruct_proc.scr,v
 28  * Revision 6.7  1998/06/12 17:45:00  kimelman
 29  * timestamps history fixed, vacuum cleaning debugged
 30  *
 31  * Revision 6.6  1998/06/05 18:19:23  kimelman
 32  * atextract styled
 33  *
 34  * Revision 6.5  1998/06/05 17:59:18  kimelman
 35  * structure takeover bug fixed
 36  */
 37 /************************************************************************/
 38 PRINT '/***** SELECT DATABASE PubStruct                             *****/'
 39 /************************************************************************/
 40 go
 41 USE PubStruct
 42 go
 43 
 44 IF EXISTS (SELECT * FROM sysobjects
 45     WHERE name = 'post_index'
 46     AND   uid = user_id('dbo')
 47     AND   type = 'P')
 48 BEGIN
 49     DROP PROCEDURE dbo.post_index
 50 END
 51 go
 52 
 53 /************************************************************************/
 54 PRINT '/*****           PROCEDURE    post_index                     *****/'
 55 /************************************************************************/
 56 go
 57 
 58 create proc
 59 post_index ( @index_key int, @minutes int = null, @enforce int = 0 )
 60 as
 61   declare @acc int
 62   declare @date datetime
 63   declare @mod_date  datetime
 64   declare @emod_date datetime
 65   declare @mmdb_id        int
 66 
 67   if ( @minutes is null )
 68     select @date = getdate()
 69   else
 70     begin
 71         select @date = dateadd(minute,@minutes,'Jan 1 1900')
 72         if ( @date < getdate() and @enforce = 0 )
 73           begin
 74             /* we come to this case only if we update mmdb entry or just reindex it */
 75             /* make sure the date we got is the same we sent to e2index */
 76             select @mmdb_id= mmdb_id
 77             from   Struct
 78             where  acc = @index_key
 79             
 80             select @mod_date=min(date)
 81             from   Struct s
 82             where  s.state = 0 and s.mmdb_id = @mmdb_id 
 83             
 84             select @emod_date=min(i.date_entrez)
 85             from   Struct s, EntrezControl..SatKeyFlags i
 86             where  s.state = 0 and s.mmdb_id = @mmdb_id 
 87             and s.acc = i.sat_key and i.sat = 10
 88 
 89             select @mod_date=isnull(@emod_date,@mod_date)
 90             /* round time to minutes */
 91             select @minutes = datediff(minute,'Jan 1 1900',@mod_date)
 92             select @mod_date = dateadd(minute,@minutes,'Jan 1 1900')
 93 
 94             if ( @emod_date is not null and @mod_date != @date )
 95               begin
 96                 print "Post_index: error: modification dates incosistence for %1! : db=%2!, entrez=%3! ", @index_key, @mod_date, @date
 97                 return 100
 98               end
 99           end
100     end
101 
102   update EntrezControl..SatKeyFlags
103   set dumped4entrez = 0
104   from EntrezControl..SatKeyFlags i, Struct a, Struct b
105   where i.sat = 10 and i.dumped4entrez = 1 and i.sat_key = a.acc
106     and a.mmdb_id=b.mmdb_id and b.acc = @index_key
107                                  
108   update EntrezControl..SatKeyFlags
109   set dumped4entrez = 1, date_entrez = isnull(date_entrez,@date)
110   where sat = 10 and sat_key = @index_key
111 go
112 
113 /*****        Grant and Revoke permissions post_index               *****/
114 go
115 GRANT EXECUTE ON post_index  TO anyone
116 go
117 
118 
119 /************************************************************************/
120 PRINT '/*****           PROCEDURE    post_remove                    *****/'
121 /************************************************************************/
122 go
123 
124 IF EXISTS (SELECT * FROM sysobjects
125     WHERE name = 'post_remove'
126     AND   uid = user_id('dbo')
127     AND   type = 'P')
128 BEGIN
129     DROP PROCEDURE dbo.post_remove
130 END
131 go
132 create proc
133 post_remove(@index_key int) as
134   declare @acc  int
135   declare @date datetime
136 
137   update EntrezControl..SatKeyFlags
138   set dumped4entrez = 0
139   from EntrezControl..SatKeyFlags i, Struct a, Struct b
140   where i.sat = 10 and i.dumped4entrez = 1 and i.sat_key = a.acc
141     and a.mmdb_id= @index_key
142 go
143 /*****        Grant and Revoke permissions post_remove              *****/
144 go
145 GRANT EXECUTE ON post_remove  TO anyone
146 go
147 
148 /************************************************************************/
149 PRINT '/*****           TRIGGER  at_insert                         *****/'
150 /************************************************************************/
151 go
152 IF EXISTS (SELECT * FROM sysobjects
153     WHERE name = 'at_insert'
154     AND   uid = user_id('dbo')
155     AND   type = 'TR')
156 BEGIN
157     DROP trigger dbo.at_insert
158 END
159 go
160 
161 create trigger
162 at_insert on Struct for update,insert as
163 begin
164   insert EntrezControl..SatKeyFlags
165   select 10, si.acc,  0, 0, null, 0
166   from  inserted si
167   where not exists (select * from EntrezControl..SatKeyFlags i
168                     where i.sat_key = si.acc and i.sat = 10 )
169 end
170 go
171   
172 /************************************************************************/
173 PRINT '/*****           TRIGGER  at_delete                          *****/'
174 /************************************************************************/
175 go
176 
177 IF EXISTS (SELECT * FROM sysobjects
178     WHERE name = 'at_delete'
179     AND   uid = user_id('dbo')
180     AND   type = 'TR')
181 BEGIN
182     DROP trigger dbo.at_delete
183 END
184 go
185 
186 create trigger
187 at_delete on Struct for delete as
188 begin
189   delete EntrezControl..SatKeyFlags
190   from EntrezControl..SatKeyFlags i, deleted d 
191   where i.sat_key = d.acc and i.sat = 10
192 end
193 go
194 
195 /************************************************************************/
196 PRINT '/*****           PROCEDURE    fill_satinfo                   *****/'
197 /************************************************************************/
198 go
199 IF EXISTS (SELECT * FROM sysobjects
200     WHERE name = 'fill_satinfo'
201     AND   uid = user_id('dbo')
202     AND   type = 'P')
203 BEGIN
204     DROP PROCEDURE dbo.fill_satinfo
205 END
206 go
207 create proc
208 fill_satinfo
209 as
210 begin
211   delete from    EntrezControl..SatKeyFlags
212   where sat = 10
213   
214   insert EntrezControl..SatKeyFlags
215   select 10, acc,  0, 0, date, 1
216   from Struct where state = 0
217   
218   update EntrezControl..SatKeyFlags
219   set dumped4entrez = 1, suppress = 0
220   from Struct s, EntrezControl..SatKeyFlags i
221   where s.state = 0 and i.sat_key = s.acc and i.sat = 10 and s.suppressed = 0 
222 end
223 go
224 
225 /************************************************************************/
226 PRINT '/*****           DONE!!!!                                   *****/'
227 /************************************************************************/
228 go

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.