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.

1003 lines
23 KiB

  1. -- Script: uddi.v2.repl.sql
  2. -- Author: [email protected]
  3. -- Description: Creates replication stored procedures.
  4. -- Note: This file is best viewed and edited with a tab width of 2.
  5. -- =============================================
  6. -- Section: Update routines
  7. -- =============================================
  8. -- =============================================
  9. -- Name: net_changeRecord_save
  10. -- =============================================
  11. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_changeRecord_save' AND type = 'P')
  12. DROP PROCEDURE net_changeRecord_save
  13. GO
  14. CREATE PROCEDURE net_changeRecord_save
  15. @USN bigint = NULL, -- NULL for local changeRecords
  16. @PUID nvarchar(450) = NULL, -- NULL for remote changeRecords
  17. @delegatePUID nvarchar(450) = NULL, -- NULL for remote changeRecords or local changeRecords with no delegate
  18. @operatorKey uniqueidentifier = NULL, -- NULL for local changeRecords
  19. @entityKey uniqueidentifier = NULL, -- entityKey for top-level entity in changeRecord
  20. @entityTypeID tinyint = NULL, -- entityType for top-level entity in changeRecord
  21. @changeTypeID tinyint, -- changeType for current save operation
  22. @contextID uniqueidentifier, -- contextID for current save operation
  23. @contextTypeID tinyint, -- contextType for current save operation
  24. @lastChange bigint, -- timestamp for changeRecord
  25. @changeData ntext, -- payload for current save operation
  26. @flag int = 0, -- for future use
  27. @seqNo bigint OUTPUT -- seqNo of newly created changeRecord
  28. WITH ENCRYPTION
  29. AS
  30. BEGIN
  31. DECLARE
  32. @error int,
  33. @context nvarchar(4000),
  34. @publisherID bigint,
  35. @delegatePublisherID bigint,
  36. @operatorID bigint,
  37. @RC int
  38. -- Validate parameters
  39. IF (@PUID IS NOT NULL) AND (@operatorKey IS NOT NULL)
  40. BEGIN
  41. SET @error = 50009 -- E_parmError
  42. SET @context = 'Must pass either @PUID (local) or @operatorKey (remote).'
  43. GOTO errorLabel
  44. END
  45. IF (@operatorKey IS NOT NULL)
  46. BEGIN
  47. SET @operatorID = dbo.operatorID(@operatorKey)
  48. IF @operatorID IS NULL
  49. BEGIN
  50. SET @error = 60150 -- E_unknownUser
  51. SET @context = '@operatorKey = ' + dbo.UUIDSTR(@operatorKey)
  52. GOTO errorLabel
  53. END
  54. SELECT
  55. @PUID = PU.[PUID]
  56. FROM
  57. [UDO_publishers] PU
  58. JOIN [UDO_operators] OP ON PU.[publisherID] = OP.[publisherID]
  59. WHERE
  60. (OP.[operatorID] = @operatorID)
  61. IF @delegatePUID IS NOT NULL
  62. BEGIN
  63. SET @error = 50009 -- E_parmError
  64. SET @context = '@delegatePUID not valid for remote changeRecords.'
  65. GOTO errorLabel
  66. END
  67. SET @publisherID = dbo.publisherID(@PUID)
  68. END -- @operatorKey
  69. ELSE
  70. BEGIN -- Local change records
  71. IF @delegatePUID IS NOT NULL
  72. BEGIN
  73. SET @delegatePublisherID = dbo.publisherID(@delegatePUID)
  74. IF @delegatePublisherID IS NULL
  75. BEGIN
  76. SET @error = 60150 -- E_unknownUser
  77. SET @context = 'Invalid delegate PUID. Delegates must be registered as publishers prior to impersonating other users.'
  78. GOTO errorLabel
  79. END
  80. END
  81. IF @PUID IS NULL
  82. SET @publisherID = dbo.currentOperatorID()
  83. ELSE
  84. SET @publisherID = dbo.publisherID(@PUID)
  85. END
  86. IF @publisherID IS NULL
  87. BEGIN
  88. SET @error = 60150 -- E_unknownUser
  89. SET @context = 'Invalid PUID.'
  90. GOTO errorLabel
  91. END
  92. ELSE
  93. -- Insert changeRecord
  94. INSERT [UDO_changeLog] (
  95. [USN],
  96. [newSeqNo],
  97. [publisherID],
  98. [delegatePublisherID],
  99. [entityKey],
  100. [entityTypeID],
  101. [changeTypeID],
  102. [contextID],
  103. [contextTypeID],
  104. [lastChange],
  105. [changeData],
  106. [flag])
  107. VALUES (
  108. @USN,
  109. NULL,
  110. @publisherID,
  111. @delegatePublisherID,
  112. @entityKey,
  113. @entityTypeID,
  114. @changeTypeID,
  115. @contextID,
  116. @contextTypeID,
  117. @lastChange,
  118. @changeData,
  119. @flag)
  120. SET @seqNo = @@IDENTITY
  121. RETURN 0
  122. errorLabel:
  123. RAISERROR (@error, 16, 1, @context)
  124. RETURN 1
  125. END -- net_changeRecord_save
  126. GO
  127. -- =============================================
  128. -- Name: net_changeRecord_update
  129. -- =============================================
  130. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_changeRecord_update' AND type = 'P')
  131. DROP PROCEDURE net_changeRecord_update
  132. GO
  133. CREATE PROCEDURE net_changeRecord_update
  134. @seqNo bigint = NULL, -- NULL for remote changeRecords
  135. @USN bigint = NULL, -- NULL for local changeRecords
  136. @operatorKey uniqueidentifier = NULL, -- NULL for local changeRecords
  137. @newSeqNo bigint = NULL, -- seqNo of corrected changeRecord
  138. @flag int = NULL -- updated flag value
  139. WITH ENCRYPTION
  140. AS
  141. BEGIN
  142. DECLARE
  143. @error int,
  144. @context nvarchar(4000),
  145. @operatorID bigint,
  146. @publisherID bigint
  147. -- Check parameters
  148. IF @seqNo IS NOT NULL AND @USN IS NOT NULL
  149. BEGIN
  150. SET @error = 50009 -- E_parmError
  151. SET @context = 'Procedure accepts either @seqNo or @USN parameters, not both.'
  152. GOTO errorLabel
  153. END
  154. IF @newSeqNo IS NOT NULL
  155. BEGIN
  156. IF NOT EXISTS(SELECT [seqNo] FROM [UDO_changeLog] WHERE (([seqNo] = @newSeqNo) AND ([changeTypeID] = dbo.changeTypeID('changeRecordCorrection'))))
  157. BEGIN
  158. SET @error = 50015 -- E_invalidSeqNo
  159. SET @context = '@newSeqNo = ' + CAST(@newSeqNo AS varchar(256))
  160. GOTO errorLabel
  161. END
  162. END
  163. IF @seqNo IS NOT NULL
  164. BEGIN
  165. UPDATE [UDO_changeLog] SET
  166. [newSeqNo] = ISNULL(@newSeqNo, [newSeqNo]),
  167. [flag] = ISNULL(@flag, [flag])
  168. WHERE
  169. ([seqNo] = @seqNo) AND
  170. ([changeTypeID] <> dbo.changeTypeID('changeRecordCorrection'))
  171. IF @@ROWCOUNT = 0
  172. BEGIN
  173. SET @error = 50015 -- E_invalidSeqNo
  174. SET @context = 'changeRecord for seqNo = ' + CAST(@seqNo AS varchar(256)) + ' is invalid.'
  175. GOTO errorLabel
  176. END
  177. END
  178. IF @USN IS NOT NULL
  179. BEGIN
  180. IF @operatorKey IS NULL
  181. BEGIN
  182. SET @error = 50009 -- E_parmError
  183. SET @context = '@operatorKey required when annotating a USN.'
  184. END
  185. SET @operatorID = dbo.operatorID(@operatorKey)
  186. IF @operatorID IS NULL
  187. BEGIN
  188. SET @error = 60150 -- E_unknownUser
  189. SET @context = 'Unknown operatorKey: ' + dbo.UUIDSTR(@operatorKey)
  190. GOTO errorLabel
  191. END
  192. SET @publisherID = dbo.getOperatorPublisherID(@operatorID)
  193. UPDATE [UDO_changeLog] SET
  194. [newSeqNo] = ISNULL(@newSeqNo, [newSeqNo]),
  195. [flag] = ISNULL(@flag, [flag])
  196. WHERE
  197. ([USN] = @USN) AND
  198. ([publisherID] = @publisherID) AND
  199. ([changeTypeID] <> dbo.changeTypeID('changeRecordCorrection'))
  200. IF @@ROWCOUNT = 0
  201. BEGIN
  202. SET @error = 50015 -- E_invalidSeqNo
  203. SET @context = 'changeRecord for USN = ' + CAST(@USN AS varchar(256)) + ' is invalid.'
  204. GOTO errorLabel
  205. END
  206. END
  207. RETURN 0
  208. errorLabel:
  209. RAISERROR (@error, 16, 1, @context)
  210. RETURN 1
  211. END -- net_changeRecord_update
  212. GO
  213. -- =============================================
  214. -- Section: Find and get routines
  215. -- =============================================
  216. -- =============================================
  217. -- Name: net_find_changeRecords
  218. -- =============================================
  219. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_find_changeRecords' AND type = 'P')
  220. DROP PROCEDURE net_find_changeRecords
  221. GO
  222. CREATE PROCEDURE net_find_changeRecords
  223. @contextID uniqueidentifier, -- contextID of current find operation
  224. @operatorKey uniqueidentifier, -- operatorKey for source operator node
  225. @startUSN bigint, -- low end of USN range, NULL for 0
  226. @stopUSN bigint, -- high end of USN range, NULL for max
  227. @rows bigint OUTPUT -- rows added to UDS_findResults
  228. WITH ENCRYPTION
  229. AS
  230. BEGIN
  231. DECLARE
  232. @error int,
  233. @context nvarchar(4000),
  234. @operatorID bigint,
  235. @publisherID bigint,
  236. @i int
  237. SET @rows = 0
  238. IF @startUSN > @stopUSN
  239. BEGIN
  240. SET @error = 50009 -- E_parmError
  241. SET @context = '@startUSN must be less than or equal to @stopUSN.'
  242. GOTO errorLabel
  243. END
  244. SET @operatorID = dbo.operatorID(@operatorKey)
  245. IF @operatorID IS NULL
  246. BEGIN
  247. SET @error = 60150 -- E_unknownUser
  248. SET @context = 'operatorKey = ' + dbo.UUIDSTR(@operatorKey)
  249. GOTO errorLabel
  250. END
  251. SET @publisherID = dbo.getOperatorPublisherID(@operatorID)
  252. IF (@operatorID = dbo.currentOperatorID())
  253. BEGIN
  254. -- Find changeRecords for the local operator
  255. INSERT [UDS_replResults] (
  256. [contextID],
  257. [seqNo])
  258. SELECT
  259. @contextID,
  260. [seqNo]
  261. FROM
  262. [UDO_changeLog]
  263. WHERE
  264. ([seqNo] BETWEEN @startUSN and @stopUSN) AND
  265. ([USN] IS NULL)
  266. ORDER BY
  267. [seqNo] ASC
  268. END
  269. ELSE
  270. BEGIN
  271. INSERT [UDS_replResults] (
  272. [contextID],
  273. [seqNo])
  274. SELECT
  275. @contextID,
  276. [seqNo]
  277. FROM
  278. [UDO_changeLog]
  279. WHERE
  280. ([USN] BETWEEN @startUSN and @stopUSN) AND
  281. ([publisherID] = @publisherID)
  282. ORDER BY
  283. [seqNo] ASC
  284. END
  285. SET @rows = @@ROWCOUNT
  286. RETURN 0
  287. errorLabel:
  288. RAISERROR (@error, 16, 1, @context)
  289. RETURN 1
  290. END -- net_find_changeRecords
  291. GO
  292. -- =============================================
  293. -- Name: net_find_changeRecords_cleanup
  294. -- =============================================
  295. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_find_changeRecords_cleanup' AND type = 'P')
  296. DROP PROCEDURE net_find_changeRecords_cleanup
  297. GO
  298. CREATE PROCEDURE net_find_changeRecords_cleanup
  299. @contextID uniqueidentifier -- contextID of current find operation
  300. WITH ENCRYPTION
  301. AS
  302. BEGIN
  303. DECLARE
  304. @error int,
  305. @context nvarchar(4000)
  306. DELETE
  307. [UDS_replResults]
  308. WHERE
  309. ([contextID] = @contextID)
  310. RETURN 0
  311. errorLabel:
  312. RAISERROR (@error, 16, 1, @context)
  313. RETURN 1
  314. END -- net_find_changeRecords_cleanup
  315. GO
  316. -- =============================================
  317. -- Name: net_find_changeRecords_commit
  318. -- =============================================
  319. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_find_changeRecords_commit' AND type = 'P')
  320. DROP PROCEDURE net_find_changeRecords_commit
  321. GO
  322. CREATE PROCEDURE net_find_changeRecords_commit
  323. @contextID uniqueidentifier, -- contextID of current find operation
  324. @responseLimitCount bigint -- limits number of rows returned, 0 for all
  325. WITH ENCRYPTION
  326. AS
  327. BEGIN
  328. DECLARE
  329. @error int,
  330. @context nvarchar(4000),
  331. @RC int,
  332. @changeRecord cursor,
  333. @seqNo bigint,
  334. @USN bigint,
  335. @newSeqNo bigint,
  336. @publisherID bigint,
  337. @changeDataSeqNo bigint,
  338. @flag int,
  339. @rowNum bigint
  340. CREATE TABLE #tempResults (
  341. [seqNo] bigint,
  342. [USN] bigint,
  343. [newSeqNo] bigint,
  344. [publisherID] bigint,
  345. [changeDataSeqNo] bigint,
  346. [flag] int)
  347. -- Set responseLimitCount
  348. IF ISNULL(@responseLimitCount,0) = 0
  349. SET @responseLimitCount = ISNULL(dbo.configValue('Replication.ResponseLimitCountDefault'),1000)
  350. SET @changeRecord = CURSOR LOCAL FORWARD_ONLY READ_ONLY FOR
  351. SELECT DISTINCT
  352. CL.[seqNo],
  353. CL.[USN],
  354. CL.[newSeqNo],
  355. CL.[publisherID],
  356. CL.[flag]
  357. FROM
  358. [UDO_changeLog] CL
  359. JOIN [UDS_replResults] RR ON CL.[seqNo] = RR.[seqNo]
  360. WHERE
  361. (RR.[contextID] = @contextID)
  362. ORDER BY
  363. 1 ASC
  364. OPEN @changeRecord
  365. FETCH NEXT FROM @changeRecord INTO
  366. @seqNo,
  367. @USN,
  368. @newSeqNo,
  369. @publisherID,
  370. @flag
  371. SET @rowNum = 0
  372. WHILE @@FETCH_STATUS = 0
  373. BEGIN
  374. SET @rowNum = @rowNum + 1
  375. IF @rowNum > @responseLimitCount
  376. BREAK
  377. IF @newSeqNo IS NULL
  378. SET @changeDataSeqNo = @seqNo
  379. ELSE
  380. SET @changeDataSeqNo = @newSeqNo
  381. INSERT #tempResults(
  382. [seqNo],
  383. [USN],
  384. [newSeqNo],
  385. [publisherID],
  386. [changeDataSeqNo],
  387. [flag])
  388. VALUES (
  389. @seqNo,
  390. @USN,
  391. @newSeqNo,
  392. @publisherID,
  393. @changeDataSeqNo,
  394. @flag)
  395. FETCH NEXT FROM @changeRecord INTO
  396. @seqNo,
  397. @USN,
  398. @newSeqNo,
  399. @publisherID,
  400. @flag
  401. END
  402. CLOSE @changeRecord
  403. SELECT
  404. TR.[seqNo] AS [seqNo],
  405. ISNULL(TR.[USN], TR.[seqNo]) AS [USN],
  406. dbo.operatorKey(dbo.getPublisherOperatorID(TR.[publisherID])) AS [operatorKey],
  407. CL.[changeData] AS [changeData],
  408. CL.[changeTypeID] AS [changeTypeID],
  409. TR.[flag] AS [flag]
  410. FROM
  411. #tempResults TR
  412. JOIN [UDO_changeLog] CL ON TR.[changeDataSeqNo] = CL.[seqNo]
  413. ORDER BY
  414. 1 ASC
  415. EXEC @RC=net_find_changeRecords_cleanup @contextID
  416. IF @RC <> 0
  417. BEGIN
  418. SET @error = 50006 -- E_subProcFailure
  419. SET @context = ''
  420. GOTO errorLabel
  421. END
  422. RETURN 0
  423. errorLabel:
  424. RAISERROR (@error, 16, 1, @context)
  425. RETURN 1
  426. END -- net_find_changeRecords_commit
  427. GO
  428. -- =============================================
  429. -- Section: Operator routines
  430. -- =============================================
  431. -- =============================================
  432. -- Name: net_operator_save
  433. -- =============================================
  434. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_operator_save' AND type = 'P')
  435. DROP PROCEDURE net_operator_save
  436. GO
  437. CREATE PROCEDURE net_operator_save
  438. @operatorKey uniqueidentifier, -- insert only
  439. @PUID nvarchar(450) = NULL, -- insert only
  440. @operatorStatusID tinyint = NULL, -- insert / update (NULL for no change)
  441. @name nvarchar(450) = NULL, -- insert / update (NULL for no change)
  442. @soapReplicationURL nvarchar(4000) = NULL, -- insert / update (NULL for no change)
  443. @businessKey uniqueidentifier = NULL, -- insert / update (NULL for no change)
  444. @certSerialNo nvarchar(450) = NULL, -- insert / update (NULL for no change)
  445. @certIssuer nvarchar(225) = NULL, -- insert / update (NULL for no change)
  446. @certSubject nvarchar(225) = NULL, -- insert / update (NULL for no change)
  447. @certificate image -- insert / update (always required)
  448. WITH ENCRYPTION
  449. AS
  450. BEGIN
  451. DECLARE
  452. @error int,
  453. @context nvarchar(4000),
  454. @publisherID bigint,
  455. @oldOperatorStatusID tinyint,
  456. @oldName nvarchar(4000),
  457. @oldBusinessKey uniqueidentifier,
  458. @oldSoapReplicationURL nvarchar(4000),
  459. @oldCertSerialNo nvarchar(450),
  460. @oldCertIssuer nvarchar(225),
  461. @oldCertSubject nvarchar(225)
  462. IF EXISTS(SELECT * FROM [UDO_operators] WHERE [operatorKey] = @operatorKey)
  463. BEGIN
  464. -- Update Logic
  465. SELECT
  466. @oldOperatorStatusID = [operatorStatusID],
  467. @oldName = [name],
  468. @oldBusinessKey = [businessKey],
  469. @oldSoapReplicationURL = [soapReplicationURL],
  470. @oldCertSerialNo = [certSerialNo],
  471. @oldCertIssuer = [certIssuer],
  472. @oldCertSubject = [certSubject]
  473. FROM
  474. [UDO_operators]
  475. WHERE
  476. ([operatorKey] = @operatorKey)
  477. UPDATE
  478. [UDO_operators]
  479. SET
  480. [operatorStatusID] = ISNULL(@operatorStatusID, @oldOperatorStatusID),
  481. [name] = ISNULL(@name, @oldName),
  482. [businessKey] = ISNULL(@businessKey, @oldBusinessKey),
  483. [soapReplicationURL] = ISNULL(@soapReplicationURL, @oldSoapReplicationURL),
  484. [certSerialNo] = ISNULL(@certSerialNo, @oldCertSerialNo),
  485. [certIssuer] = ISNULL(@certIssuer, @oldCertIssuer),
  486. [certSubject] = ISNULL(@certSubject, @oldCertSubject),
  487. [certificate] = @certificate
  488. WHERE
  489. ([operatorKey] = @operatorKey)
  490. END
  491. ELSE
  492. BEGIN
  493. -- Insert Logic
  494. -- Validate @publisherID
  495. IF @PUID IS NOT NULL
  496. SET @publisherID = dbo.publisherID(@PUID)
  497. IF @publisherID IS NULL
  498. BEGIN
  499. SET @error = 60150 -- E_unknownUser
  500. SET @context = ''
  501. GOTO errorLabel
  502. END
  503. IF EXISTS(SELECT * FROM [UDO_operators] WHERE [publisherID] = @publisherID)
  504. BEGIN
  505. SET @error = 60140 -- E_userMismatch
  506. SET @context = 'Publisher is already being used by another operator.'
  507. GOTO errorLabel
  508. END
  509. INSERT [UDO_operators](
  510. [operatorKey],
  511. [publisherID],
  512. [operatorStatusID],
  513. [name],
  514. [businessKey],
  515. [soapReplicationURL],
  516. [certSerialNo],
  517. [certIssuer],
  518. [certSubject],
  519. [certificate],
  520. [flag])
  521. VALUES(
  522. @operatorKey,
  523. @publisherID,
  524. ISNULL(@operatorStatusID,dbo.operatorStatusID('new')),
  525. @name,
  526. @businessKey,
  527. @soapReplicationURL,
  528. @certSerialNo,
  529. @certIssuer,
  530. @certSubject,
  531. @certificate,
  532. 0)
  533. END
  534. RETURN 0
  535. errorLabel:
  536. RAISERROR (@error, 16, 1, @context)
  537. RETURN 1
  538. END -- net_operator_save
  539. GO
  540. -- =============================================
  541. -- Name: net_operator_get
  542. -- =============================================
  543. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_operator_get' AND type = 'P')
  544. DROP PROCEDURE net_operator_get
  545. GO
  546. CREATE PROCEDURE net_operator_get
  547. @operatorKey uniqueidentifier
  548. WITH ENCRYPTION
  549. AS
  550. BEGIN
  551. -- Gets a single operator
  552. DECLARE
  553. @error int,
  554. @context nvarchar(4000),
  555. @operatorID bigint
  556. SET @operatorID = dbo.operatorID(@operatorKey)
  557. IF @operatorID IS NULL
  558. BEGIN
  559. SET @error = 60150 -- E_unknownUser
  560. SET @context = 'Invalid operatorKey: ' + dbo.UUIDSTR(@operatorKey)
  561. GOTO errorLabel
  562. END
  563. SELECT
  564. [operatorStatusID],
  565. [name],
  566. [soapReplicationURL],
  567. [certSerialNo],
  568. [certIssuer],
  569. [certSubject],
  570. [certificate]
  571. FROM
  572. [UDO_operators]
  573. WHERE
  574. ([operatorID] = @operatorID)
  575. RETURN 0
  576. errorLabel:
  577. RAISERROR (@error, 16, 1, @context)
  578. RETURN 1
  579. END -- net_operator_get
  580. GO
  581. -- =============================================
  582. -- Name: net_operators_get
  583. -- =============================================
  584. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_operators_get' AND type = 'P')
  585. DROP PROCEDURE net_operators_get
  586. GO
  587. CREATE PROCEDURE net_operators_get
  588. WITH ENCRYPTION
  589. AS
  590. BEGIN
  591. -- Gets all operators
  592. DECLARE
  593. @error int,
  594. @context nvarchar(4000)
  595. SELECT
  596. [operatorKey],
  597. [operatorStatusID],
  598. [name],
  599. [soapReplicationURL]
  600. FROM
  601. [UDO_operators]
  602. RETURN 0
  603. errorLabel:
  604. RAISERROR (@error, 16, 1, @context)
  605. RETURN 1
  606. END -- net_operators_get
  607. GO
  608. -- =============================================
  609. -- Name: net_operator_delete
  610. -- =============================================
  611. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_operator_delete' AND type = 'P')
  612. DROP PROCEDURE net_operator_delete
  613. GO
  614. CREATE PROCEDURE net_operator_delete
  615. @operatorKey uniqueidentifier
  616. WITH ENCRYPTION
  617. AS
  618. BEGIN
  619. -- Gets a single operator
  620. DECLARE
  621. @error int,
  622. @context nvarchar(4000),
  623. @operatorID bigint
  624. SET @operatorID = dbo.operatorID(@operatorKey)
  625. IF @operatorID IS NULL
  626. BEGIN
  627. SET @error = 60150 -- E_unknownUser
  628. SET @context = 'Invalid operatorKey: ' + dbo.UUIDSTR(@operatorKey)
  629. GOTO errorLabel
  630. END
  631. DELETE
  632. [UDO_operators]
  633. WHERE
  634. ([operatorID] = @operatorID)
  635. RETURN 0
  636. errorLabel:
  637. RAISERROR (@error, 16, 1, @context)
  638. RETURN 1
  639. END -- net_operator_delete
  640. GO
  641. -- =============================================
  642. -- Name: net_highWaterMarks_get
  643. -- =============================================
  644. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_highWaterMarks_get' AND type = 'P')
  645. DROP PROCEDURE net_highWaterMarks_get
  646. GO
  647. CREATE PROCEDURE net_highWaterMarks_get
  648. WITH ENCRYPTION
  649. AS
  650. BEGIN
  651. DECLARE
  652. @error int,
  653. @context nvarchar(4000),
  654. @currentOperatorID bigint,
  655. @operatorID bigint,
  656. @rows bigint,
  657. @operatorCursor cursor
  658. DECLARE @results TABLE(
  659. [operatorKey] uniqueidentifier,
  660. [USN] bigint)
  661. -- Calculate current highWaterMark for local operator
  662. SET @currentOperatorID = dbo.currentOperatorID()
  663. SELECT
  664. @rows = MAX([seqNo])
  665. FROM
  666. [UDO_changeLog]
  667. WHERE
  668. ([publisherID] NOT IN (SELECT [publisherID] FROM [UDO_operators] WHERE [operatorID] <> @currentOperatorID))
  669. INSERT @results VALUES(
  670. dbo.operatorKey(@currentOperatorID),
  671. ISNULL(@rows,0))
  672. SET @operatorCursor = CURSOR LOCAL FORWARD_ONLY READ_ONLY FOR
  673. SELECT
  674. [operatorID]
  675. FROM
  676. [UDO_operators]
  677. WHERE
  678. [operatorID] <> @currentOperatorID
  679. OPEN @operatorCursor
  680. FETCH NEXT FROM @operatorCursor INTO
  681. @operatorID
  682. WHILE @@FETCH_STATUS = 0
  683. BEGIN
  684. SELECT
  685. @rows = MAX([USN])
  686. FROM
  687. [UDO_changeLog]
  688. WHERE
  689. ([publisherID] = dbo.getOperatorPublisherID(@operatorID))
  690. INSERT @results VALUES(
  691. dbo.operatorKey(@operatorID),
  692. ISNULL(@rows,0))
  693. FETCH NEXT FROM @operatorCursor INTO
  694. @operatorID
  695. END
  696. CLOSE @operatorCursor
  697. SELECT * FROM @results
  698. RETURN 0
  699. errorLabel:
  700. RAISERROR (@error, 16, 1, @context)
  701. RETURN 1
  702. END -- net_highWaterMarks_get
  703. GO
  704. -- =============================================
  705. -- Name: net_operatorLog_save
  706. -- =============================================
  707. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_operatorLog_save' AND type = 'P')
  708. DROP PROCEDURE net_operatorLog_save
  709. GO
  710. CREATE PROCEDURE net_operatorLog_save
  711. @operatorKey uniqueidentifier,
  712. @replStatusID tinyint,
  713. @description nvarchar(4000) = NULL,
  714. @lastOperatorKey uniqueidentifier = NULL,
  715. @lastUSN bigint = NULL,
  716. @lastChange bigint
  717. WITH ENCRYPTION
  718. AS
  719. BEGIN
  720. DECLARE
  721. @error int,
  722. @context nvarchar(4000),
  723. @operatorID bigint
  724. SET @operatorID = dbo.operatorID(@operatorKey)
  725. IF @operatorID IS NULL
  726. BEGIN
  727. SET @error = 60150 -- E_unknownUser
  728. SET @context = 'operatorKey = ' + dbo.UUIDSTR(@operatorKey)
  729. GOTO errorLabel
  730. END
  731. INSERT [UDO_operatorLog] (
  732. [operatorID],
  733. [replStatusID],
  734. [description],
  735. [lastOperatorKey],
  736. [lastUSN],
  737. [lastChange])
  738. VALUES (
  739. @operatorID,
  740. @replStatusID,
  741. @description,
  742. @lastOperatorKey,
  743. @lastUSN,
  744. @lastChange)
  745. RETURN 0
  746. errorLabel:
  747. RAISERROR (@error, 16, 1, @context)
  748. RETURN 1
  749. END -- net_operatorLog_save
  750. GO
  751. -- =============================================
  752. -- Name: net_operatorLogLast_get
  753. -- =============================================
  754. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_operatorLogLast_get' AND type = 'P')
  755. DROP PROCEDURE net_operatorLogLast_get
  756. GO
  757. CREATE PROCEDURE net_operatorLogLast_get
  758. @operatorKey uniqueidentifier,
  759. @inboundStatus bit, -- specifies whether we want last inbound or outbound status
  760. @replStatusID tinyint OUTPUT,
  761. @description nvarchar(4000) OUTPUT,
  762. @lastOperatorKey uniqueidentifier OUTPUT,
  763. @lastUSN bigint OUTPUT,
  764. @lastChange bigint OUTPUT
  765. WITH ENCRYPTION
  766. AS
  767. BEGIN
  768. DECLARE
  769. @error int,
  770. @context nvarchar(4000),
  771. @operatorID bigint,
  772. @maxSeqNo bigint
  773. SET @operatorID = dbo.operatorID(@operatorKey)
  774. IF @operatorID IS NULL
  775. BEGIN
  776. SET @error = 60150 -- E_unknownUser
  777. SET @context = 'operatorKey = ' + dbo.UUIDSTR(@operatorKey)
  778. GOTO errorLabel
  779. END
  780. IF (@inboundStatus = 0)
  781. BEGIN
  782. SELECT
  783. @maxSeqNo = MAX([seqNo])
  784. FROM
  785. [UDO_operatorLog]
  786. WHERE
  787. ([operatorID] = @operatorID) AND
  788. ([replStatusID] < 128 )
  789. END
  790. ELSE
  791. BEGIN
  792. SELECT
  793. @maxSeqNo = MAX([seqNo])
  794. FROM
  795. [UDO_operatorLog]
  796. WHERE
  797. ([operatorID] = @operatorID) AND
  798. ([replStatusID] >= 128 )
  799. END
  800. IF @maxSeqNo IS NOT NULL
  801. BEGIN
  802. SELECT
  803. @replStatusID = [replStatusID],
  804. @description = [description],
  805. @lastOperatorKey = [lastOperatorKey],
  806. @lastUSN = [lastUSN],
  807. @lastChange = [lastChange]
  808. FROM
  809. [UDO_operatorLog]
  810. WHERE
  811. ([operatorID] = @operatorID) AND
  812. ([seqNo] = @maxSeqNo)
  813. END
  814. RETURN 0
  815. errorLabel:
  816. RAISERROR (@error, 16, 1, @context)
  817. RETURN 1
  818. END -- net_operatorLogLast_get
  819. GO
  820. -- =============================================
  821. -- Name: net_operatorCert_get
  822. -- =============================================
  823. IF EXISTS (SELECT name FROM sysobjects WHERE name = N'net_operatorCert_get' AND type = 'P')
  824. DROP PROCEDURE net_operatorCert_get
  825. GO
  826. CREATE PROCEDURE net_operatorCert_get
  827. @certSerialNo nvarchar(450)
  828. WITH ENCRYPTION
  829. AS
  830. BEGIN
  831. DECLARE
  832. @error int,
  833. @context nvarchar(4000),
  834. @operatorID bigint
  835. SELECT
  836. @operatorID = [operatorID]
  837. FROM
  838. [UDO_operators]
  839. WHERE
  840. ([certSerialNo] = @certSerialNo)
  841. IF (@operatorID IS NULL)
  842. BEGIN
  843. SET @error = 50016 -- E_invalidCert
  844. SET @context = 'Certificate Serial Number not valid.'
  845. GOTO errorLabel
  846. END
  847. SELECT
  848. [operatorKey],
  849. [certificate]
  850. FROM
  851. [UDO_operators]
  852. WHERE
  853. ([operatorID] = @operatorID)
  854. RETURN 0
  855. errorLabel:
  856. RAISERROR (@error, 16, 1, @context)
  857. RETURN 1
  858. END -- net_operatorCert_get
  859. GO