Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

8 meses atrás
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 Query(sql, params)
  14. dim cmd : set cmd = server.createobject("adodb.command")
  15. set cmd.ActiveConnection = Connection
  16. cmd.CommandText = sql
  17. dim rs
  18. If IsArray(params) then
  19. set rs = cmd.Execute(, params)
  20. ElseIf Not IsEmpty(params) then ' one parameter
  21. set rs = cmd.Execute(, Array(params))
  22. Else
  23. set rs = cmd.Execute()
  24. End If
  25. set Query = rs
  26. End Function
  27. '---------------------------------------------------------------------------------------------------------------------
  28. Public Function PagedQuery(sql, params, per_page, page_num)
  29. dim cmd : set cmd = server.createobject("adodb.command")
  30. set cmd.ActiveConnection = Connection
  31. cmd.CommandText = sql
  32. cmd.CommandType = 1 'adCmdText
  33. cmd.ActiveConnection.CursorLocation = 3 'adUseClient
  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. If Not rs.EOF then
  43. rs.PageSize = 1
  44. rs.CacheSize = 1
  45. rs.AbsolutePage = 1
  46. End If
  47. set PagedQuery = rs
  48. End Function
  49. '---------------------------------------------------------------------------------------------------------------------
  50. Public Sub [Execute](sql, params)
  51. me.query sql, params
  52. End Sub
  53. '---------------------------------------------------------------------------------------------------------------------
  54. Public Sub BeginTransaction
  55. Connection.BeginTrans
  56. End Sub
  57. Public Sub RollbackTransaction
  58. Connection.RollbackTrans
  59. End Sub
  60. Public Sub CommitTransaction
  61. Connection.CommitTrans
  62. End Sub
  63. '---------------------------------------------------------------------------------------------------------------------
  64. ' Private Methods
  65. '---------------------------------------------------------------------------------------------------------------------
  66. Private Sub Class_terminate
  67. Destroy m_connection
  68. End Sub
  69. Private Function Connection
  70. if not isobject(m_connection) then
  71. set m_connection = Server.CreateObject("adodb.connection")
  72. m_connection.open m_connection_string
  73. end if
  74. set Connection = m_connection
  75. End Function
  76. end Class
  77. %>

Powered by TurnKey Linux.