The data persistence layer exists in all systems. This is often not appreciated for small or medium-scale ASP applications. This article attempts to improve this situation by providing a simple way to simplify the invocation of ADO-related objects. The idea of this approach can be extended to other programming languages, as long as the language has a little bit of object-oriented thinking, then this article will make you gain.
Are you still using ASP? I know that ASP has been abandoned by many advanced enterprise applications, but developers like me who started on ASP, or who developed some simple web apps, must be thinking about ASP at some point. It's simple and easy to use. You can also do anything with ADO to access the database. However, using ADO is a little bit more complicated. If you are still honest, repeat the following code or see someone else writing this code, then you must read this article. This article will completely overturn your previous concept of ASP and bring you into a new world.
Set rs = Server.CreateObject("ADODB.RecordSet")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open SOMEDB
rs.Open SomeSQL_OR_Some_Table, conn
While Not rs.EOF
' Do operations...
rs.MoveNext
Wend
...
Each of these needs are written in this way, do you bother?
Introduction of Poasp
What is poasp? is the abbreviation for the Persistence Object for ASP. As the name suggests, this small library wants to introduce object-oriented concepts into the ASP, while using them as simply as possible. Consider the scenario where you want to insert a record: The above code I think everyone who does ASP is familiar with it. So take a look at the poasp code: The difference between the two, I believe we can see.
Compare Items Insert Data:
ADO Implementation
Set rs = Server.CreateObject("ADODB.RecordSet")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open SOMEDB
rs.Open <TableName>, conn
rs.AddNew
rs("Field1") = Value1
rs("Field2") = Value2
...
rs.Update
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
poasp implementation
Dim poasp, po
Set poasp = New POAsp
Set po = New POAspObject
po.Init "对象名称", "对应的表名", "主键字段", "要进行操作的字段列表"
po.SetProperty "Field1", Value1
po.SetProperty "Field2", Value2
...
poasp.InsertObject(po)
Compare Items Delete data:
ADO Implementation
Set rs = Server.CreateObject("ADODB.RecordSet")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open SOMEDB
conn.Execute "delete from TableName where id=SomeID"
conn.Close
Set rs = Nothing
Set conn = Nothing
poasp implementation
Dim poasp, po
Set poasp = New POAsp
Set po = New POAspObject
po.Init "对象名称", "对应的表名", "主键字段", "要进行操作的字段列表"
poasp.DeleteObject(po, SomeID)