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.

473 lines
12 KiB

  1. VERSION 1.0 CLASS
  2. BEGIN
  3. MultiUse = -1 'True
  4. Persistable = 0 'NotPersistable
  5. DataBindingBehavior = 0 'vbNone
  6. DataSourceBehavior = 0 'vbNone
  7. MTSTransactionMode = 0 'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "SynonymSets"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = False
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  15. Attribute VB_Ext_KEY = "Top_Level" ,"No"
  16. Option Explicit
  17. Public Sub GetAllSynonymSetsRs( _
  18. ByVal o_rs As ADODB.Recordset _
  19. )
  20. Dim strQuery As String
  21. CheckDatabaseVersion
  22. CloseRecordSet o_rs
  23. strQuery = "" & _
  24. "SELECT * " & _
  25. "FROM SynonymSets " & _
  26. "ORDER BY Name;"
  27. o_rs.Open strQuery, g_cnn, adOpenStatic, adLockReadOnly
  28. End Sub
  29. Public Sub GetSynonymSetsForKeyword( _
  30. ByVal i_intKID As Long, _
  31. ByVal o_rs As ADODB.Recordset _
  32. )
  33. Dim strQuery As String
  34. CheckDatabaseVersion
  35. CloseRecordSet o_rs
  36. strQuery = "" & _
  37. "SELECT SynonymSets.* " & _
  38. "FROM " & _
  39. " Synonyms INNER JOIN SynonymSets " & _
  40. " ON Synonyms.EID = SynonymSets.EID " & _
  41. "WHERE (Synonyms.KID = " & i_intKID & ") " & _
  42. "ORDER BY SynonymSets.Name;"
  43. o_rs.Open strQuery, g_cnn, adOpenStatic, adLockReadOnly
  44. End Sub
  45. Public Sub GetSynonymsRs( _
  46. ByVal o_rs As ADODB.Recordset _
  47. )
  48. Dim strQuery As String
  49. CheckDatabaseVersion
  50. CloseRecordSet o_rs
  51. strQuery = "" & _
  52. "SELECT Synonyms.EID, SynonymSets.Name, Keywords.Keyword " & _
  53. "FROM " & _
  54. " (Keywords INNER JOIN Synonyms " & _
  55. " ON Keywords.KID = Synonyms.KID) " & _
  56. " INNER JOIN SynonymSets ON SynonymSets.EID = Synonyms.EID " & _
  57. "ORDER BY Synonyms.EID"
  58. o_rs.Open strQuery, g_cnn, adOpenStatic, adLockReadOnly
  59. End Sub
  60. ' Consider only i_arrKeywords(1..UBound).
  61. Public Sub Create( _
  62. ByVal i_strName As String, _
  63. ByRef i_vntKeywordsArray As Variant _
  64. )
  65. Dim rsLock1 As ADODB.Recordset
  66. Dim rsLock2 As ADODB.Recordset
  67. Dim rs As ADODB.Recordset
  68. Dim strQuery As String
  69. CheckDatabaseVersion
  70. LockTable LOCK_TABLE_SYNONYM_SETS, rsLock1
  71. LockTable LOCK_TABLE_SYNONYMS, rsLock1
  72. CheckAuthoringGroupAccess
  73. ' Do some validation to see if the Synonym Set is acceptable.
  74. p_ValidateSynonymSet i_strName
  75. ' Does an active Synonym Set exist with this name?
  76. Set rs = New ADODB.Recordset
  77. p_GetSynonymSet i_strName, rs
  78. If (Not rs.EOF) Then
  79. Err.Raise errAlreadyExists
  80. Exit Sub
  81. End If
  82. rs.Close
  83. ' Create a new record in the database
  84. strQuery = "" & _
  85. "SELECT * " & _
  86. "FROM SynonymSets "
  87. rs.Open strQuery, g_cnn, adOpenStatic, adLockPessimistic
  88. If (rs.RecordCount > 0) Then
  89. rs.MoveLast
  90. End If
  91. rs.AddNew
  92. rs("Name") = i_strName
  93. rs("EID") = p_GetNextEID
  94. rs.Update
  95. p_AddKeywordsToSynonymSet rs("EID").Value, GetLongArray(i_vntKeywordsArray)
  96. End Sub
  97. Public Sub Delete( _
  98. ByVal i_intEID As Long _
  99. )
  100. Dim rsLock1 As ADODB.Recordset
  101. Dim rsLock2 As ADODB.Recordset
  102. Dim rs As ADODB.Recordset
  103. Dim strQuery As String
  104. Dim strName As String
  105. CheckDatabaseVersion
  106. LockTable LOCK_TABLE_SYNONYM_SETS, rsLock1
  107. LockTable LOCK_TABLE_SYNONYMS, rsLock1
  108. Set rs = New ADODB.Recordset
  109. strQuery = "" & _
  110. "DELETE * " & _
  111. "FROM SynonymSets " & _
  112. "WHERE (EID = " & i_intEID & ")"
  113. rs.Open strQuery, g_cnn, adOpenStatic, adLockPessimistic
  114. strQuery = "" & _
  115. "DELETE * " & _
  116. "FROM Synonyms " & _
  117. "WHERE (EID = " & i_intEID & ")"
  118. rs.Open strQuery, g_cnn, adOpenStatic, adLockPessimistic
  119. End Sub
  120. ' Consider only i_arrKeywords(1..UBound).
  121. Public Sub Update( _
  122. ByVal i_intEID As Long, _
  123. ByVal i_strName As String, _
  124. ByRef i_vntKeywordsArray As Variant _
  125. )
  126. Dim rsLock1 As ADODB.Recordset
  127. Dim rsLock2 As ADODB.Recordset
  128. Dim arrKeywordsToAdd() As Long
  129. Dim arrKeywordsToRemove() As Long
  130. CheckDatabaseVersion
  131. LockTable LOCK_TABLE_SYNONYM_SETS, rsLock1
  132. LockTable LOCK_TABLE_SYNONYMS, rsLock1
  133. p_GetKeywordsToAddAndRemove i_intEID, GetLongArray(i_vntKeywordsArray), _
  134. arrKeywordsToAdd, arrKeywordsToRemove
  135. p_Rename i_intEID, i_strName, False
  136. p_AddKeywordsToSynonymSet i_intEID, arrKeywordsToAdd
  137. p_RemoveKeywordsFromSynonymSet i_intEID, arrKeywordsToRemove
  138. End Sub
  139. Public Sub Rename( _
  140. ByVal i_intEID As Long, _
  141. ByVal i_strName As String _
  142. )
  143. p_Rename i_intEID, i_strName, True
  144. End Sub
  145. Private Sub p_Rename( _
  146. ByVal i_intEID As Long, _
  147. ByVal i_strName As String, _
  148. ByVal i_blnLock As Boolean _
  149. )
  150. Dim rsLock As ADODB.Recordset
  151. Dim rs As ADODB.Recordset
  152. Dim strQuery As String
  153. CheckDatabaseVersion
  154. If (i_blnLock) Then
  155. LockTable LOCK_TABLE_SYNONYM_SETS, rsLock
  156. End If
  157. ' Do some validation to see if the Synonym Set is acceptable.
  158. p_ValidateSynonymSet i_strName
  159. ' Does an active Synonym Set exist with this name?
  160. Set rs = New ADODB.Recordset
  161. p_GetSynonymSet i_strName, rs
  162. If (Not rs.EOF) Then
  163. If ((rs.RecordCount = 1) And (rs("EID") = i_intEID)) Then
  164. ' The name needn't change
  165. Else
  166. Err.Raise errAlreadyExists
  167. End If
  168. Exit Sub
  169. End If
  170. rs.Close
  171. Set rs = New ADODB.Recordset
  172. strQuery = "" & _
  173. "SELECT * " & _
  174. "FROM SynonymSets " & _
  175. "WHERE (EID = " & i_intEID & ")"
  176. rs.Open strQuery, g_cnn, adOpenStatic, adLockPessimistic
  177. ' Does an active Synonym Set exist?
  178. If (rs.EOF) Then
  179. Exit Sub
  180. End If
  181. rs("Name") = i_strName
  182. rs.Update
  183. End Sub
  184. Private Function p_GetNextEID() As Long
  185. Dim rs As ADODB.Recordset
  186. Dim strQuery As String
  187. Set rs = New ADODB.Recordset
  188. strQuery = "" & _
  189. "SELECT Max(EID) as MaxEID " & _
  190. "FROM SynonymSets "
  191. rs.Open strQuery, g_cnn, adOpenStatic, adLockReadOnly
  192. If (rs.EOF) Then
  193. p_GetNextEID = 1
  194. Else
  195. p_GetNextEID = rs("MaxEID") + 1
  196. End If
  197. End Function
  198. Private Sub p_GetSynonymSet( _
  199. ByVal i_strName As String, _
  200. ByVal o_rs As ADODB.Recordset _
  201. )
  202. Dim strQuery As String
  203. CloseRecordSet o_rs
  204. strQuery = "" & _
  205. "SELECT * " & _
  206. "FROM SynonymSets " & _
  207. "WHERE (Name = """ & i_strName & """)"
  208. o_rs.Open strQuery, g_cnn, adOpenStatic, adLockReadOnly
  209. End Sub
  210. ' Consider only i_arrKeywords(1..UBound).
  211. ' Don't try to lock the Synonyms table. This function is only called from
  212. ' Create and Update. Those functions have already locked the table.
  213. Private Sub p_AddKeywordsToSynonymSet( _
  214. ByVal i_intEID As Long, _
  215. ByRef i_arrKeywords() As Long _
  216. )
  217. Dim rs As ADODB.Recordset
  218. Dim strQuery As String
  219. Dim intIndex As Long
  220. If (UBound(i_arrKeywords) = 0) Then
  221. Exit Sub
  222. End If
  223. Set rs = New ADODB.Recordset
  224. strQuery = "" & _
  225. "SELECT * " & _
  226. "FROM Synonyms"
  227. rs.Open strQuery, g_cnn, adOpenForwardOnly, adLockPessimistic
  228. For intIndex = 1 To UBound(i_arrKeywords)
  229. rs.AddNew
  230. rs("EID") = i_intEID
  231. rs("KID") = i_arrKeywords(intIndex)
  232. Next
  233. rs.Update
  234. End Sub
  235. ' Consider only i_arrKeywords(1..UBound).
  236. ' Don't try to lock the Synonyms table. This function is only called from
  237. ' Update. Update has already locked the table.
  238. Private Sub p_RemoveKeywordsFromSynonymSet( _
  239. ByVal i_intEID As Long, _
  240. ByRef i_arrKeywords() As Long _
  241. )
  242. Dim rs As ADODB.Recordset
  243. Dim strQuery As String
  244. Dim intIndex As Long
  245. If (UBound(i_arrKeywords) = 0) Then
  246. Exit Sub
  247. End If
  248. Set rs = New ADODB.Recordset
  249. strQuery = "" & _
  250. "SELECT * " & _
  251. "FROM Synonyms " & _
  252. "WHERE (EID = " & i_intEID & ") " & _
  253. "ORDER BY KID;"
  254. rs.Open strQuery, g_cnn, adOpenStatic, adLockPessimistic
  255. intIndex = 1
  256. Do While (Not rs.EOF)
  257. If (intIndex <= UBound(i_arrKeywords)) Then
  258. If (rs("KID") = i_arrKeywords(intIndex)) Then
  259. rs.Delete
  260. intIndex = intIndex + 1
  261. End If
  262. End If
  263. rs.MoveNext
  264. Loop
  265. End Sub
  266. ' Consider only o_arrKeywordsToAdd(1..UBound) and o_arrKeywordsToRemove(1..UBound)
  267. Private Sub p_GetKeywordsToAddAndRemove( _
  268. ByVal i_intEID As Long, _
  269. ByRef i_arrKeywords() As Long, _
  270. ByRef o_arrKeywordsToAdd() As Long, _
  271. ByRef o_arrKeywordsToRemove() As Long _
  272. )
  273. Dim clsKeywords As Keywords
  274. Dim rs As ADODB.Recordset
  275. Dim intUBound As Long
  276. Dim intKeywordsIndex As Long
  277. Dim intAddIndex As Long
  278. Dim intRemoveIndex As Long
  279. Dim intCurrentKeywordInArray As Long
  280. Dim intCurrentKeywordInRS As Long
  281. Set clsKeywords = New Keywords
  282. Set rs = New ADODB.Recordset
  283. clsKeywords.GetKeywordsInSynonymSet i_intEID, rs, True
  284. InsertionSort i_arrKeywords
  285. ' In the worst case, we may have to add all Keywords in i_arrKeywords
  286. ReDim o_arrKeywordsToAdd(UBound(i_arrKeywords) - LBound(i_arrKeywords) + 1)
  287. ' In the worst case, we may have to remove all Keywords in rs
  288. ReDim o_arrKeywordsToRemove(rs.RecordCount + 1)
  289. intKeywordsIndex = 1
  290. intAddIndex = 1
  291. intRemoveIndex = 1
  292. intUBound = UBound(i_arrKeywords)
  293. Do While (Not rs.EOF)
  294. If (intKeywordsIndex <= intUBound) Then
  295. intCurrentKeywordInArray = i_arrKeywords(intKeywordsIndex)
  296. Else
  297. intCurrentKeywordInArray = INVALID_ID_C
  298. End If
  299. intCurrentKeywordInRS = rs("KID")
  300. If (intCurrentKeywordInArray = INVALID_ID_C) Then
  301. ' The Keyword in the RS isn't in the desired Keywords list
  302. o_arrKeywordsToRemove(intRemoveIndex) = intCurrentKeywordInRS
  303. intRemoveIndex = intRemoveIndex + 1
  304. rs.MoveNext
  305. Else
  306. If (intCurrentKeywordInArray < intCurrentKeywordInRS) Then
  307. ' The Keyword in the desired Keywords list isn't in the RS
  308. o_arrKeywordsToAdd(intAddIndex) = intCurrentKeywordInArray
  309. intAddIndex = intAddIndex + 1
  310. intKeywordsIndex = intKeywordsIndex + 1
  311. ElseIf (intCurrentKeywordInArray = intCurrentKeywordInRS) Then
  312. ' The Keyword in the desired Keywords list is already in the RS
  313. rs.MoveNext
  314. intKeywordsIndex = intKeywordsIndex + 1
  315. Else
  316. ' The Keyword in the RS isn't in the desired Keywords list
  317. o_arrKeywordsToRemove(intRemoveIndex) = intCurrentKeywordInRS
  318. intRemoveIndex = intRemoveIndex + 1
  319. rs.MoveNext
  320. End If
  321. End If
  322. Loop
  323. ' The remaining keywords in the desired Keywords list aren't in the RS
  324. Do While (intKeywordsIndex <= UBound(i_arrKeywords))
  325. intCurrentKeywordInArray = i_arrKeywords(intKeywordsIndex)
  326. If (intCurrentKeywordInArray <> INVALID_ID_C) Then
  327. o_arrKeywordsToAdd(intAddIndex) = intCurrentKeywordInArray
  328. intAddIndex = intAddIndex + 1
  329. End If
  330. intKeywordsIndex = intKeywordsIndex + 1
  331. Loop
  332. ReDim Preserve o_arrKeywordsToAdd(intAddIndex - 1)
  333. ReDim Preserve o_arrKeywordsToRemove(intRemoveIndex - 1)
  334. End Sub
  335. Private Sub p_ValidateSynonymSet( _
  336. ByVal i_strName As String _
  337. )
  338. If (ContainsGarbage(i_strName)) Then
  339. Err.Raise errContainsGarbageChar
  340. End If
  341. End Sub