1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
|
/*
* $Id: Entrez.scr,v 6.5 1998/10/26 20:53:43 kimelman Exp $
*
* This file contains the additions to PubStruct Database on Public
* Entrez Servers
*
* $Log: Entrez.scr,v $
* Revision 6.5 1998/10/26 20:53:43 kimelman
* bugfix: timerounding to minutes before comparision and print format fioxes
*
* Revision 6.4 1998/10/05 17:47:03 kimelman
* Fix for dates problem
*
* Revision 6.3 1998/07/27 19:35:57 kimelman
* fresh & full lists 2 index reordered in according to 'entrez' modification dates
*
* Revision 6.2 1998/07/22 22:06:09 kimelman
* Enterez removed list : satkey sat date ==> mmdb
*
* Revision 6.1 1998/07/14 20:24:42 kimelman
* FT schema & smart load
*
* Log: PubStruct_proc.scr,v
* Revision 6.7 1998/06/12 17:45:00 kimelman
* timestamps history fixed, vacuum cleaning debugged
*
* Revision 6.6 1998/06/05 18:19:23 kimelman
* atextract styled
*
* Revision 6.5 1998/06/05 17:59:18 kimelman
* structure takeover bug fixed
*/
/************************************************************************/
PRINT '/***** SELECT DATABASE PubStruct *****/'
/************************************************************************/
go
USE PubStruct
go
IF EXISTS (SELECT * FROM sysobjects
WHERE name = 'id_find_gi'
AND uid = user_id('dbo')
AND type = 'P')
BEGIN
DROP PROCEDURE dbo.id_find_gi
END
go
/************************************************************************/
PRINT '/***** PROCEDURE id_find_gi *****/'
/************************************************************************/
go
create proc
id_find_gi(
@gi int, /* mmdb */
@state tinyint = 0
)
as
declare @acc int
select @acc=acc
from Struct
where mmdb_id = @gi and state = @state and suppressed = 0
if @@rowcount = 0 /* looks to be removed */
select @acc = -1
if @state = 0
begin
declare @acc1 int
select @acc=acc
from Struct s, EntrezControl..SatKeyInfo i(1)
where s.mmdb_id = @gi and s.state = 0 and s.acc = i.sat_key and i.sat = 10 and i. dumped4entrez = 1
if @@rowcount = 0 /* looks to be removed */
select @acc = -1
end
select sat=convert(smallint,10),sat_key=acc,gi_state=convert(tinyint,0)
from Struct
where acc = @acc
go
/***** Grant and Revoke permissions id_find_gi *****/
GRANT EXECUTE ON id_find_gi TO public
go
IF EXISTS (SELECT * FROM sysobjects
WHERE name = 'id_get_asnprop'
AND uid = user_id('dbo')
AND type = 'P')
BEGIN
DROP PROCEDURE dbo.id_get_asnprop
END
go
/************************************************************************/
PRINT '/***** PROCEDURE id_get_asnprop *****/'
/************************************************************************/
go
create proc
id_get_asnprop ( @sat_key int)
as
select state=100,confidential, suppress=convert(tinyint,0), override=convert(tinyint,0), length=datalength(blob)
from Struct
where acc = @sat_key
go
/***** Grant and Revoke permissions id_get_asnprop *****/
go
GRANT EXECUTE ON id_get_asnprop TO public
go
IF EXISTS (SELECT * FROM sysobjects
WHERE name = 'id_get_asnblob'
AND uid = user_id('dbo')
AND type = 'P')
BEGIN
DROP PROCEDURE dbo.id_get_asnblob
END
go
/************************************************************************/
PRINT '/***** PROCEDURE id_get_asnblob *****/'
/************************************************************************/
go
create proc
id_get_asnblob ( @sat_key int)
as
select asn=blob
from Struct
where @sat_key = acc
go
/***** Grant and Revoke permissions id_get_asnblob *****/
go
GRANT EXECUTE ON id_get_asnblob TO public
go
IF EXISTS (SELECT * FROM sysobjects
WHERE name = 'id_get_gi_content'
AND uid = user_id('dbo')
AND type = 'P')
BEGIN
DROP PROCEDURE dbo.id_get_gi_content
END
go
/************************************************************************/
PRINT '/***** PROCEDURE id_get_gi_content *****/'
/************************************************************************/
go
create proc
id_get_gi_content(
@sat_key int,
@sat smallint=10
)
as
declare @mod_date datetime
declare @date_entrez datetime
declare @create_date datetime
declare @gi int
declare @pdb_id char(4)
declare @mmdb_id int
if(@sat != 10)
return 100
select @mmdb_id= mmdb_id
from Struct
where acc = @sat_key
select @pdb_id=pdb_id
from pdb
where mmdb_id = @mmdb_id
/* create date */
select @create_date=min(date)
from Struct
where state = 0 and mmdb_id in (select mmdb_id from pdb where pdb_id = @pdb_id)
select @create_date=isnull(min(i.date_entrez),@create_date)
from Struct s, EntrezControl..SatKeyInfo i(1)
where s.state = 0 and s.mmdb_id in (select mmdb_id from pdb where pdb_id = @pdb_id)
and s.acc = i.sat_key and i.sat = 10
/* Modificatio Date */
select @mod_date=min(date)
from Struct s
where s.state = 0 and s.mmdb_id = @mmdb_id
select @mod_date=isnull(min(i.date_entrez),@mod_date)
from Struct s, EntrezControl..SatKeyInfo i(1)
where s.state = 0 and s.mmdb_id = @mmdb_id
and s.acc = i.sat_key and i.sat = 10
/* Entrez Publication Date */
select @date_entrez=min(i.date_entrez)
from Struct s, EntrezControl..SatKeyInfo i(1)
where s.mmdb_id = @mmdb_id and s.state = 0 and s.acc = i.sat_key and i.sat = 10
and i.date_entrez is not null
select gi =@mmdb_id,
create_date=@create_date,
mod_date =@mod_date,
entrez_date=@date_entrez
return 0
go
/***** Grant and Revoke permissions id_get_gi_content *****/
go
GRANT EXECUTE ON id_get_gi_content TO public
go
IF EXISTS (SELECT * FROM sysobjects
WHERE name = 'id_get_asn'
AND uid = user_id('dbo')
AND type = 'P')
BEGIN
DROP PROCEDURE dbo.id_get_asn
END
go
/************************************************************************/
PRINT '/***** PROCEDURE id_get_asn *****/'
/************************************************************************/
go
create proc
id_get_asn(
@gi int=0,
@sat_key int=0,
@sat smallint=0,
@maxplex int=0,
@outfmt int=0
)
as
if(@sat != 10)
return 100
if(@outfmt !=100 and @outfmt != 0)
return 100
if(@sat_key=0)
begin
select @sat_key = acc
from Struct s, EntrezControl..SatKeyInfo i(1)
where mmdb_id = @gi and state = 0 and s.acc = i.sat_key and i.sat = 10 and i.dumped4entrez =1
if(@@rowcount = 0)
return 100
end
exec id_get_asnprop @sat_key
exec id_get_asnblob @sat_key
if(@outfmt=100)
exec id_get_gi_content @sat_key,@sat
return 0
go
/***** Grant and Revoke permissions id_get_asn *****/
go
GRANT EXECUTE ON id_get_asn TO public
go
IF EXISTS (SELECT * FROM sysobjects
WHERE name = 'post_index'
AND uid = user_id('dbo')
AND type = 'P')
BEGIN
DROP PROCEDURE dbo.post_index
END
go
/************************************************************************/
PRINT '/***** PROCEDURE post_index *****/'
/************************************************************************/
go
create proc
post_index(@index_key int, @minutes int = null)
as
declare @acc int
declare @date datetime
declare @mod_date datetime
declare @mmdb_id int
if ( @minutes is null )
select @date = getdate()
else
begin
select @date = dateadd(minute,@minutes,'Jan 1 1900')
if ( @date < getdate() )
begin
/* we come to this cased only if we update mmdb entry or just reindex it */
/* make sure the date we got is the same we sent to e2index */
select @mmdb_id= mmdb_id
from Struct
where acc = @index_key
select @mod_date=min(date)
from Struct s
where s.state = 0 and s.mmdb_id = @mmdb_id
select @mod_date=isnull(min(i.date_entrez),@mod_date)
from Struct s, EntrezControl..SatKeyInfo i(1)
where s.state = 0 and s.mmdb_id = @mmdb_id
and s.acc = i.sat_key and i.sat = 10
/* round time to minutes */
select @minutes = datediff(minute,'Jan 1 1900',@mod_date)
select @mod_date = dateadd(minute,@minutes,'Jan 1 1900')
if ( @mod_date is not null and @mod_date != @date )
begin
print "Post_index: modification dates incosistence: db=%1!, entrez=%2! ", @mod_date, @date
return 100
end
select @date = getdate()
end
end
update EntrezControl..SatKeyInfo
set dumped4entrez = 0
from EntrezControl..SatKeyInfo i, Struct a, Struct b
where i.sat = 10 and i.dumped4entrez != 1 and i.sat_key = a.acc
and a.mmdb_id=b.mmdb_id and b.acc = @index_key
update EntrezControl..SatKeyInfo
set dumped4entrez = 1, date_entrez = isnull(date_entrez,@date)
where sat = 10 and sat_key = @index_key
go
/***** Grant and Revoke permissions post_index *****/
go
GRANT EXECUTE ON post_index TO anyone
go
IF EXISTS (SELECT * FROM sysobjects
WHERE name = 'post_remove'
AND uid = user_id('dbo')
AND type = 'P')
BEGIN
DROP PROCEDURE dbo.post_remove
END
go
/************************************************************************/
PRINT '/***** PROCEDURE post_remove *****/'
/************************************************************************/
go
create proc
post_remove(@index_key int) as
declare @acc int
declare @date datetime
update EntrezControl..SatKeyInfo
set dumped4entrez = 0
from EntrezControl..SatKeyInfo i(1), Struct a, Struct b
where i.sat = 10 and i.dumped4entrez = 1 and i.sat_key = a.acc
and a.mmdb_id= @index_key
go
/***** Grant and Revoke permissions post_remove *****/
go
GRANT EXECUTE ON post_remove TO anyone
go
IF EXISTS (SELECT * FROM sysobjects
WHERE name = 'list2index'
AND uid = user_id('dbo')
AND type = 'P')
BEGIN
DROP PROCEDURE dbo.list2index
END
go
/************************************************************************/
PRINT '/***** PROCEDURE list2index *****/'
/************************************************************************/
go
create proc
list2index(@full int = 0)
as
begin
if (@full = 1)
begin
select 'fresh ' , s.acc, '10', mod_date=datediff(minute,'Jan 1 1900', isnull(min(i.date_entrez),min(s1.date)))
from Struct s, Struct s1, EntrezControl..SatKeyInfo i(1), EntrezControl..SatKeyInfo i1(1)
where s.state = 0 and s.suppressed = 0 and i1.sat_key = s.acc and i1.sat=10 and i1.date_entrez is null
and s1.state = 0 and s.mmdb_id = s1.mmdb_id and i.sat_key = s1.acc and i.sat=10
group by s.acc
order by mod_date,s.acc
end
else if(@full = -1)
begin
select 'removed ', mmdb_id
from Struct s, EntrezControl..SatKeyInfo i(1)
where state = 0 and suppressed > 0 and i.sat_key = s.acc and i.sat=10 and i.dumped4entrez = 1
and not exists ( select * from Struct b where b.mmdb_id = s.mmdb_id and b.state = 0 and b.suppressed = 0 )
order by mmdb_id
end
else if(@full = 0)
begin
select 'data ' , s.acc, '10', mod_date=datediff(minute,'Jan 1 1900', isnull(min(i.date_entrez),min(s1.date)))
from Struct s, Struct s1, EntrezControl..SatKeyInfo i(1)
where s1.state = 0 and s.mmdb_id = s1.mmdb_id and s.state = 0 and s.suppressed = 0 and
i.sat_key = s1.acc and i.sat=10
group by s.acc
order by mod_date,s.acc
end
end
go
GRANT EXECUTE ON list2index TO anyone
go
IF EXISTS (SELECT * FROM sysobjects
WHERE name = 'vacuum_entrez'
AND uid = user_id('dbo')
AND type = 'P')
BEGIN
DROP PROCEDURE dbo.vacuum_entrez
END
go
/************************************************************************/
PRINT '/***** PROCEDURE vacuum_entrez *****/'
/************************************************************************/
go
create proc
vacuum_entrez(@days int = 0)
as
declare @acc int
declare @obv_date datetime
declare @stamp datetime
/* set the obvilion date */
select @obv_date = dateadd(day,-@days,getdate())
select @stamp = getdate()
select acc
from Struct s, EntrezControl..SatKeyInfo i(1)
where s.state = 0 and i.sat_key = s.acc and i.sat = 10 and s.suppressed >0
and date < @obv_date and datalength(blob) > 0 and i.dumped4entrez = 0
go
GRANT EXECUTE ON vacuum_entrez TO anyone
go
|