Consolidated ASP Classic MVC framework from best components
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

113 lignes
3.8KB

  1. <%
  2. Class Database_Class
  3. Private m_connection
  4. Private m_connection_string
  5. Private m_trace_enabled
  6. Public Sub set_trace(bool) : m_trace_enabled = bool : End Sub
  7. Public Property Get is_trace_enabled : is_trace_enabled = m_trace_enabled : End Property
  8. '---------------------------------------------------------------------------------------------------------------------
  9. Public Sub Initialize(connection_string)
  10. m_connection_string = connection_string
  11. End Sub
  12. '---------------------------------------------------------------------------------------------------------------------
  13. Public Function ShapeQuery(sql,params)
  14. dim shapeConn : set shapeConn = server.createobject("adodb.connection")
  15. shapeConn.ConnectionString = "Provider=MSDataShape;Data " & m_connection_string
  16. dim cmd : set cmd = server.createobject("adodb.command")
  17. shapeConn.open
  18. set cmd.ActiveConnection = shapeConn
  19. cmd.CommandText = sql
  20. dim rs
  21. If IsArray(params) then
  22. set rs = cmd.Execute(, params)
  23. ElseIf Not IsEmpty(params) then ' one parameter
  24. set rs = cmd.Execute(, Array(params))
  25. Else
  26. set rs = cmd.Execute()
  27. End If
  28. set ShapeQuery = rs
  29. End Function
  30. Public Function Query(sql, params)
  31. dim cmd : set cmd = server.createobject("adodb.command")
  32. set cmd.ActiveConnection = Connection
  33. cmd.CommandText = sql
  34. dim rs
  35. If IsArray(params) then
  36. set rs = cmd.Execute(, params)
  37. ElseIf Not IsEmpty(params) then ' one parameter
  38. set rs = cmd.Execute(, Array(params))
  39. Else
  40. set rs = cmd.Execute()
  41. End If
  42. set Query = rs
  43. End Function
  44. '---------------------------------------------------------------------------------------------------------------------
  45. Public Function PagedQuery(sql, params, per_page, page_num)
  46. dim cmd : set cmd = server.createobject("adodb.command")
  47. set cmd.ActiveConnection = Connection
  48. cmd.CommandText = sql
  49. cmd.CommandType = 1 'adCmdText
  50. cmd.ActiveConnection.CursorLocation = 3 'adUseClient
  51. dim rs
  52. If IsArray(params) then
  53. set rs = cmd.Execute(, params)
  54. ElseIf Not IsEmpty(params) then ' one parameter
  55. set rs = cmd.Execute(, Array(params))
  56. Else
  57. set rs = cmd.Execute()
  58. End If
  59. If Not rs.EOF then
  60. rs.PageSize = 1
  61. rs.CacheSize = 1
  62. rs.AbsolutePage = 1
  63. End If
  64. set PagedQuery = rs
  65. End Function
  66. '---------------------------------------------------------------------------------------------------------------------
  67. Public Sub [Execute](sql, params)
  68. me.query sql, params
  69. End Sub
  70. '---------------------------------------------------------------------------------------------------------------------
  71. Public Sub BeginTransaction
  72. Connection.BeginTrans
  73. End Sub
  74. Public Sub RollbackTransaction
  75. Connection.RollbackTrans
  76. End Sub
  77. Public Sub CommitTransaction
  78. Connection.CommitTrans
  79. End Sub
  80. '---------------------------------------------------------------------------------------------------------------------
  81. ' Private Methods
  82. '---------------------------------------------------------------------------------------------------------------------
  83. Private Sub Class_terminate
  84. Destroy m_connection
  85. End Sub
  86. Public Function Connection
  87. if not isobject(m_connection) then
  88. set m_connection = Server.CreateObject("adodb.connection")
  89. m_connection.open m_connection_string
  90. end if
  91. set Connection = m_connection
  92. End Function
  93. end Class
  94. %>

Powered by TurnKey Linux.