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.

1822 lines
40 KiB

  1. -- Script: uddi.v2.func.sql
  2. -- Author: [email protected]
  3. -- Description: Creates scalar functions
  4. -- Note: This file is best viewed and edited with a tab width of 2.
  5. -- =============================================
  6. -- Section: Configuration helper functions
  7. -- =============================================
  8. -- =============================================
  9. -- Name: configValue()
  10. -- =============================================
  11. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'configValue' AND type = 'FN')
  12. DROP FUNCTION configValue
  13. GO
  14. CREATE FUNCTION configValue (
  15. @configName nvarchar(450))
  16. RETURNS varchar(8000)
  17. WITH ENCRYPTION
  18. AS
  19. BEGIN
  20. DECLARE
  21. @configValue nvarchar(4000)
  22. SELECT
  23. @configValue = [configValue]
  24. FROM
  25. [UDO_config]
  26. WHERE
  27. ([configName] = @configName)
  28. RETURN @configValue
  29. END
  30. GO
  31. -- =============================================
  32. -- Name: currentOperatorID
  33. -- =============================================
  34. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'currentOperatorID' AND type='FN')
  35. DROP FUNCTION currentOperatorID
  36. GO
  37. CREATE FUNCTION currentOperatorID ()
  38. RETURNS bigint
  39. WITH ENCRYPTION
  40. AS
  41. BEGIN
  42. -- Return the operatorID for the current operator site
  43. DECLARE
  44. @operatorID bigint
  45. SET @operatorID = CAST(dbo.configValue('OperatorID') AS bigint)
  46. RETURN @operatorID
  47. END -- currentOperatorID
  48. GO
  49. -- =============================================
  50. -- Section: Dereferencing functions
  51. -- =============================================
  52. -- =============================================
  53. -- Name: bindingKey
  54. -- =============================================
  55. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'bindingKey' AND type = 'FN')
  56. DROP FUNCTION bindingKey
  57. GO
  58. CREATE FUNCTION bindingKey
  59. (@bindingID bigint)
  60. RETURNS uniqueidentifier
  61. WITH ENCRYPTION
  62. AS
  63. BEGIN
  64. DECLARE @bindingKey uniqueidentifier
  65. SELECT @bindingKey = bindingKey FROM [UDC_bindingTemplates] WHERE bindingID = @bindingID
  66. RETURN @bindingKey
  67. END
  68. GO
  69. -- =============================================
  70. -- Name: bindingID
  71. -- =============================================
  72. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'bindingID' AND type = 'FN')
  73. DROP FUNCTION bindingID
  74. GO
  75. CREATE FUNCTION bindingID(
  76. @bindingKey uniqueidentifier)
  77. RETURNS bigint
  78. WITH ENCRYPTION
  79. AS
  80. BEGIN
  81. DECLARE
  82. @bindingID bigint
  83. SELECT @bindingID = bindingID FROM [UDC_bindingTemplates] WHERE bindingKey = @bindingKey
  84. RETURN @bindingID
  85. END
  86. GO
  87. -- =============================================
  88. -- Name: businessID
  89. -- =============================================
  90. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'businessID' AND type = 'FN')
  91. DROP FUNCTION businessID
  92. GO
  93. CREATE FUNCTION businessID(
  94. @businessKey uniqueidentifier)
  95. RETURNS bigint
  96. WITH ENCRYPTION
  97. AS
  98. BEGIN
  99. DECLARE
  100. @businessID bigint
  101. SELECT @businessID = businessID FROM [UDC_businessEntities] WHERE businessKey = @businessKey
  102. RETURN @businessID
  103. END
  104. GO
  105. -- =============================================
  106. -- Name: businessKey()
  107. -- =============================================
  108. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'businessKey' AND type = 'FN')
  109. DROP FUNCTION businessKey
  110. GO
  111. CREATE FUNCTION businessKey(
  112. @businessID bigint)
  113. RETURNS uniqueidentifier
  114. WITH ENCRYPTION
  115. AS
  116. BEGIN
  117. DECLARE
  118. @businessKey uniqueidentifier
  119. SELECT @businessKey = [businessKey] FROM [UDC_businessEntities] WHERE businessID = @businessID
  120. RETURN @businessKey
  121. END -- businessKey
  122. GO
  123. -- =============================================
  124. -- Name: changeType()
  125. -- =============================================
  126. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'changeType' AND type = 'FN')
  127. DROP FUNCTION changeType
  128. GO
  129. CREATE FUNCTION changeType(
  130. @changeTypeID tinyint)
  131. RETURNS nvarchar(4000)
  132. WITH ENCRYPTION
  133. AS
  134. BEGIN
  135. DECLARE
  136. @changeType nvarchar(4000)
  137. SELECT
  138. @changeType = [changeType]
  139. FROM
  140. [UDO_changeTypes]
  141. WHERE
  142. [changeTypeID] = @changeTypeID
  143. RETURN @changeType
  144. END -- changeType
  145. GO
  146. -- =============================================
  147. -- Name: changeTypeID
  148. -- =============================================
  149. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'changeTypeID' AND type = 'FN')
  150. DROP FUNCTION changeTypeID
  151. GO
  152. CREATE FUNCTION changeTypeID(
  153. @changeType nvarchar(4000))
  154. RETURNS bigint
  155. WITH ENCRYPTION
  156. AS
  157. BEGIN
  158. DECLARE
  159. @changeTypeID tinyint
  160. SELECT
  161. @changeTypeID = [changeTypeID]
  162. FROM
  163. [UDO_changeTypes]
  164. WHERE
  165. ([changeType] = @changeType)
  166. RETURN @changeTypeID
  167. END
  168. GO
  169. -- =============================================
  170. -- Name: elementName()
  171. -- =============================================
  172. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'elementName' AND type = 'FN')
  173. DROP FUNCTION elementName
  174. GO
  175. CREATE FUNCTION elementName(
  176. @elementID tinyint)
  177. RETURNS nvarchar(4000)
  178. WITH ENCRYPTION
  179. AS
  180. BEGIN
  181. DECLARE
  182. @elementName nvarchar(4000)
  183. SELECT
  184. @elementName = [elementName]
  185. FROM
  186. [UDO_elementNames]
  187. WHERE
  188. [elementID] = @elementID
  189. RETURN @elementName
  190. END -- elementName
  191. GO
  192. -- =============================================
  193. -- Name: elementID()
  194. -- =============================================
  195. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'elementID' AND type = 'FN')
  196. DROP FUNCTION elementID
  197. GO
  198. CREATE FUNCTION elementID(
  199. @elementName nvarchar(4000))
  200. RETURNS tinyint
  201. WITH ENCRYPTION
  202. AS
  203. BEGIN
  204. DECLARE
  205. @elementID tinyint
  206. SELECT
  207. @elementID = [elementID]
  208. FROM
  209. [UDO_elementNames]
  210. WHERE
  211. ([elementName] = @elementName)
  212. RETURN @elementID
  213. END -- elementID
  214. GO
  215. -- =============================================
  216. -- Name: entityType()
  217. -- =============================================
  218. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'entityType' AND type = 'FN')
  219. DROP FUNCTION entityType
  220. GO
  221. CREATE FUNCTION entityType
  222. (@entityTypeID tinyint)
  223. RETURNS nvarchar(4000)
  224. WITH ENCRYPTION
  225. AS
  226. BEGIN
  227. DECLARE
  228. @entityType nvarchar(4000)
  229. SELECT
  230. @entityType = [entityType]
  231. FROM
  232. [UDO_entityTypes]
  233. WHERE
  234. ([entityTypeID] = @entityTypeID)
  235. RETURN @entityType
  236. END -- entityType
  237. GO
  238. -- =============================================
  239. -- Name: entityTypeID()
  240. -- =============================================
  241. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'entityTypeID' AND type = 'FN')
  242. DROP FUNCTION entityTypeID
  243. GO
  244. CREATE FUNCTION entityTypeID
  245. (@entityType nvarchar(4000))
  246. RETURNS tinyint
  247. WITH ENCRYPTION
  248. AS
  249. BEGIN
  250. DECLARE
  251. @entityTypeID tinyint
  252. SELECT
  253. @entityTypeID = [entityTypeID]
  254. FROM
  255. [UDO_entityTypes]
  256. WHERE
  257. ([entityType] = @entityType)
  258. RETURN @entityTypeID
  259. END -- entityTypeID
  260. GO
  261. -- =============================================
  262. -- Name: operatorID
  263. -- =============================================
  264. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'operatorID' AND type='FN')
  265. DROP FUNCTION operatorID
  266. GO
  267. CREATE FUNCTION operatorID
  268. (@operatorKey uniqueidentifier)
  269. RETURNS bigint
  270. WITH ENCRYPTION
  271. AS
  272. BEGIN
  273. DECLARE
  274. @operatorID bigint
  275. SELECT
  276. @operatorID = [operatorID]
  277. FROM
  278. [UDO_operators]
  279. WHERE
  280. ([operatorKey] = @operatorKey)
  281. RETURN @operatorID
  282. END
  283. GO
  284. -- =============================================
  285. -- Name: operatorStatus
  286. -- =============================================
  287. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'operatorStatus' AND type='FN')
  288. DROP FUNCTION operatorStatus
  289. GO
  290. CREATE FUNCTION operatorStatus
  291. (@operatorStatusID tinyint)
  292. RETURNS nvarchar(4000)
  293. WITH ENCRYPTION
  294. AS
  295. BEGIN
  296. DECLARE
  297. @operatorStatus nvarchar(4000)
  298. SELECT
  299. @operatorStatus = [operatorStatus]
  300. FROM
  301. [UDO_operatorStatus]
  302. WHERE
  303. ([operatorStatusID] = @operatorStatusID)
  304. RETURN @operatorStatus
  305. END -- operatorStatus
  306. GO
  307. -- =============================================
  308. -- Name: operatorStatusID
  309. -- =============================================
  310. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'operatorStatusID' AND type='FN')
  311. DROP FUNCTION operatorStatusID
  312. GO
  313. CREATE FUNCTION operatorStatusID
  314. (@operatorStatus nvarchar(4000))
  315. RETURNS tinyint
  316. WITH ENCRYPTION
  317. AS
  318. BEGIN
  319. DECLARE
  320. @operatorStatusID tinyint
  321. SELECT
  322. @operatorStatusID = [operatorStatusID]
  323. FROM
  324. [UDO_operatorStatus]
  325. WHERE
  326. ([operatorStatus] = @operatorStatus)
  327. RETURN @operatorStatusID
  328. END -- operatorStatusID
  329. GO
  330. -- =============================================
  331. -- Function: operatorKey
  332. -- =============================================
  333. IF EXISTS (SELECT * FROM sysobjects WHERE name = N'operatorKey' AND type = 'FN')
  334. DROP FUNCTION operatorKey
  335. GO
  336. CREATE FUNCTION operatorKey (
  337. @operatorID bigint)
  338. RETURNS uniqueidentifier
  339. WITH ENCRYPTION
  340. AS
  341. BEGIN
  342. DECLARE
  343. @operatorKey AS uniqueidentifier
  344. SELECT
  345. @operatorKey = [operatorKey]
  346. FROM
  347. [UDO_operators]
  348. WHERE
  349. ([operatorID] = @operatorID)
  350. RETURN @operatorKey
  351. END -- operatorKey
  352. GO
  353. -- =============================================
  354. -- Name: operatorName
  355. -- =============================================
  356. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'operatorName' AND type='FN')
  357. DROP FUNCTION operatorName
  358. GO
  359. CREATE FUNCTION operatorName
  360. (@operatorID bigint)
  361. RETURNS nvarchar(450)
  362. WITH ENCRYPTION
  363. AS
  364. BEGIN
  365. DECLARE
  366. @name nvarchar(450)
  367. SELECT @name=[name] FROM [UDO_operators] WHERE [operatorID] = @operatorID
  368. RETURN @name
  369. END
  370. GO
  371. -- =============================================
  372. -- Name: publisherID
  373. -- =============================================
  374. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'publisherID' AND type='FN')
  375. DROP FUNCTION publisherID
  376. GO
  377. CREATE FUNCTION publisherID
  378. (@PUID nvarchar(450))
  379. RETURNS bigint
  380. WITH ENCRYPTION
  381. AS
  382. BEGIN
  383. DECLARE
  384. @publisherID bigint
  385. SELECT @publisherID=publisherID FROM [UDO_publishers] WHERE PUID=@PUID
  386. RETURN @publisherID
  387. END
  388. GO
  389. -- =============================================
  390. -- Name: PUID()
  391. -- =============================================
  392. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'PUID' AND type='FN')
  393. DROP FUNCTION PUID
  394. GO
  395. CREATE FUNCTION PUID
  396. (@publisherID bigint)
  397. RETURNS nvarchar(450)
  398. WITH ENCRYPTION
  399. AS
  400. BEGIN
  401. DECLARE
  402. @PUID nvarchar(450)
  403. SELECT @PUID = PUID FROM [UDO_publishers] WHERE publisherID = @publisherID
  404. RETURN @PUID
  405. END
  406. GO
  407. -- =============================================
  408. -- Name: publisherName
  409. -- =============================================
  410. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'publisherName' AND type = 'FN')
  411. DROP FUNCTION publisherName
  412. GO
  413. CREATE FUNCTION publisherName(
  414. @publisherID bigint)
  415. RETURNS nvarchar(450)
  416. WITH ENCRYPTION
  417. AS
  418. BEGIN
  419. DECLARE
  420. @name nvarchar(450)
  421. SELECT @name=[name] FROM [UDO_publishers] WHERE publisherID = @publisherID
  422. RETURN @name
  423. END
  424. GO
  425. -- =============================================
  426. -- publisherNameUnique
  427. -- =============================================
  428. -- TODO: Temporarily removed for heartland
  429. -- IF EXISTS (SELECT name FROM sysobjects WHERE name = 'publisherNameUnique' AND type = 'FN')
  430. -- DROP FUNCTION publisherNameUnique
  431. -- GO
  432. --
  433. -- CREATE FUNCTION publisherNameUnique(
  434. -- @publisherID bigint)
  435. -- RETURNS nvarchar(450)
  436. -- AS
  437. -- BEGIN
  438. -- DECLARE
  439. -- @publisherName nvarchar(4000),
  440. -- @publisherIDString nvarchar(4000),
  441. -- @publisherNameUnique nvarchar(450)
  442. --
  443. -- SELECT
  444. -- @publisherName = [name]
  445. -- FROM
  446. -- [UDO_publishers]
  447. -- WHERE
  448. -- [publisherID] = @publisherID
  449. --
  450. -- IF @@ROWCOUNT = 0
  451. -- RETURN NULL
  452. --
  453. -- SET @publisherIDString = ' : ' + CAST(@publisherID AS nvarchar(4000))
  454. --
  455. -- SET @publisherNameUnique = LEFT(ISNULL(@publisherName,''),450 - LEN(@publisherIDString)) + @publisherIDString
  456. --
  457. -- RETURN @publisherNameUnique
  458. -- END -- publisherNameUnique
  459. -- GO
  460. -- =============================================
  461. -- Name: publisherStatus
  462. -- =============================================
  463. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'publisherStatus' AND type = 'FN')
  464. DROP FUNCTION publisherStatus
  465. GO
  466. CREATE FUNCTION publisherStatus(
  467. @publisherStatusID tinyint)
  468. RETURNS nvarchar(256)
  469. WITH ENCRYPTION
  470. AS
  471. BEGIN
  472. DECLARE
  473. @publisherStatus nvarchar(256)
  474. SELECT @publisherStatus = publisherStatus FROM [UDO_publisherStatus] WHERE publisherStatusID = @publisherStatusID
  475. RETURN @publisherStatus
  476. END
  477. GO
  478. -- =============================================
  479. -- Name: publisherStatusID
  480. -- =============================================
  481. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'publisherStatusID' AND type = 'FN')
  482. DROP FUNCTION publisherStatusID
  483. GO
  484. CREATE FUNCTION publisherStatusID(
  485. @publisherStatus nvarchar(256))
  486. RETURNS tinyint
  487. WITH ENCRYPTION
  488. AS
  489. BEGIN
  490. DECLARE
  491. @publisherStatusID tinyint
  492. SELECT @publisherStatusID = publisherStatusID FROM [UDO_publisherStatus] WHERE publisherStatus = @publisherStatus
  493. RETURN @publisherStatusID
  494. END -- puublisherStatusID
  495. GO
  496. -- =============================================
  497. -- Name: reportStatus
  498. -- =============================================
  499. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'reportStatus' AND type = 'FN')
  500. DROP FUNCTION reportStatus
  501. GO
  502. CREATE FUNCTION reportStatus (
  503. @reportStatusID tinyint)
  504. RETURNS nvarchar(4000)
  505. WITH ENCRYPTION
  506. AS
  507. BEGIN
  508. DECLARE
  509. @reportStatus nvarchar(4000)
  510. SELECT
  511. @reportStatus = [reportStatus]
  512. FROM
  513. [UDO_reportStatus]
  514. WHERE
  515. ([reportStatusID] = @reportStatusID)
  516. RETURN @reportStatus
  517. END -- reportStatus
  518. GO
  519. -- =============================================
  520. -- Name: reportStatusID
  521. -- =============================================
  522. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'reportStatusID' AND type = 'FN')
  523. DROP FUNCTION reportStatusID
  524. GO
  525. CREATE FUNCTION reportStatusID (
  526. @reportStatus nvarchar(4000))
  527. RETURNS tinyint
  528. WITH ENCRYPTION
  529. AS
  530. BEGIN
  531. DECLARE
  532. @reportStatusID tinyint
  533. SELECT
  534. @reportStatusID = [reportStatusID]
  535. FROM
  536. [UDO_reportStatus]
  537. WHERE
  538. ([reportStatus] = @reportStatus)
  539. RETURN @reportStatusID
  540. END -- reportStatusID
  541. GO
  542. -- =============================================
  543. -- Name: serviceKey
  544. -- =============================================
  545. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'serviceKey' AND type = 'FN')
  546. DROP FUNCTION serviceKey
  547. GO
  548. CREATE FUNCTION serviceKey
  549. (@serviceID bigint)
  550. RETURNS uniqueidentifier
  551. WITH ENCRYPTION
  552. AS
  553. BEGIN
  554. DECLARE @serviceKey uniqueidentifier
  555. SELECT @serviceKey = serviceKey FROM [UDC_businessServices] WHERE serviceID = @serviceID
  556. RETURN @serviceKey
  557. END
  558. GO
  559. -- =============================================
  560. -- Name: serviceID
  561. -- =============================================
  562. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'serviceID' AND type = 'FN')
  563. DROP FUNCTION serviceID
  564. GO
  565. CREATE FUNCTION serviceID(
  566. @serviceKey uniqueidentifier)
  567. RETURNS bigint
  568. WITH ENCRYPTION
  569. AS
  570. BEGIN
  571. DECLARE
  572. @serviceID bigint
  573. SELECT @serviceID = serviceID FROM [UDC_businessServices] WHERE serviceKey = @serviceKey
  574. RETURN @serviceID
  575. END
  576. GO
  577. -- =============================================
  578. -- Name: taxonomyID()
  579. -- =============================================
  580. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'taxonomyID' AND type = 'FN')
  581. DROP FUNCTION taxonomyID
  582. GO
  583. CREATE FUNCTION taxonomyID (
  584. @tModelKey uniqueidentifier)
  585. RETURNS int
  586. WITH ENCRYPTION
  587. AS
  588. BEGIN
  589. DECLARE
  590. @taxonomyID int
  591. SELECT @taxonomyID = [taxonomyID] FROM [UDT_taxonomies] WHERE [tModelKey] = @tModelKey
  592. RETURN @taxonomyID
  593. END
  594. GO
  595. -- =============================================
  596. -- Name: tModelKey
  597. -- =============================================
  598. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'tModelKey' AND type = 'FN')
  599. DROP FUNCTION tModelKey
  600. GO
  601. CREATE FUNCTION tModelKey(
  602. @tModelID bigint)
  603. RETURNS uniqueidentifier
  604. WITH ENCRYPTION
  605. AS
  606. BEGIN
  607. DECLARE
  608. @tModelKey uniqueidentifier
  609. SELECT @tModelKey = tModelKey FROM [UDC_tModels] WHERE tModelID = @tModelID
  610. RETURN @tModelKey
  611. END
  612. GO
  613. -- =============================================
  614. -- Name: tModelID
  615. -- =============================================
  616. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'tModelID' AND type = 'FN')
  617. DROP FUNCTION tModelID
  618. GO
  619. CREATE FUNCTION tModelID(
  620. @tModelKey uniqueidentifier)
  621. RETURNS bigint
  622. WITH ENCRYPTION
  623. AS
  624. BEGIN
  625. DECLARE
  626. @tModelID bigint
  627. SELECT @tModelID = tModelID FROM [UDC_tModels] WHERE tModelKey = @tModelKey
  628. RETURN @tModelID
  629. END
  630. GO
  631. -- =============================================
  632. -- Name: URLTypeID
  633. -- =============================================
  634. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'URLTypeID' AND type = 'FN')
  635. DROP FUNCTION URLTypeID
  636. GO
  637. CREATE FUNCTION URLTypeID(
  638. @URLType nvarchar(450))
  639. RETURNS tinyint
  640. WITH ENCRYPTION
  641. AS
  642. BEGIN
  643. DECLARE
  644. @URLTypeID tinyint
  645. SELECT @URLTypeID = URLTypeID FROM [UDC_URLTypes] WHERE URLType = @URLType
  646. RETURN @URLTypeID
  647. END
  648. GO
  649. -- =============================================
  650. -- Name: URLType
  651. -- =============================================
  652. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'URLType' AND type = 'FN')
  653. DROP FUNCTION URLType
  654. GO
  655. CREATE FUNCTION URLType(
  656. @URLTypeID tinyint)
  657. RETURNS nvarchar(450)
  658. WITH ENCRYPTION
  659. AS
  660. BEGIN
  661. DECLARE
  662. @URLType nvarchar(450)
  663. SELECT @URLType = URLType FROM [UDC_URLTypes] WHERE URLTypeID = @URLTypeID
  664. RETURN @URLType
  665. END
  666. GO
  667. -- =============================================
  668. -- Name: URLType
  669. -- =============================================
  670. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'URLType' AND type = 'FN')
  671. DROP FUNCTION URLType
  672. GO
  673. CREATE FUNCTION URLType(
  674. @URLTypeID tinyint)
  675. RETURNS nvarchar(450)
  676. WITH ENCRYPTION
  677. AS
  678. BEGIN
  679. DECLARE
  680. @URLType nvarchar(450)
  681. SELECT @URLType = URLType FROM [UDC_URLTypes] WHERE URLTypeID = @URLTypeID
  682. RETURN @URLType
  683. END
  684. GO
  685. -- =============================================
  686. -- Section: Find helper functions
  687. -- =============================================
  688. -- =============================================
  689. -- Name: caseSensitiveMatch
  690. -- =============================================
  691. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'caseSensitiveMatch' AND type = 'FN')
  692. DROP FUNCTION caseSensitiveMatch
  693. GO
  694. CREATE FUNCTION caseSensitiveMatch(
  695. @searchArgument nvarchar(4000),
  696. @columnVal nvarchar(4000),
  697. @exactNameMatch bit)
  698. RETURNS bit
  699. WITH ENCRYPTION
  700. AS
  701. BEGIN
  702. DECLARE
  703. @caseSensitiveMatch bit
  704. SET @caseSensitiveMatch = 0
  705. IF @exactNameMatch=1
  706. BEGIN
  707. -- exactNameMatch and caseSensitiveMatch were specified
  708. IF (CONVERT(binary(8000), @columnVal) = CONVERT(binary(8000), @searchArgument))
  709. SET @caseSensitiveMatch = 1
  710. END
  711. ELSE
  712. BEGIN
  713. -- Only caseSensitiveMatch was specified, wildcards must be considered
  714. IF (dbo.containsWildCard(@searchArgument) = 0)
  715. SET @searchArgument = @searchArgument + N'%'
  716. IF (@columnVal COLLATE Latin1_General_BIN LIKE @searchArgument COLLATE Latin1_General_BIN)
  717. SET @caseSensitiveMatch = 1
  718. END
  719. RETURN @caseSensitiveMatch
  720. END -- caseSensitiveMatch
  721. GO
  722. -- =============================================
  723. -- Name: contextRows
  724. -- =============================================
  725. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'contextRows' AND type = 'FN')
  726. DROP FUNCTION contextRows
  727. GO
  728. CREATE FUNCTION contextRows(
  729. @contextID uniqueidentifier)
  730. RETURNS int
  731. WITH ENCRYPTION
  732. AS
  733. BEGIN
  734. DECLARE
  735. @contextRows int
  736. SELECT
  737. @contextRows = COUNT(*)
  738. FROM
  739. [UDS_findResults]
  740. WHERE
  741. ([contextID] = @contextID)
  742. RETURN @contextRows
  743. END -- contextRows
  744. GO
  745. -- =============================================
  746. -- Name: containsWildcard
  747. -- =============================================
  748. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'containsWildcard' AND type = 'FN')
  749. DROP FUNCTION containsWildcard
  750. GO
  751. CREATE FUNCTION containsWildcard(
  752. @string nvarchar(4000))
  753. RETURNS bit
  754. WITH ENCRYPTION
  755. AS
  756. BEGIN
  757. DECLARE
  758. @containsWildcard bit
  759. SET @containsWildcard = 0
  760. IF CHARINDEX(N'%', @string) <> 0
  761. SET @containsWildcard = 1
  762. RETURN @containsWildcard
  763. END -- containsWildcard
  764. GO
  765. -- =============================================
  766. -- Function: ownerFlag
  767. -- =============================================
  768. IF EXISTS (SELECT * FROM sysobjects WHERE name = N'ownerFlag' AND type = 'FN')
  769. DROP FUNCTION ownerFlag
  770. GO
  771. CREATE FUNCTION ownerFlag (
  772. @publisherID bigint,
  773. @fromKey uniqueidentifier,
  774. @toKey uniqueidentifier)
  775. RETURNS int
  776. WITH ENCRYPTION
  777. AS
  778. BEGIN
  779. DECLARE
  780. @ownerFlag int
  781. SET @ownerFlag = 0
  782. IF EXISTS(SELECT * FROM [UDC_businessEntities] WHERE [businessKey] = @fromKey AND [publisherID] = @publisherID)
  783. SET @ownerFlag = @ownerFlag | 0x2
  784. IF EXISTS(SELECT * FROM [UDC_businessEntities] WHERE [businessKey] = @toKey AND [publisherID] = @publisherID)
  785. SET @ownerFlag = @ownerFlag | 0x1
  786. RETURN @ownerFlag
  787. END -- ownerFlag
  788. GO
  789. -- =============================================
  790. -- Function: genKeywordsKey
  791. -- =============================================
  792. IF EXISTS (SELECT * FROM sysobjects WHERE name = N'genKeywordsKey' AND type = 'FN')
  793. DROP FUNCTION genKeywordsKey
  794. GO
  795. CREATE FUNCTION genKeywordsKey ()
  796. RETURNS uniqueidentifier
  797. WITH ENCRYPTION
  798. AS
  799. BEGIN
  800. DECLARE
  801. @genKeywordsKeyStr varchar(8000),
  802. @genKeywordsKey uniqueidentifier
  803. SET @genKeywordsKeyStr = dbo.configValue('TModelKey.GeneralKeywords')
  804. SET @genKeywordsKey = RIGHT(@genKeywordsKeyStr, LEN(@genKeywordsKeyStr) - 5)
  805. RETURN @genKeywordsKey
  806. END -- genKeywordsKey
  807. GO
  808. -- =============================================
  809. -- Function: operatorsKey()
  810. -- =============================================
  811. IF EXISTS (SELECT * FROM sysobjects WHERE name = N'operatorsKey' AND type = 'FN')
  812. DROP FUNCTION operatorsKey
  813. GO
  814. CREATE FUNCTION operatorsKey ()
  815. RETURNS uniqueidentifier
  816. WITH ENCRYPTION
  817. AS
  818. BEGIN
  819. DECLARE
  820. @operatorsKeyStr varchar(8000),
  821. @operatorsKey uniqueidentifier
  822. SET @operatorsKeyStr = dbo.configValue('TModelKey.Operators')
  823. SET @operatorsKey = RIGHT(@operatorsKeyStr, LEN(@operatorsKeyStr) - 5)
  824. RETURN @operatorsKey
  825. END -- operatorsKey
  826. GO
  827. -- =============================================
  828. -- Section: Lookup helper functions
  829. -- =============================================
  830. -- =============================================
  831. -- Name: getBindingPublisherID
  832. -- =============================================
  833. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'getBindingPublisherID' AND type = 'FN')
  834. DROP FUNCTION getBindingPublisherID
  835. GO
  836. CREATE FUNCTION getBindingPublisherID(
  837. @bindingKey uniqueidentifier)
  838. RETURNS bigint
  839. WITH ENCRYPTION
  840. AS
  841. BEGIN
  842. DECLARE
  843. @businessKey uniqueidentifier,
  844. @publisherID bigint
  845. SELECT
  846. @businessKey = dbo.businessKey(BS.businessID)
  847. FROM
  848. [UDC_businessServices] BS
  849. JOIN [UDC_bindingTemplates] BT
  850. ON BS.serviceID = BT.serviceID
  851. WHERE
  852. BT.bindingKey = @bindingKey
  853. SELECT @publisherID = dbo.getBusinessPublisherID(@businessKey)
  854. RETURN @publisherID
  855. END
  856. GO
  857. -- =============================================
  858. -- Name: getBindingOperatorID
  859. -- =============================================
  860. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'getBindingOperatorID' AND type = 'FN')
  861. DROP FUNCTION getBindingOperatorID
  862. GO
  863. CREATE FUNCTION getBindingOperatorID(
  864. @bindingKey uniqueidentifier)
  865. RETURNS bigint
  866. WITH ENCRYPTION
  867. AS
  868. BEGIN
  869. DECLARE
  870. @businessKey uniqueidentifier,
  871. @publisherID bigint,
  872. @operatorID bigint
  873. SELECT
  874. @businessKey = dbo.businessKey(BS.businessID)
  875. FROM
  876. [UDC_businessServices] BS
  877. JOIN [UDC_bindingTemplates] BT
  878. ON BS.serviceID = BT.serviceID
  879. WHERE
  880. BT.bindingKey = @bindingKey
  881. SELECT @publisherID = dbo.getBusinessPublisherID(@businessKey)
  882. SELECT
  883. @operatorID = [operatorID]
  884. FROM
  885. [UDO_operators]
  886. WHERE
  887. ([publisherID] = @publisherID)
  888. IF @operatorID IS NULL
  889. SET @operatorID = dbo.currentOperatorID()
  890. RETURN @operatorID
  891. END
  892. GO
  893. -- =============================================
  894. -- Name: getBindingServiceKey
  895. -- =============================================
  896. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'getBindingServiceKey' AND type = 'FN')
  897. DROP FUNCTION getBindingServiceKey
  898. GO
  899. CREATE FUNCTION getBindingServiceKey
  900. (@bindingKey uniqueidentifier)
  901. RETURNS uniqueidentifier
  902. WITH ENCRYPTION
  903. AS
  904. BEGIN
  905. DECLARE
  906. @serviceID bigint
  907. SELECT @serviceID = serviceID FROM [UDC_bindingTemplates] WHERE bindingKey = @bindingKey
  908. RETURN dbo.serviceKey(@serviceID)
  909. END
  910. GO
  911. -- =============================================
  912. -- Name: getBusinessPublisherID
  913. -- =============================================
  914. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'getBusinessPublisherID' AND type = 'FN')
  915. DROP FUNCTION getBusinessPublisherID
  916. GO
  917. CREATE FUNCTION getBusinessPublisherID
  918. (@businessKey uniqueidentifier)
  919. RETURNS bigint
  920. WITH ENCRYPTION
  921. AS
  922. BEGIN
  923. DECLARE @publisherID bigint
  924. SELECT @publisherID = publisherID FROM [UDC_businessEntities] WHERE businessKey = @businessKey
  925. RETURN @publisherID
  926. END
  927. GO
  928. -- =============================================
  929. -- Function: getOperatorPublisherID
  930. -- =============================================
  931. IF EXISTS (SELECT * FROM sysobjects WHERE name = N'getOperatorPublisherID' AND type = 'FN')
  932. DROP FUNCTION getOperatorPublisherID
  933. GO
  934. CREATE FUNCTION getOperatorPublisherID (
  935. @operatorID bigint)
  936. RETURNS bigint
  937. WITH ENCRYPTION
  938. AS
  939. BEGIN
  940. DECLARE
  941. @publisherID bigint
  942. SELECT
  943. @publisherID = [publisherID]
  944. FROM
  945. [UDO_operators]
  946. WHERE
  947. ([operatorID] = @operatorID)
  948. RETURN @publisherID
  949. END -- getOperatorPublisherID
  950. GO
  951. -- =============================================
  952. -- Function: getPublisherOperatorID
  953. -- =============================================
  954. IF EXISTS (SELECT * FROM sysobjects WHERE name = N'getPublisherOperatorID' AND type = 'FN')
  955. DROP FUNCTION getPublisherOperatorID
  956. GO
  957. CREATE FUNCTION getPublisherOperatorID (
  958. @publisherID bigint)
  959. RETURNS bigint
  960. WITH ENCRYPTION
  961. AS
  962. BEGIN
  963. DECLARE
  964. @operatorID bigint
  965. SELECT
  966. @operatorID = [operatorID]
  967. FROM
  968. [UDO_operators]
  969. WHERE
  970. ([publisherID] = @publisherID)
  971. IF @operatorID IS NULL
  972. SET @operatorID = dbo.currentOperatorID()
  973. RETURN @operatorID
  974. END -- getPublisherOperatorID
  975. GO
  976. -- =============================================
  977. -- Name: getServicePublisherID
  978. -- =============================================
  979. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'getServicePublisherID' AND type = 'FN')
  980. DROP FUNCTION getServicePublisherID
  981. GO
  982. CREATE FUNCTION getServicePublisherID(
  983. @serviceKey uniqueidentifier)
  984. RETURNS bigint
  985. WITH ENCRYPTION
  986. AS
  987. BEGIN
  988. DECLARE
  989. @publisherID bigint,
  990. @businessKey uniqueidentifier
  991. SELECT
  992. @businessKey = dbo.businessKey(businessID)
  993. FROM
  994. [UDC_businessServices]
  995. WHERE
  996. serviceKey = @serviceKey
  997. SELECT @publisherID = dbo.getBusinessPublisherID(@businessKey)
  998. RETURN @publisherID
  999. END
  1000. GO
  1001. -- =============================================
  1002. -- Name: getTModelPublisherID
  1003. -- =============================================
  1004. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'getTModelPublisherID' AND type = 'FN')
  1005. DROP FUNCTION getTModelPublisherID
  1006. GO
  1007. CREATE FUNCTION getTModelPublisherID(
  1008. @tModelKey uniqueidentifier)
  1009. RETURNS bigint
  1010. WITH ENCRYPTION
  1011. AS
  1012. BEGIN
  1013. DECLARE
  1014. @publisherID bigint
  1015. SELECT @publisherID = publisherID FROM [UDC_tModels] WHERE tModelKey = @tModelKey
  1016. RETURN @publisherID
  1017. END
  1018. GO
  1019. -- =============================================
  1020. -- Section: Publisher helper functions
  1021. -- =============================================
  1022. -- =============================================
  1023. -- Name: defaultIsoLangCode
  1024. -- =============================================
  1025. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'defaultIsoLangCode' AND type='FN')
  1026. DROP FUNCTION defaultIsoLangCode
  1027. GO
  1028. CREATE FUNCTION defaultIsoLangCode (
  1029. @PUID nvarchar(450) = NULL)
  1030. RETURNS varchar(17)
  1031. WITH ENCRYPTION
  1032. AS
  1033. BEGIN
  1034. DECLARE
  1035. @isoLangCode varchar(17)
  1036. IF @PUID IS NULL
  1037. RETURN 'en'
  1038. -- Return the default isoLangCode for the current operator site
  1039. SELECT @isoLangCode = isoLangCode FROM [UDO_publishers] WHERE PUID = @PUID
  1040. IF @isoLangCode IS NULL
  1041. SET @isoLangCode = 'en'
  1042. RETURN @isoLangCode
  1043. END
  1044. GO
  1045. -- =============================================
  1046. -- Name: getPublisherStatus
  1047. -- =============================================
  1048. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'getPublisherStatus' AND type = 'FN')
  1049. DROP FUNCTION getPublisherStatus
  1050. GO
  1051. CREATE FUNCTION getPublisherStatus(
  1052. @PUID nvarchar(450))
  1053. RETURNS nvarchar(256)
  1054. WITH ENCRYPTION
  1055. AS
  1056. BEGIN
  1057. DECLARE
  1058. @publisherStatus nvarchar(256)
  1059. SELECT @publisherStatus = dbo.publisherStatus(publisherStatusID) FROM [UDO_publishers] WHERE PUID = @PUID
  1060. RETURN @publisherStatus
  1061. END
  1062. GO
  1063. -- =============================================
  1064. -- Name: publisherExists
  1065. -- =============================================
  1066. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'publisherExists' AND type = 'FN')
  1067. DROP FUNCTION publisherExists
  1068. GO
  1069. CREATE FUNCTION publisherExists(
  1070. @PUID nvarchar(450))
  1071. RETURNS bit
  1072. WITH ENCRYPTION
  1073. AS
  1074. BEGIN
  1075. DECLARE
  1076. @RC bit
  1077. IF EXISTS(SELECT * FROM [UDO_publishers] WHERE PUID = @PUID)
  1078. SET @RC = 1
  1079. ELSE
  1080. SET @RC = 0
  1081. RETURN @RC
  1082. END
  1083. GO
  1084. -- =============================================
  1085. -- Function: publisherOperatorName
  1086. -- =============================================
  1087. IF EXISTS (SELECT * FROM sysobjects WHERE name = N'publisherOperatorName' AND type = 'FN')
  1088. DROP FUNCTION publisherOperatorName
  1089. GO
  1090. CREATE FUNCTION publisherOperatorName (
  1091. @publisherID bigint)
  1092. RETURNS nvarchar(450)
  1093. WITH ENCRYPTION
  1094. AS
  1095. BEGIN
  1096. DECLARE
  1097. @name nvarchar(450)
  1098. SELECT
  1099. @name = [name]
  1100. FROM
  1101. [UDO_operators]
  1102. WHERE
  1103. ([publisherID] = @publisherID)
  1104. IF @name IS NULL
  1105. BEGIN
  1106. SELECT
  1107. @name = [name]
  1108. FROM
  1109. [UDO_operators]
  1110. WHERE
  1111. ([operatorID] = dbo.configValue('OperatorID'))
  1112. END
  1113. RETURN @name
  1114. END -- publisherOperatorName
  1115. GO
  1116. -- =============================================
  1117. -- Section: Replication helper functions
  1118. -- =============================================
  1119. -- =============================================
  1120. -- Name: entityExists()
  1121. -- =============================================
  1122. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'entityExists' AND type = 'FN')
  1123. DROP FUNCTION entityExists
  1124. GO
  1125. CREATE FUNCTION entityExists(
  1126. @entityKey uniqueidentifier,
  1127. @entityTypeID tinyint)
  1128. RETURNS bit
  1129. WITH ENCRYPTION
  1130. AS
  1131. BEGIN
  1132. DECLARE
  1133. @entityExists bit,
  1134. @rowCount int
  1135. IF dbo.entityType(@entityTypeID) NOT IN ('tModel', 'businessEntity', 'businessService', 'bindingTemplate')
  1136. RETURN 10500
  1137. SET @entityExists = 0
  1138. IF dbo.entityType(@entityTypeID) = 'tModel'
  1139. BEGIN
  1140. SELECT
  1141. @rowCount = COUNT(*)
  1142. FROM
  1143. [UDC_tModels]
  1144. WHERE
  1145. ([tModelKey] = @entityKey) AND
  1146. ([flag] = 0x0)
  1147. IF @rowCount = 0
  1148. RETURN 0
  1149. ELSE
  1150. RETURN 1
  1151. END
  1152. IF dbo.entityType(@entityTypeID) = 'businessEntity'
  1153. IF EXISTS(SELECT * FROM [UDC_businessEntities] WHERE [businessKey] = @entityKey)
  1154. RETURN 1
  1155. ELSE
  1156. RETURN 0
  1157. IF dbo.entityType(@entityTypeID) = 'businessService'
  1158. IF EXISTS(SELECT * FROM [UDC_businessServices] WHERE [serviceKey] = @entityKey)
  1159. RETURN 1
  1160. ELSE
  1161. RETURN 0
  1162. IF dbo.entityType(@entityTypeID) = 'bindingTemplate'
  1163. IF EXISTS(SELECT * FROM [UDC_bindingTemplates] WHERE [bindingKey] = @entityKey)
  1164. RETURN 1
  1165. ELSE
  1166. RETURN 0
  1167. RETURN @entityExists
  1168. END -- entityExists
  1169. GO
  1170. -- =============================================
  1171. -- Name: entityKeyStr()
  1172. -- =============================================
  1173. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'entityKeyStr' AND type = 'FN')
  1174. DROP FUNCTION entityKeyStr
  1175. GO
  1176. CREATE FUNCTION entityKeyStr(
  1177. @entityKey uniqueidentifier,
  1178. @entityTypeID tinyint)
  1179. RETURNS nvarchar(4000)
  1180. WITH ENCRYPTION
  1181. AS
  1182. BEGIN
  1183. DECLARE
  1184. @entityKeyStr nvarchar(4000)
  1185. IF dbo.entityType(@entityTypeID) = 'tModel'
  1186. SET @entityKeyStr = dbo.addURN(@entityKey)
  1187. ELSE
  1188. SET @entityKeyStr = dbo.UUIDSTR(@entityKey)
  1189. RETURN @entityKeyStr
  1190. END -- entityKeyStr
  1191. GO
  1192. -- =============================================
  1193. -- Name: isReplPublisher()
  1194. -- =============================================
  1195. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'isReplPublisher' AND type = 'FN')
  1196. DROP FUNCTION isReplPublisher
  1197. GO
  1198. CREATE FUNCTION isReplPublisher (
  1199. @PUID nvarchar(4000))
  1200. RETURNS bit
  1201. WITH ENCRYPTION
  1202. AS
  1203. BEGIN
  1204. DECLARE
  1205. @isReplPublisher bit
  1206. SET @isReplPublisher = 0
  1207. IF EXISTS(SELECT * FROM [UDO_operators] WHERE [publisherID] = dbo.publisherID(@PUID))
  1208. BEGIN
  1209. SET @isReplPublisher = 1
  1210. END
  1211. RETURN @isReplPublisher
  1212. END
  1213. GO
  1214. -- =============================================
  1215. -- Name: keyType()
  1216. -- =============================================
  1217. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'keyType' AND type = 'FN')
  1218. DROP FUNCTION keyType
  1219. GO
  1220. CREATE FUNCTION keyType(
  1221. @key uniqueidentifier
  1222. )
  1223. RETURNS nvarchar(256)
  1224. WITH ENCRYPTION
  1225. AS
  1226. BEGIN
  1227. -- Returns the key type of an arbitrary key, returns NULL if the key doesn't exist
  1228. DECLARE
  1229. @keyType nvarchar(256)
  1230. SET @keyType = NULL
  1231. IF EXISTS(SELECT [tModelKey] FROM [UDC_tModels] WHERE [tModelKey] = @key)
  1232. BEGIN
  1233. SET @keyType = 'tModelKey'
  1234. RETURN @keyType
  1235. END
  1236. IF EXISTS(SELECT [businessKey] FROM [UDC_businessEntities] WHERE [businessKey] = @key)
  1237. BEGIN
  1238. SET @keyType = 'businessKey'
  1239. RETURN @keyType
  1240. END
  1241. IF EXISTS(SELECT [serviceKey] FROM [UDC_businessServices] WHERE [serviceKey] = @key)
  1242. BEGIN
  1243. SET @keyType = 'serviceKey'
  1244. RETURN @keyType
  1245. END
  1246. IF EXISTS(SELECT [bindingKey] FROM [UDC_bindingTemplates] WHERE [bindingKey] = @key)
  1247. BEGIN
  1248. SET @keyType = 'bindingKey'
  1249. RETURN @keyType
  1250. END
  1251. RETURN @keyType
  1252. END
  1253. GO
  1254. -- =============================================
  1255. -- Section: String and Conversion helper functions
  1256. -- =============================================
  1257. -- =============================================
  1258. -- Name: addURN()
  1259. -- =============================================
  1260. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'addURN' AND type='FN')
  1261. DROP FUNCTION addURN
  1262. GO
  1263. CREATE FUNCTION addURN
  1264. (@guid uniqueidentifier)
  1265. RETURNS varchar(256)
  1266. WITH ENCRYPTION
  1267. AS
  1268. BEGIN
  1269. DECLARE
  1270. @guidStr varchar(256)
  1271. SET @guidStr='uuid:' + CAST(@guid AS varchar(256))
  1272. RETURN @guidStr
  1273. END -- addURN()
  1274. GO
  1275. -- =============================================
  1276. -- Name: UUIDSTR
  1277. -- =============================================
  1278. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'UUIDSTR' AND type = 'FN')
  1279. DROP FUNCTION UUIDSTR
  1280. GO
  1281. CREATE FUNCTION UUIDSTR(
  1282. @uuid uniqueidentifier)
  1283. RETURNS varchar(256)
  1284. WITH ENCRYPTION
  1285. AS
  1286. BEGIN
  1287. DECLARE
  1288. @uuidStr varchar(256)
  1289. SET @uuidStr = CAST(@uuid AS varchar(256))
  1290. RETURN @uuidStr
  1291. END
  1292. GO
  1293. -- =============================================
  1294. -- Section: Validation helper functions
  1295. -- =============================================
  1296. -- =============================================
  1297. -- Name: validTaxonomyValue()
  1298. -- =============================================
  1299. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'validTaxonomyValue' AND type = 'FN')
  1300. DROP FUNCTION validTaxonomyValue
  1301. GO
  1302. CREATE FUNCTION validTaxonomyValue (
  1303. @tModelKey uniqueidentifier,
  1304. @keyValue nvarchar(225))
  1305. RETURNS bit
  1306. WITH ENCRYPTION
  1307. AS
  1308. BEGIN
  1309. DECLARE
  1310. @RC bit
  1311. IF (@tModelKey IS NOT NULL) AND (@keyValue IS NOT NULL)
  1312. IF EXISTS(SELECT * FROM [UDT_taxonomyValues] WHERE ([taxonomyID] = dbo.taxonomyID(@tModelKey)) AND ([keyValue] = @keyValue) AND ([valid]= 1))
  1313. SET @RC=1
  1314. ELSE
  1315. SET @RC=0
  1316. ELSE
  1317. SET @RC=0
  1318. RETURN @RC
  1319. END -- validTaxonomyValue()
  1320. GO
  1321. -- =============================================
  1322. -- Name: checkedTaxonomy()
  1323. -- =============================================
  1324. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'checkedTaxonomy' AND type = 'FN')
  1325. DROP FUNCTION checkedTaxonomy
  1326. GO
  1327. CREATE FUNCTION checkedTaxonomy (
  1328. @tModelKey uniqueidentifier)
  1329. RETURNS bit
  1330. WITH ENCRYPTION
  1331. AS
  1332. BEGIN
  1333. DECLARE
  1334. @RC bit,
  1335. @flag int
  1336. SET @RC = 0
  1337. SELECT
  1338. @flag = [flag]
  1339. FROM
  1340. [UDT_taxonomies]
  1341. WHERE
  1342. [tModelKey] = @tModelKey
  1343. IF @flag IS NOT NULL
  1344. IF dbo.checkFlag(@flag,0x1) = 1
  1345. SET @RC = 1
  1346. RETURN @RC
  1347. END -- checkedTaxonomy()
  1348. GO
  1349. -- =============================================
  1350. -- Name: ISGUID()
  1351. -- =============================================
  1352. IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ISGUID' AND type='FN')
  1353. DROP FUNCTION ISGUID
  1354. GO
  1355. CREATE FUNCTION ISGUID
  1356. (@guidText varchar(256))
  1357. RETURNS int
  1358. WITH ENCRYPTION
  1359. AS
  1360. BEGIN
  1361. DECLARE
  1362. @guidPattern1 varchar(256),
  1363. @guidPattern2 varchar(256),
  1364. @pos1 int,
  1365. @pos2 int,
  1366. @RC int
  1367. SET @RC = 0
  1368. IF @guidText IS NULL
  1369. RETURN 1
  1370. SET @guidPattern1 ='%[0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F]-[0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F]-[0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F]-[0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F]-%'
  1371. SET @guidPattern2 ='%-[0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F]%'
  1372. -- Check for standard GUID string with no curly braces
  1373. SELECT @pos1=PATINDEX(@guidPattern1, UPPER(@guidText))
  1374. SELECT @pos2=PATINDEX(@guidPattern2, UPPER(@guidText))
  1375. IF (@pos1 = 1) AND (@pos2 = 24)
  1376. SET @RC=1
  1377. ELSE
  1378. BEGIN
  1379. -- Check for standard GUID string with curly braces
  1380. SET @guidPattern1 ='%{[0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F]-[0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F]-[0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F]-[0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F]-%'
  1381. SET @guidPattern2 ='%-[0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F][0-9,A-F]}%'
  1382. SELECT @pos1=PATINDEX(@guidPattern1, UPPER(@guidText))
  1383. SELECT @pos2=PATINDEX(@guidPattern2, UPPER(@guidText))
  1384. IF (@pos1 = 1) AND (@pos2 = 25)
  1385. SET @RC=1
  1386. ELSE
  1387. SET @RC=0
  1388. END
  1389. RETURN @RC
  1390. END
  1391. GO
  1392. -- =============================================
  1393. -- Name: isUuidUnique
  1394. -- =============================================
  1395. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'isUuidUnique' AND type = 'FN')
  1396. DROP FUNCTION isUuidUnique
  1397. GO
  1398. CREATE FUNCTION isUuidUnique(
  1399. @uuid uniqueidentifier)
  1400. RETURNS bit
  1401. WITH ENCRYPTION
  1402. AS
  1403. BEGIN
  1404. IF EXISTS(SELECT [tModelKey] FROM [UDC_tModels] WHERE [tModelKey] = @uuid)
  1405. RETURN 0
  1406. IF EXISTS(SELECT [businessKey] FROM [UDC_businessEntities] WHERE [businessKey] = @uuid)
  1407. RETURN 0
  1408. IF EXISTS(SELECT [serviceKey] FROM [UDC_businessServices] WHERE [serviceKey] = @uuid)
  1409. RETURN 0
  1410. IF EXISTS(SELECT [bindingKey] FROM [UDC_bindingTemplates] WHERE [bindingKey] = @uuid)
  1411. RETURN 0
  1412. RETURN 1
  1413. END -- isUuidUnique()
  1414. GO
  1415. -- =============================================
  1416. -- Section: Miscellaneous functions
  1417. -- =============================================
  1418. -- =============================================
  1419. -- Name: checkFlag()
  1420. -- =============================================
  1421. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'checkFlag' AND type = 'FN')
  1422. DROP FUNCTION checkFlag
  1423. GO
  1424. CREATE FUNCTION checkFlag(
  1425. @flag int,
  1426. @bit int)
  1427. RETURNS bit
  1428. WITH ENCRYPTION
  1429. AS
  1430. BEGIN
  1431. DECLARE
  1432. @RC bit
  1433. IF @flag & @bit = @bit
  1434. SET @RC=1
  1435. ELSE
  1436. SET @RC=0
  1437. RETURN @RC
  1438. END
  1439. GO
  1440. -- =============================================
  1441. -- Name: isReportRunning
  1442. -- =============================================
  1443. IF EXISTS (SELECT name FROM sysobjects WHERE name = 'isReportRunning' AND type = 'FN')
  1444. DROP FUNCTION isReportRunning
  1445. GO
  1446. CREATE FUNCTION isReportRunning (
  1447. @reportID sysname,
  1448. @now datetime)
  1449. RETURNS bit
  1450. WITH ENCRYPTION
  1451. AS
  1452. BEGIN
  1453. DECLARE
  1454. @isReportRunning bit,
  1455. @reportStatusID tinyint,
  1456. @lastChange datetime
  1457. SET @isReportRunning = 0
  1458. SELECT
  1459. @reportStatusID = [reportStatusID],
  1460. @lastChange = [lastChange]
  1461. FROM
  1462. [UDO_reports]
  1463. WHERE
  1464. ([reportID] = @reportID)
  1465. --
  1466. -- Check to see if report is already running.
  1467. -- If report has been running for less than 5 minutes get out.
  1468. -- If report has been running for more than 5 assume failure and rerun.
  1469. --
  1470. IF (@reportStatusID = dbo.reportStatusID('Processing')) AND (DATEDIFF(mi, @lastChange, @now) < 5)
  1471. SET @isReportRunning = 1
  1472. RETURN @isReportRunning
  1473. END -- isReportRunning
  1474. GO