Source code of Windows XP (NT5)
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.

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