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.

390 lines
8.9 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 = "Keywords"
  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 GetAllKeywordsRs( _
  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 Keywords " & _
  26. "ORDER BY Keyword;"
  27. o_rs.Open strQuery, g_cnn, adOpenStatic, adLockReadOnly
  28. End Sub
  29. Public Sub GetAllKeywordsColl( _
  30. ByVal o_colKeywords As Collection _
  31. )
  32. Dim rs As ADODB.Recordset
  33. Dim strQuery As String
  34. Dim intKID As Long
  35. CheckDatabaseVersion
  36. Set rs = New ADODB.Recordset
  37. strQuery = "" & _
  38. "SELECT * " & _
  39. "FROM Keywords"
  40. rs.Open strQuery, g_cnn, adOpenForwardOnly, adLockReadOnly
  41. Do While (Not rs.EOF)
  42. intKID = rs("KID")
  43. o_colKeywords.Add rs("Keyword").Value, CStr(intKID)
  44. LWhileEnd:
  45. DoEvents
  46. rs.MoveNext
  47. Loop
  48. End Sub
  49. Public Sub GetAllKeywordsDict( _
  50. ByVal o_dictKeywords As Scripting.Dictionary _
  51. )
  52. Dim rs As ADODB.Recordset
  53. Dim strQuery As String
  54. Dim intKID As Long
  55. CheckDatabaseVersion
  56. Set rs = New ADODB.Recordset
  57. strQuery = "" & _
  58. "SELECT * " & _
  59. "FROM Keywords"
  60. rs.Open strQuery, g_cnn, adOpenForwardOnly, adLockReadOnly
  61. Do While (Not rs.EOF)
  62. intKID = rs("KID")
  63. o_dictKeywords.Add rs("Keyword").Value, CStr(intKID)
  64. LWhileEnd:
  65. DoEvents
  66. rs.MoveNext
  67. Loop
  68. End Sub
  69. Public Sub GetKeyword( _
  70. ByVal i_intKID As Long, _
  71. ByRef o_strKeyword As String _
  72. )
  73. Dim rs As ADODB.Recordset
  74. Dim strQuery As String
  75. o_strKeyword = ""
  76. CheckDatabaseVersion
  77. Set rs = New ADODB.Recordset
  78. strQuery = "" & _
  79. "SELECT * " & _
  80. "FROM Keywords " & _
  81. "WHERE (KID = " & i_intKID & ")"
  82. rs.Open strQuery, g_cnn, adOpenStatic, adLockReadOnly
  83. If (Not rs.EOF) Then
  84. o_strKeyword = rs("Keyword")
  85. End If
  86. End Sub
  87. Public Function GetKIDOfKeyword( _
  88. ByVal i_strKeyword As String _
  89. ) As Long
  90. Dim rs As ADODB.Recordset
  91. CheckDatabaseVersion
  92. ' Does an active Keyword exist with this name?
  93. Set rs = New ADODB.Recordset
  94. ' Do some validation to see if the Keyword is acceptable.
  95. ' For example, if there are embedded quotes, then p_GetKeyword will
  96. ' cause an error.
  97. p_ValidateKeyword i_strKeyword
  98. p_GetKeyword i_strKeyword, rs
  99. If (Not rs.EOF) Then
  100. GetKIDOfKeyword = rs("KID")
  101. Else
  102. GetKIDOfKeyword = INVALID_ID_C
  103. End If
  104. End Function
  105. Public Sub GetKeywordsInSynonymSet( _
  106. ByVal i_intEID As Long, _
  107. ByVal o_rs As ADODB.Recordset, _
  108. Optional ByVal i_blnOrderById As Boolean = False _
  109. )
  110. Dim strQuery As String
  111. Dim strOrder As String
  112. CheckDatabaseVersion
  113. If (i_blnOrderById) Then
  114. strOrder = "ORDER BY Keywords.KID;"
  115. Else
  116. strOrder = "ORDER BY Keywords.Keyword;"
  117. End If
  118. CloseRecordSet o_rs
  119. strQuery = "" & _
  120. "SELECT Keywords.* " & _
  121. "FROM " & _
  122. " Synonyms INNER JOIN Keywords " & _
  123. " ON Synonyms.KID = Keywords.KID " & _
  124. "WHERE (Synonyms.EID = " & i_intEID & ") " & _
  125. strOrder
  126. o_rs.Open strQuery, g_cnn, adOpenStatic, adLockReadOnly
  127. End Sub
  128. Public Function Create( _
  129. ByVal i_strKeyword As String, _
  130. Optional ByVal i_blnMinValidation As Boolean = False _
  131. ) As Long
  132. Dim rsLock As ADODB.Recordset
  133. Dim rs As ADODB.Recordset
  134. Dim strQuery As String
  135. CheckDatabaseVersion
  136. LockTable LOCK_TABLE_KEYWORDS, rsLock
  137. ' Do some validation to see if the Keyword is acceptable.
  138. p_ValidateKeyword i_strKeyword, i_blnMinValidation
  139. ' Does an active Keyword exist with this name?
  140. Set rs = New ADODB.Recordset
  141. p_GetKeyword i_strKeyword, rs
  142. If (Not rs.EOF) Then
  143. Create = rs("KID")
  144. Exit Function
  145. End If
  146. rs.Close
  147. ' Create a new record in the database
  148. strQuery = "" & _
  149. "SELECT * " & _
  150. "FROM Keywords "
  151. rs.Open strQuery, g_cnn, adOpenStatic, adLockPessimistic
  152. If (rs.RecordCount > 0) Then
  153. rs.MoveLast
  154. End If
  155. rs.AddNew
  156. rs("Keyword") = i_strKeyword
  157. rs.Update
  158. Create = rs("KID")
  159. End Function
  160. Public Sub Delete( _
  161. ByVal i_intKID As Long _
  162. )
  163. Dim rsLock1 As ADODB.Recordset
  164. Dim rsLock2 As ADODB.Recordset
  165. Dim rs As ADODB.Recordset
  166. Dim strQuery As String
  167. Dim strKeyword As String
  168. CheckDatabaseVersion
  169. LockTable LOCK_TABLE_KEYWORDS, rsLock1
  170. LockTable LOCK_TABLE_SYNONYMS, rsLock2
  171. Set rs = New ADODB.Recordset
  172. strQuery = "" & _
  173. "DELETE * " & _
  174. "FROM Keywords " & _
  175. "WHERE (KID = " & i_intKID & ")"
  176. rs.Open strQuery, g_cnn, adOpenStatic, adLockPessimistic
  177. strQuery = "" & _
  178. "DELETE * " & _
  179. "FROM Synonyms " & _
  180. "WHERE (KID = " & i_intKID & ")"
  181. rs.Open strQuery, g_cnn, adOpenStatic, adLockPessimistic
  182. End Sub
  183. Public Sub Rename( _
  184. ByVal i_intKID As Long, _
  185. ByVal i_strKeyword As String _
  186. )
  187. Dim rsLock As ADODB.Recordset
  188. Dim rs As ADODB.Recordset
  189. Dim rs2 As ADODB.Recordset
  190. Dim strQuery As String
  191. CheckDatabaseVersion
  192. LockTable LOCK_TABLE_KEYWORDS, rsLock
  193. ' Do some validation to see if the Keyword is acceptable.
  194. p_ValidateKeyword i_strKeyword
  195. Set rs = New ADODB.Recordset
  196. strQuery = "" & _
  197. "SELECT * " & _
  198. "FROM Keywords " & _
  199. "WHERE (KID = " & i_intKID & " )"
  200. rs.Open strQuery, g_cnn, adOpenStatic, adLockPessimistic
  201. ' Does an active Keyword exist?
  202. If (rs.EOF) Then
  203. Exit Sub
  204. End If
  205. ' Does the name really need to change?
  206. If (rs("Keyword") = i_strKeyword) Then
  207. Exit Sub
  208. End If
  209. Set rs2 = New ADODB.Recordset
  210. p_GetKeyword i_strKeyword, rs2
  211. If (Not rs2.EOF) Then
  212. Err.Raise errAlreadyExists
  213. End If
  214. rs("Keyword") = i_strKeyword
  215. rs.Update
  216. End Sub
  217. Private Sub p_GetKeyword( _
  218. ByVal i_strKeyword As String, _
  219. ByVal o_rs As ADODB.Recordset _
  220. )
  221. Dim strQuery As String
  222. CloseRecordSet o_rs
  223. strQuery = "" & _
  224. "SELECT * " & _
  225. "FROM Keywords " & _
  226. "WHERE (Keyword = """ & i_strKeyword & """ )"
  227. o_rs.Open strQuery, g_cnn, adOpenForwardOnly, adLockReadOnly
  228. End Sub
  229. Private Function p_ContainsStopSign( _
  230. ByVal i_strKeyword As String _
  231. ) As Boolean
  232. Dim clsStopSigns As StopSigns
  233. Set clsStopSigns = New StopSigns
  234. p_ContainsStopSign = clsStopSigns.ContainsStopSign(i_strKeyword)
  235. End Function
  236. Private Function p_ContainsStopWord( _
  237. ByVal i_strKeyword As String _
  238. ) As Boolean
  239. Dim clsStopWords As StopWords
  240. Set clsStopWords = New StopWords
  241. p_ContainsStopWord = clsStopWords.ContainsStopWord(i_strKeyword)
  242. End Function
  243. Private Sub p_ValidateKeyword( _
  244. ByVal i_strKeyword As String, _
  245. Optional ByVal i_blnMinValidation As Boolean = False _
  246. )
  247. Dim blnMinimumValidatation As Boolean
  248. If (ContainsGarbage(i_strKeyword)) Then
  249. Err.Raise errContainsGarbageChar
  250. ElseIf (InStr(i_strKeyword, """") <> 0) Then
  251. Err.Raise errContainsQuote
  252. ElseIf (Len(i_strKeyword) > MAX_KEYWORD_LENGTH_C) Then
  253. Err.Raise errTooLong
  254. End If
  255. blnMinimumValidatation = False
  256. If (Not (IsNull(g_clsParameters.Value(MINIMUM_KEYWORD_VALIDATION_C)))) Then
  257. blnMinimumValidatation = g_clsParameters.Value(MINIMUM_KEYWORD_VALIDATION_C)
  258. End If
  259. If (blnMinimumValidatation Or i_blnMinValidation) Then
  260. Exit Sub
  261. End If
  262. If (p_ContainsStopSign(i_strKeyword)) Then
  263. Err.Raise errContainsStopSign
  264. ElseIf (p_ContainsStopWord(i_strKeyword)) Then
  265. Err.Raise errContainsStopWord
  266. ElseIf (ContainsIndependentOperatorShortcut(i_strKeyword)) Then
  267. Err.Raise errContainsOperatorShortcut
  268. ElseIf (ContainsVerbalOperator(i_strKeyword)) Then
  269. Err.Raise errContainsVerbalOperator
  270. End If
  271. End Sub