Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1272 lines
28 KiB

  1. -- Script: uddi.v2.sp.sql
  2. -- Author: [email protected]
  3. -- Description: Creates common stored procedures.
  4. -- Note: This file is best viewed and edited with a tab width of 2.
  5. -- =============================================
  6. -- Section: Configuration routines
  7. -- =============================================
  8. -- =============================================
  9. -- Name: net_config_get
  10. -- =============================================
  11. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_config_get' AND type = 'P')
  12. DROP PROCEDURE net_config_get
  13. GO
  14. CREATE PROCEDURE net_config_get
  15. WITH ENCRYPTION
  16. AS
  17. BEGIN
  18. DECLARE
  19. @error int,
  20. @context nvarchar(4000),
  21. @operatorID bigint,
  22. @businessKey uniqueidentifier,
  23. @name nvarchar(450),
  24. @description nvarchar(4000)
  25. DECLARE @tempConfig TABLE(
  26. [configName] nvarchar(450),
  27. [configValue] nvarchar(4000))
  28. SET @operatorID = CAST(dbo.configValue('OperatorID') AS bigint)
  29. IF @operatorID IS NULL
  30. BEGIN
  31. SET @error = 50014
  32. SET @context = 'OperatorID configuration item not set.'
  33. GOTO errorLabel
  34. END
  35. INSERT @tempConfig (
  36. [configName],
  37. [configValue])
  38. SELECT
  39. [configName],
  40. [configValue]
  41. FROM
  42. [UDO_config]
  43. INSERT @tempConfig (
  44. [configName],
  45. [configValue])
  46. SELECT
  47. 'Operator',
  48. [name]
  49. FROM
  50. [UDO_operators]
  51. WHERE
  52. ([operatorID] = @operatorID)
  53. INSERT @tempConfig (
  54. [configName],
  55. [configValue])
  56. SELECT
  57. 'OperatorKey',
  58. dbo.UUIDSTR([operatorKey])
  59. FROM
  60. [UDO_operators]
  61. WHERE
  62. ([operatorID] = @operatorID)
  63. -- Look up the key for the operational business entity, a.k.a. "Site.Key"
  64. SELECT
  65. @businessKey = [businessKey]
  66. FROM
  67. [UDO_operators]
  68. WHERE
  69. ([operatorID] = @operatorID)
  70. IF (@businessKey IS NULL)
  71. BEGIN
  72. INSERT @tempConfig (
  73. [configName],
  74. [configValue])
  75. VALUES (
  76. 'Site.Key',
  77. 'unspecified')
  78. INSERT @tempConfig (
  79. [configName],
  80. [configValue])
  81. VALUES (
  82. 'Site.Name',
  83. 'unspecified')
  84. INSERT @tempConfig (
  85. [configName],
  86. [configValue])
  87. VALUES (
  88. 'Site.Description',
  89. 'unspecified')
  90. END
  91. ELSE
  92. BEGIN
  93. -- TODO: needs to be language aware as opposed to first item
  94. SELECT TOP 1
  95. @name = [name]
  96. FROM
  97. [UDC_names_BE]
  98. WHERE
  99. ([businessID] = dbo.businessID(@businessKey))
  100. -- TODO: needs to be language aware as opposed to first item
  101. SELECT TOP 1
  102. @description = [description]
  103. FROM
  104. [UDC_businessDesc]
  105. WHERE
  106. ([businessID] = dbo.businessID(@businessKey))
  107. INSERT @tempConfig (
  108. [configName],
  109. [configValue])
  110. VALUES (
  111. 'Site.Key',
  112. dbo.UUIDSTR(@businessKey))
  113. INSERT @tempConfig (
  114. [configName],
  115. [configValue])
  116. VALUES (
  117. 'Site.Name',
  118. ISNULL(@name,'unspecified'))
  119. INSERT @tempConfig (
  120. [configName],
  121. [configValue])
  122. VALUES (
  123. 'Site.Description',
  124. ISNULL(@description,'unspecified'))
  125. END
  126. -- Return results
  127. SELECT
  128. [configName],
  129. [configValue]
  130. FROM
  131. @tempConfig
  132. ORDER BY
  133. 1
  134. RETURN 0
  135. errorLabel:
  136. RAISERROR (@error, 16, 1, @context)
  137. RETURN 1
  138. END -- net_config_get
  139. GO
  140. -- =============================================
  141. -- Name: net_config_save
  142. -- =============================================
  143. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_config_save' AND type = 'P')
  144. DROP PROCEDURE net_config_save
  145. GO
  146. CREATE PROCEDURE net_config_save
  147. @configName nvarchar(450),
  148. @configValue nvarchar(4000)
  149. WITH ENCRYPTION
  150. AS
  151. BEGIN
  152. DECLARE
  153. @error int,
  154. @context nvarchar(4000),
  155. @RC int,
  156. @dateTimeString varchar(8000)
  157. IF @configName NOT IN ('Operator', 'Site.Key')
  158. BEGIN
  159. -- Update configuration item in UDO_config
  160. IF NOT EXISTS(SELECT * FROM [UDO_config] WHERE [configName] = @configName)
  161. INSERT [UDO_config] VALUES(@configName, @configValue)
  162. ELSE
  163. UPDATE [UDO_config] SET [configValue] = @configValue WHERE [configName] = @configName
  164. END
  165. ELSE
  166. BEGIN
  167. -- Derived configuration item. Update elsewhere.
  168. IF @configName = ('Operator')
  169. BEGIN
  170. UPDATE
  171. [UDO_operators]
  172. SET
  173. [name] = LEFT(@configValue, 450)
  174. WHERE
  175. [operatorID] = dbo.currentOperatorID()
  176. END
  177. IF @configName = ('Site.Key')
  178. BEGIN
  179. UPDATE
  180. [UDO_operators]
  181. SET
  182. [businessKey] = CAST(@configValue AS uniqueidentifier)
  183. WHERE
  184. [operatorID] = dbo.currentOperatorID()
  185. END
  186. END
  187. --
  188. -- Update the last change date and time
  189. --
  190. SET @dateTimeString = CONVERT(varchar(8000), GETDATE(), 126) -- Use IS08601 format, e.g. yyyy-mm-dd Thh:mm:ss:mmm
  191. IF NOT EXISTS(SELECT * FROM [UDO_config] WHERE [configName]='LastChange')
  192. INSERT [UDO_config] VALUES('LastChange', @dateTimeString)
  193. ELSE
  194. UPDATE [UDO_config] SET [configValue] = @dateTimeString WHERE [configName] = 'LastChange'
  195. RETURN 0
  196. errorLabel:
  197. RAISERROR (@error, 16, 1, @context)
  198. RETURN 1
  199. END -- net_config_save
  200. GO
  201. -- =============================================
  202. -- Name: net_config_getLastChangeDate
  203. -- =============================================
  204. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_config_getLastChangeDate' AND type = 'P')
  205. DROP PROCEDURE net_config_getLastChangeDate
  206. GO
  207. CREATE PROCEDURE net_config_getLastChangeDate
  208. WITH ENCRYPTION
  209. AS
  210. BEGIN
  211. DECLARE
  212. @error int,
  213. @context nvarchar(4000)
  214. SELECT
  215. [configValue]
  216. FROM
  217. [UDO_config]
  218. WHERE
  219. [configName] = 'LastChange'
  220. RETURN 0
  221. errorLabel:
  222. RAISERROR (@error, 16, 1, @context)
  223. RETURN 1
  224. END -- net_config_getLastChangeDate
  225. GO
  226. -- =============================================
  227. -- Section: Validation shared routines
  228. -- =============================================
  229. -- =============================================
  230. -- Name: net_categoryBag_validate
  231. -- =============================================
  232. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_categoryBag_validate' AND type = 'P')
  233. DROP PROCEDURE net_categoryBag_validate
  234. GO
  235. CREATE PROCEDURE net_categoryBag_validate
  236. @keyValue nvarchar(255),
  237. @tModelKey uniqueidentifier,
  238. @replActive bit = 0
  239. WITH ENCRYPTION
  240. AS
  241. BEGIN
  242. DECLARE
  243. @error int,
  244. @context nvarchar(4000)
  245. -- Validate keyValue
  246. IF @tModelKey IS NULL
  247. BEGIN
  248. SET @error = 60210 -- E_invalidKeyPassed
  249. SET @context = 'tModelKey is required.'
  250. GOTO errorLabel
  251. END
  252. IF @keyValue IS NULL
  253. BEGIN
  254. SET @error = 70100 -- E_categorizationNotAllowed
  255. SET @context = 'keyValue is required.'
  256. GOTO errorLabel
  257. END
  258. IF (dbo.checkedTaxonomy(@tModelKey) = 1) AND (dbo.validTaxonomyValue(@tModelKey, @keyValue) = 0)
  259. BEGIN
  260. SET @error = 70200 -- E_invalidValue
  261. SET @context = 'tModelKey = ' + dbo.addURN(@tModelKey) + ', keyValue = ' + @keyValue
  262. GOTO errorLabel
  263. END
  264. IF @replActive = 0
  265. BEGIN
  266. IF NOT EXISTS(SELECT [tModelKey] FROM [UDC_tModels] WHERE [tModelKey] = @tModelKey)
  267. BEGIN
  268. SET @error = 60210 -- E_invalidKey
  269. SET @context = dbo.addURN(@tModelKey)
  270. GOTO errorLabel
  271. END
  272. END
  273. RETURN 0
  274. errorLabel:
  275. RAISERROR (@error, 16, 1, @context)
  276. RETURN 1
  277. END -- net_categoryBag_validate
  278. GO
  279. -- =============================================
  280. -- Name: net_identifierBag_validate
  281. -- =============================================
  282. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_identifierBag_validate' AND type = 'P')
  283. DROP PROCEDURE net_identifierBag_validate
  284. GO
  285. CREATE PROCEDURE net_identifierBag_validate
  286. @keyValue nvarchar(225),
  287. @tModelKey uniqueidentifier,
  288. @replActive bit = 0
  289. WITH ENCRYPTION
  290. AS
  291. BEGIN
  292. DECLARE
  293. @error int,
  294. @context nvarchar(4000)
  295. -- Validate tModelKey
  296. IF @tModelKey IS NULL
  297. BEGIN
  298. SET @error = 60210 -- E_invalidKeyPassed
  299. SET @context = 'tModelKey is required.'
  300. GOTO errorLabel
  301. END
  302. IF @replActive = 0
  303. BEGIN
  304. IF @tModelKey IS NOT NULL
  305. BEGIN
  306. IF NOT EXISTS(SELECT [tModelKey] FROM [UDC_tModels] WHERE [tModelKey] = @tModelKey)
  307. BEGIN
  308. SET @error = 60210 -- E_invalidKey
  309. SET @context = dbo.addURN(@tModelKey)
  310. GOTO errorLabel
  311. END
  312. IF @tModelKey = dbo.operatorsKey()
  313. BEGIN
  314. SET @error = 60210 -- E_invalidKey
  315. SET @context = 'Only operators may reference the uddi-org:operators tModelKey (' + dbo.configValue('TModelKey.Operators') + ').'
  316. GOTO errorLabel
  317. END
  318. END
  319. END
  320. -- Validate keyValue
  321. IF @keyValue IS NULL
  322. BEGIN
  323. SET @error = 70100 -- E_categorizationNotAllowed
  324. SET @context = 'keyValue is required.'
  325. GOTO errorLabel
  326. END
  327. IF (dbo.checkedTaxonomy(@tModelKey) = 1) AND (dbo.validTaxonomyValue(@tModelKey, @keyValue) = 0)
  328. BEGIN
  329. SET @error = 70200 -- E_invalidValue
  330. SET @context = 'tModelKey = ' + dbo.addURN(@tModelKey) + ', keyValue = ' + @keyValue
  331. GOTO errorLabel
  332. END
  333. RETURN 0
  334. errorLabel:
  335. RAISERROR (@error, 16, 1, @context)
  336. RETURN 1
  337. END -- net_identifierBag_validate
  338. GO
  339. -- =============================================
  340. -- Name: net_keyedReference_validate
  341. -- =============================================
  342. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_keyedReference_validate' AND type = 'P')
  343. DROP PROCEDURE net_keyedReference_validate
  344. GO
  345. CREATE PROCEDURE net_keyedReference_validate
  346. @PUID nvarchar(450),
  347. @keyedRefType int,
  348. @keyValue nvarchar(255),
  349. @tModelKey uniqueidentifier
  350. WITH ENCRYPTION
  351. AS
  352. BEGIN
  353. DECLARE
  354. @RC int,
  355. @error int,
  356. @context nvarchar(4000),
  357. @publisherID bigint,
  358. @operatorID bigint,
  359. @replActive bit
  360. SET @RC=0
  361. -- Validate publisher
  362. SET @publisherID = dbo.publisherID(@PUID)
  363. IF @publisherID IS NULL
  364. BEGIN
  365. SET @operatorID = dbo.currentOperatorID()
  366. SET @replActive = 0
  367. END
  368. ELSE
  369. BEGIN
  370. -- Validate operator / publisher association (replication only)
  371. EXEC @RC=net_pubOperator_get @publisherID, @operatorID OUTPUT, @replActive OUTPUT
  372. IF @RC <> 0
  373. BEGIN
  374. SET @error = 50006 -- E_subProcFailure
  375. SET @context = ''
  376. GOTO errorLabel
  377. END
  378. END
  379. IF (@keyedRefType NOT BETWEEN 1 AND 3)
  380. BEGIN
  381. SET @error = 50009 -- E_parmError
  382. SET @context = '@keyedRefType = ' + CAST(@keyedRefType AS varchar(8000))
  383. GOTO errorLabel
  384. END
  385. IF @keyedRefType = 1 OR @keyedRefType = 3 -- categoryBag or assertion keyedReference
  386. BEGIN
  387. EXEC @RC=net_categoryBag_validate @keyValue, @tModelKey, @replActive
  388. IF @RC <> 0
  389. BEGIN
  390. SET @error = 50006 -- E_subProcFailure
  391. SET @context = ''
  392. GOTO errorLabel
  393. END
  394. END
  395. IF @keyedRefType = 2 -- identifierBag
  396. BEGIN
  397. EXEC @RC=net_identifierBag_validate @keyValue, @tModelKey, @replActive
  398. IF @RC <> 0
  399. BEGIN
  400. SET @error = 50006 -- E_subProcFailure
  401. SET @context = ''
  402. GOTO errorLabel
  403. END
  404. END
  405. RETURN 0
  406. errorLabel:
  407. RAISERROR (@error, 16, 1, @context)
  408. RETURN 1
  409. END -- net_keyedReference_validate
  410. GO
  411. -- =============================================
  412. -- Name: net_key_validate
  413. -- =============================================
  414. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_key_validate' AND type = 'P')
  415. DROP PROCEDURE net_key_validate
  416. GO
  417. CREATE PROCEDURE net_key_validate
  418. @entityTypeID tinyint,
  419. @entityKey uniqueidentifier
  420. WITH ENCRYPTION
  421. AS
  422. BEGIN
  423. DECLARE
  424. @error int,
  425. @context nvarchar(4000)
  426. IF (@entityTypeID NOT BETWEEN 0 AND 3)
  427. BEGIN
  428. SET @error = 50009
  429. SET @context = 'Invalid @entityTypeID parameter value: ' + CAST(@entityTypeid AS varchar(256))
  430. GOTO errorLabel
  431. END
  432. IF dbo.entityExists(@entityKey, @entityTypeID) = 0
  433. BEGIN
  434. SET @error = 60210
  435. SELECT @context =
  436. CASE @entityTypeID
  437. WHEN 0 THEN 'tModelKey = uuid:' + dbo.UUIDSTR(@entityKey)
  438. WHEN 1 THEN 'businessKey = ' + dbo.UUIDSTR(@entityKey)
  439. WHEN 2 THEN 'serviceKey = ' + dbo.UUIDSTR(@entityKey)
  440. WHEN 3 THEN 'bindingKey = ' + dbo.UUIDSTR(@entityKey)
  441. END
  442. GOTO errorLabel
  443. END
  444. RETURN 0
  445. errorLabel:
  446. RAISERROR (@error, 16, 1, @context)
  447. RETURN 1
  448. END -- net_key_validate
  449. GO
  450. -- =============================================
  451. -- Section: General purpose routines
  452. -- =============================================
  453. -- =============================================
  454. -- Section: Shared find routines
  455. -- =============================================
  456. -- =============================================
  457. -- Name: net_find_scratch_commit
  458. -- =============================================
  459. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_find_scratch_commit' AND type = 'P')
  460. DROP PROCEDURE net_find_scratch_commit
  461. GO
  462. CREATE PROCEDURE net_find_scratch_commit
  463. @contextID uniqueidentifier,
  464. @rows int OUTPUT
  465. WITH ENCRYPTION
  466. AS
  467. BEGIN
  468. -- Commits keys in the scratch table to the find results table.
  469. DECLARE
  470. @error int,
  471. @context nvarchar(4000),
  472. @RC int
  473. IF EXISTS(SELECT * FROM [UDS_findResults] WHERE [contextID] = @contextID)
  474. BEGIN
  475. -- UDS_findResults has at least one entry so far
  476. DELETE
  477. [UDS_findResults]
  478. WHERE
  479. ([contextID] = @contextID) AND
  480. ([entityKey] NOT IN (SELECT [entityKey] FROM [UDS_findScratch] WHERE [contextID] = @contextID))
  481. SET @rows = dbo.contextRows(@contextID)
  482. UPDATE
  483. [UDS_findResults]
  484. SET
  485. [subEntityKey] = SC.[subEntityKey]
  486. FROM
  487. [UDS_findResults]
  488. JOIN [UDS_findScratch] SC ON ([UDS_findResults].[entityKey] = SC.[entityKey])
  489. WHERE
  490. ([UDS_findResults].[contextID] = @contextID)
  491. END
  492. ELSE
  493. -- UDS_findResults does not have any entries so far
  494. BEGIN
  495. INSERT [UDS_findResults] (
  496. [contextID],
  497. [entityKey],
  498. [subEntityKey])
  499. SELECT DISTINCT
  500. [contextID],
  501. [entityKey],
  502. [subEntityKey]
  503. FROM
  504. [UDS_findScratch]
  505. WHERE
  506. ([contextID] = @contextID)
  507. SET @rows = dbo.contextRows(@contextID)
  508. END
  509. EXEC @RC=net_findScratch_cleanup @contextID
  510. IF @RC<>0
  511. BEGIN
  512. SET @error = 50006 -- E_subProcFailure
  513. SET @context = ''
  514. GOTO errorLabel
  515. END
  516. RETURN 0
  517. errorLabel:
  518. RAISERROR (@error, 16, 1, @context)
  519. RETURN 1
  520. END -- net_find_scratch_commit
  521. GO
  522. -- =============================================
  523. -- Name: net_find_cleanup
  524. -- =============================================
  525. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_find_cleanup' AND type = 'P')
  526. DROP PROCEDURE net_find_cleanup
  527. GO
  528. CREATE PROCEDURE net_find_cleanup
  529. @contextID uniqueidentifier
  530. WITH ENCRYPTION
  531. AS
  532. BEGIN
  533. -- Cleans up leftover rows in scracth tables
  534. DELETE
  535. [UDS_findResults]
  536. WHERE
  537. ([contextID] = @contextID)
  538. DELETE
  539. [UDS_findScratch]
  540. WHERE
  541. ([contextID] = @contextID)
  542. RETURN 0
  543. END -- net_find_cleanup
  544. GO
  545. -- =============================================
  546. -- Name: net_findScratch_cleanup
  547. -- =============================================
  548. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_findScratch_cleanup' AND type = 'P')
  549. DROP PROCEDURE net_findScratch_cleanup
  550. GO
  551. CREATE PROCEDURE net_findScratch_cleanup
  552. @contextID uniqueidentifier
  553. WITH ENCRYPTION
  554. AS
  555. BEGIN
  556. -- Cleans up leftover rows in scratch table
  557. DELETE
  558. [UDS_findScratch]
  559. WHERE
  560. ([contextID] = @contextID)
  561. RETURN 0
  562. END -- net_findScratch_cleanup
  563. GO
  564. -- =============================================
  565. -- Section: queryLog procedures
  566. -- =============================================
  567. -- =============================================
  568. -- Name: net_queryLog_save
  569. -- =============================================
  570. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_queryLog_save' AND type = 'P')
  571. DROP PROCEDURE net_queryLog_save
  572. GO
  573. CREATE PROCEDURE net_queryLog_save
  574. @contextID uniqueidentifier,
  575. @lastChange bigint,
  576. @entityKey uniqueidentifier = NULL,
  577. @entityTypeID tinyint = NULL,
  578. @contextTypeID tinyint,
  579. @queryTypeID tinyint
  580. WITH ENCRYPTION
  581. AS
  582. BEGIN
  583. DECLARE
  584. @error int,
  585. @context nvarchar(4000)
  586. INSERT [UDO_queryLog] (
  587. [lastChange],
  588. [entityKey],
  589. [entityTypeID],
  590. [queryTypeID],
  591. [contextID],
  592. [contextTypeID])
  593. VALUES (
  594. @lastChange,
  595. @entityKey,
  596. @entityTypeID,
  597. @queryTypeID,
  598. @contextID,
  599. @contextTypeID)
  600. RETURN 0
  601. errorLabel:
  602. RAISERROR (@error, 16, 1, @context)
  603. RETURN 1
  604. END -- net_queryLog_save
  605. GO
  606. -- =============================================
  607. -- Section: Taxonomy routines
  608. -- =============================================
  609. -- =============================================
  610. -- Name: net_taxonomy_get
  611. -- =============================================
  612. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_taxonomy_get' AND type = 'P')
  613. DROP PROCEDURE net_taxonomy_get
  614. GO
  615. CREATE PROCEDURE net_taxonomy_get
  616. @tModelKey uniqueidentifier,
  617. @flag int OUTPUT
  618. WITH ENCRYPTION
  619. AS
  620. BEGIN
  621. DECLARE
  622. @error int,
  623. @context nvarchar(4000)
  624. IF NOT EXISTS(SELECT * FROM [UDT_taxonomies] WHERE [tModelKey] = @tModelKey)
  625. BEGIN
  626. SET @error = 60210
  627. SET @context = 'uuid:' + dbo.UUIDSTR(@tModelKey)
  628. GOTO errorLabel
  629. END
  630. SELECT
  631. @flag = [flag]
  632. FROM
  633. [UDT_taxonomies]
  634. WHERE
  635. ([tModelKey] = @tModelKey)
  636. RETURN 0
  637. errorLabel:
  638. RAISERROR (@error, 16, 1, @context)
  639. RETURN 1
  640. END -- net_taxonomy_get
  641. GO
  642. -- =============================================
  643. -- Name: net_taxonomy_save
  644. -- =============================================
  645. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_taxonomy_save' AND type = 'P')
  646. DROP PROCEDURE net_taxonomy_save
  647. GO
  648. CREATE PROCEDURE net_taxonomy_save
  649. @tModelKey uniqueidentifier,
  650. @flag int,
  651. @taxonomyID bigint = NULL OUTPUT
  652. WITH ENCRYPTION
  653. AS
  654. BEGIN
  655. DECLARE
  656. @error int,
  657. @context nvarchar(4000),
  658. @RC int
  659. -- Validate parameters
  660. IF @flag NOT IN(0,1,2,3)--all valid values
  661. BEGIN
  662. -- flag 0x1 = checkedTaxonomy
  663. -- flag 0x2 = browsable taxonomy
  664. SET @error = 50009 -- E_parmError
  665. SET @context = CAST(@flag AS varchar(256)) + ' is not a valid categorization scheme flag.'
  666. GOTO errorLabel
  667. END
  668. IF NOT EXISTS(SELECT * FROM [UDC_tModels] WHERE [tModelKey] = @tModelKey)
  669. BEGIN
  670. SET @error = 60210 -- E_invalidKeyPassed
  671. SET @context = dbo.UUIDSTR(@tModelKey) + ' is not a valid tModelKey.'
  672. GOTO errorLabel
  673. END
  674. IF EXISTS(SELECT * FROM [UDT_taxonomies] WHERE [tModelKey] = @tModelKey)
  675. BEGIN
  676. --
  677. -- Fix for Windows Bug #733233
  678. -- Delete existing taxonomy instead of throwing an E_invalidKey
  679. --
  680. -- SET @error = 60210 -- E_invalidKeyPassed
  681. -- SET @context = 'A categorization scheme already exists for tModelKey = ' + dbo.UUIDSTR(@tModelKey)
  682. -- GOTO errorLabel
  683. EXEC @RC = net_taxonomy_delete @tModelKey
  684. IF @RC <> 0
  685. BEGIN
  686. SET @error = 50006 -- E_subProcFailure
  687. SET @context = ''
  688. GOTO errorLabel
  689. END
  690. END
  691. -- Add new taxonomy
  692. INSERT [UDT_taxonomies](
  693. [tModelKey],
  694. [flag])
  695. VALUES(
  696. @tModelKey,
  697. @flag)
  698. SET @taxonomyID = @@IDENTITY
  699. RETURN 0
  700. errorLabel:
  701. RAISERROR (@error, 16, 1, @context)
  702. RETURN 1
  703. END
  704. GO
  705. -- =============================================
  706. -- Name: net_taxonomy_delete
  707. -- =============================================
  708. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'net_taxonomy_delete' AND type = 'P')
  709. DROP PROCEDURE net_taxonomy_delete
  710. GO
  711. CREATE PROCEDURE net_taxonomy_delete
  712. @tModelKey uniqueidentifier
  713. WITH ENCRYPTION
  714. AS
  715. BEGIN
  716. DECLARE
  717. @error int,
  718. @context nvarchar(4000),
  719. @taxonomyID bigint
  720. SET @taxonomyID = dbo.taxonomyID(@tModelKey)
  721. IF @taxonomyID IS NULL
  722. BEGIN
  723. SET @error = 60210
  724. SET @context = 'uuid:' + dbo.UUIDSTR(@tModelKey)
  725. GOTO errorLabel
  726. END
  727. IF EXISTS(SELECT * FROM [UDT_taxonomies] WHERE [taxonomyID] = @taxonomyID)
  728. DELETE [UDT_taxonomies] WHERE [taxonomyID] = @taxonomyID
  729. RETURN 0
  730. errorLabel:
  731. RAISERROR (@error, 16, 1, @context)
  732. RETURN 1
  733. END
  734. GO
  735. -- =============================================
  736. -- Name: net_taxonomyValue_save
  737. -- =============================================
  738. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_taxonomyValue_save' AND type = 'P')
  739. DROP PROCEDURE net_taxonomyValue_save
  740. GO
  741. CREATE PROCEDURE net_taxonomyValue_save
  742. @tModelKey uniqueidentifier,
  743. @keyValue nvarchar(255),
  744. @parentKeyValue nvarchar(255),
  745. @keyName nvarchar(255),
  746. @valid bit
  747. WITH ENCRYPTION
  748. AS
  749. BEGIN
  750. -- This procedure saves new rows to UDT_taxonomyValues.
  751. -- Note: if the row already exists it is deleted and resaved.
  752. -- Note: parentKeyValue is not validated.
  753. DECLARE
  754. @error int,
  755. @context nvarchar(4000),
  756. @taxonomyID bigint
  757. SET @taxonomyID = dbo.taxonomyID(@tModelKey)
  758. IF @taxonomyID IS NULL
  759. BEGIN
  760. SET @error = 60210
  761. SET @context = 'No taxonomy for uuid:' + dbo.UUIDSTR(@tModelKey)
  762. GOTO errorLabel
  763. END
  764. -- Validate parameters
  765. IF NOT EXISTS(SELECT * FROM [UDT_taxonomies] WHERE [taxonomyID] = @taxonomyID)
  766. BEGIN
  767. SET @error = 50009 -- E_parmError
  768. SET @context = CAST(@taxonomyID AS varchar(256)) + ' is not a valid taxonomyValue.'
  769. GOTO errorLabel
  770. END
  771. -- Delete taxonomyValue if it exists
  772. IF EXISTS (SELECT * FROM [UDT_taxonomyValues] WHERE [taxonomyID] = @taxonomyID AND [keyValue] = @keyValue)
  773. BEGIN
  774. DELETE
  775. [UDT_taxonomyValues]
  776. WHERE
  777. ([taxonomyID] = @taxonomyID) AND
  778. ([keyValue] = @keyValue)
  779. END
  780. INSERT [UDT_taxonomyValues](
  781. [taxonomyID],
  782. [keyValue],
  783. [parentKeyValue],
  784. [keyName],
  785. [valid])
  786. VALUES(
  787. @taxonomyID,
  788. @keyValue,
  789. @parentKeyValue,
  790. @keyName,
  791. @valid)
  792. RETURN 0
  793. errorLabel:
  794. RAISERROR (@error, 16, 1, @context)
  795. RETURN 1
  796. END
  797. GO
  798. -- =============================================
  799. -- Name: net_taxonomyValue_get
  800. -- =============================================
  801. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_taxonomyValue_get' AND type = 'P')
  802. DROP PROCEDURE net_taxonomyValue_get
  803. GO
  804. CREATE PROCEDURE net_taxonomyValue_get
  805. @tModelKey uniqueidentifier,
  806. @keyValue nvarchar(255),
  807. @relation int
  808. WITH ENCRYPTION
  809. AS
  810. BEGIN
  811. -- This procedure gets rows from UDT_taxonomyValues.
  812. -- Note: @relation is as follows
  813. -- 0 - Root information requested
  814. -- 1 - Child information requested
  815. -- 2 - Parent information requested
  816. -- 3 - Current information requested
  817. DECLARE
  818. @error int,
  819. @context nvarchar(4000),
  820. @taxonomyID bigint
  821. SET @taxonomyID = dbo.taxonomyID(@tModelKey)
  822. IF @taxonomyID IS NULL
  823. BEGIN
  824. SET @error = 60210
  825. SET @context = 'uuid:' + dbo.UUIDSTR(@tModelKey)
  826. GOTO errorLabel
  827. END
  828. -- Validate parameters
  829. IF NOT EXISTS(SELECT * FROM [UDT_taxonomies] WHERE [taxonomyID] = @taxonomyID)
  830. BEGIN
  831. SET @error = 50009 -- E_parmError
  832. SET @context = CAST(@taxonomyID AS varchar(256)) + ' is not a valid taxonomyValue.'
  833. GOTO errorLabel
  834. END
  835. IF @relation = 0
  836. BEGIN
  837. -- Get root level values
  838. -- The @keyValue is ignored in this case
  839. SELECT
  840. [keyValue],
  841. [parentKeyValue],
  842. [keyName],
  843. [valid]
  844. FROM
  845. [UDT_taxonomyValues]
  846. WHERE
  847. [taxonomyID] = @taxonomyID AND [parentKeyValue] = ''
  848. END
  849. ELSE IF @relation = 1
  850. BEGIN
  851. -- Get children values
  852. SELECT
  853. [keyValue],
  854. [parentKeyValue],
  855. [keyName],
  856. [valid]
  857. FROM
  858. [UDT_taxonomyValues]
  859. WHERE
  860. [taxonomyID] = @taxonomyID AND [parentKeyValue] = @keyValue
  861. END
  862. ELSE IF @relation = 2
  863. BEGIN
  864. -- Get parent values
  865. SELECT
  866. [keyValue],
  867. [parentKeyValue],
  868. [keyName],
  869. [valid]
  870. FROM
  871. [UDT_taxonomyValues]
  872. WHERE
  873. [taxonomyID] = @taxonomyID AND [keyValue]
  874. IN (SELECT [parentKeyValue] FROM [UDT_taxonomyValues] WHERE [keyValue] = @keyValue)
  875. END
  876. ELSE IF @relation = 3
  877. BEGIN
  878. -- Get current values
  879. SELECT
  880. [keyValue],
  881. [parentKeyValue],
  882. [keyName],
  883. [valid]
  884. FROM
  885. [UDT_taxonomyValues]
  886. WHERE
  887. [taxonomyID] = @taxonomyID AND [keyValue] = @keyValue
  888. END
  889. ELSE
  890. BEGIN
  891. SET @error = 50009 -- E_parmError
  892. SET @context = CAST(@relation AS varchar(256)) + ' is not a valid relationship value.'
  893. GOTO errorLabel
  894. END
  895. RETURN 0
  896. errorLabel:
  897. RAISERROR (@error, 16, 1, @context)
  898. RETURN 1
  899. END
  900. GO
  901. -- =============================================
  902. -- Name: net_taxonomyValues_get
  903. -- =============================================
  904. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_taxonomyValues_get' AND type = 'P')
  905. DROP PROCEDURE net_taxonomyValues_get
  906. GO
  907. CREATE PROCEDURE net_taxonomyValues_get
  908. @tModelKey uniqueidentifier
  909. AS
  910. BEGIN
  911. DECLARE
  912. @error int,
  913. @context nvarchar(4000),
  914. @taxonomyID bigint
  915. SET @taxonomyID = dbo.taxonomyID(@tModelKey)
  916. IF @taxonomyID IS NULL
  917. BEGIN
  918. SET @error = 60210
  919. SET @context = 'uuid:' + dbo.UUIDSTR(@tModelKey)
  920. GOTO errorLabel
  921. END
  922. SELECT
  923. [keyValue],
  924. [parentKeyValue],
  925. [keyName],
  926. [valid]
  927. FROM
  928. [UDT_taxonomyValues]
  929. WHERE
  930. ([taxonomyID] = @taxonomyID)
  931. ORDER BY
  932. [parentKeyValue],
  933. [keyValue]
  934. RETURN 0
  935. errorLabel:
  936. RAISERROR (@error, 16, 1, @context)
  937. RETURN 1
  938. END
  939. GO
  940. -- =============================================
  941. -- Section: Reporting routines
  942. -- =============================================
  943. -- =============================================
  944. -- Name: net_report_get
  945. -- =============================================
  946. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_report_get' AND type = 'P')
  947. DROP PROCEDURE net_report_get
  948. GO
  949. CREATE PROCEDURE net_report_get
  950. @reportID sysname,
  951. @reportStatusID tinyint = NULL OUTPUT,
  952. @lastChange datetime = NULL OUTPUT
  953. WITH ENCRYPTION
  954. AS
  955. BEGIN
  956. DECLARE
  957. @error int,
  958. @context nvarchar(4000)
  959. IF NOT EXISTS(SELECT * FROM [UDO_reports] WHERE [reportID] = @reportID)
  960. BEGIN
  961. SET @error = 50009 -- E_parmError
  962. SET @context = 'Invalid reportID.'
  963. GOTO errorLabel
  964. END
  965. SELECT
  966. @reportStatusID = [reportStatusID],
  967. @lastChange = [lastChange]
  968. FROM
  969. [UDO_reports]
  970. WHERE
  971. ([reportID] = @reportID)
  972. RETURN 0
  973. errorLabel:
  974. RAISERROR (@error, 16, 1, @context)
  975. RETURN 1
  976. END -- net_report_get
  977. GO
  978. -- =============================================
  979. -- Name: net_report_update
  980. -- =============================================
  981. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_report_update' AND type = 'P')
  982. DROP PROCEDURE net_report_update
  983. GO
  984. CREATE PROCEDURE net_report_update
  985. @reportID sysname,
  986. @reportStatusID tinyint
  987. WITH ENCRYPTION
  988. AS
  989. BEGIN
  990. DECLARE
  991. @error int,
  992. @context nvarchar(4000),
  993. @lastChange datetime
  994. IF NOT EXISTS(SELECT * FROM [UDO_reports] WHERE [reportID] = @reportID)
  995. BEGIN
  996. SET @error = 50009 -- E_parmError
  997. SET @context = 'Invalid reportID.'
  998. GOTO errorLabel
  999. END
  1000. IF NOT EXISTS(SELECT * FROM [UDO_reportStatus] WHERE [reportStatusID] = @reportStatusID)
  1001. BEGIN
  1002. SET @error = 50009 -- E_parmError
  1003. SET @context = 'Invalid reportStatusID.'
  1004. GOTO errorLabel
  1005. END
  1006. SET @lastChange = GETDATE()
  1007. UPDATE
  1008. [UDO_reports]
  1009. SET
  1010. [reportStatusID] = @reportStatusID,
  1011. [lastChange] = @lastChange
  1012. WHERE
  1013. ([reportID] = @reportID)
  1014. RETURN 0
  1015. errorLabel:
  1016. RAISERROR (@error, 16, 1, @context)
  1017. RETURN 1
  1018. END -- net_report_update
  1019. GO
  1020. -- =============================================
  1021. -- Name: net_reportLines_get
  1022. -- =============================================
  1023. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_reportLines_get' AND type = 'P')
  1024. DROP PROCEDURE net_reportLines_get
  1025. GO
  1026. CREATE PROCEDURE net_reportLines_get
  1027. @reportID sysname
  1028. WITH ENCRYPTION
  1029. AS
  1030. BEGIN
  1031. DECLARE
  1032. @error int,
  1033. @context nvarchar(4000)
  1034. IF NOT EXISTS(SELECT * FROM [UDO_reports] WHERE [reportID] = @reportID)
  1035. BEGIN
  1036. SET @error = 50009 -- E_parmError
  1037. SET @context = 'Invalid reportID.'
  1038. GOTO errorLabel
  1039. END
  1040. SELECT
  1041. [section],
  1042. [label],
  1043. [value]
  1044. FROM
  1045. [UDO_reportLines]
  1046. WHERE
  1047. ([reportID] = @reportID)
  1048. ORDER BY
  1049. [seqNo] ASC
  1050. RETURN 0
  1051. errorLabel:
  1052. RAISERROR (@error, 16, 1, @context)
  1053. RETURN 1
  1054. END -- net_reportLines_get
  1055. GO
  1056. -- =============================================
  1057. -- Name: net_statistics_recalculate
  1058. -- =============================================
  1059. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_statistics_recalculate' AND type = 'P')
  1060. DROP PROCEDURE net_statistics_recalculate
  1061. GO
  1062. CREATE PROCEDURE net_statistics_recalculate
  1063. WITH ENCRYPTION
  1064. AS
  1065. BEGIN
  1066. DECLARE
  1067. @error int,
  1068. @context nvarchar(4000),
  1069. @RC int
  1070. EXEC @RC=master.dbo.xp_recalculate_statistics
  1071. IF @RC <> 0
  1072. BEGIN
  1073. SET @error = 50006 -- E_subProcFailure
  1074. SET @context = ''
  1075. GOTO errorLabel
  1076. END
  1077. RETURN 0
  1078. errorLabel:
  1079. RAISERROR (@error, 16, 1, @context)
  1080. RETURN 1
  1081. END -- net_statistics_recalculate
  1082. GO