Buenas... estoy comenzando a interesarme en lo que es la parametrización de consultas SQL en ASP y he llegado al objeto command:
http://www.aspfaq.com/params.htm
A pesar de que me manejo bastante bien en ASP y ADO, el Command ha sido hasta el momento un territorio desconocido para mi.
Usualmente en mis desarrollos hago una clase base que se encarga de recibir las consultas SQL y asi ahorro lineas de codigo:
Código ASP:
Ver originalClass AccesoDatos
Private oCON
Private oRST
Private Sub Class_Initialize()
Set oCON = Server.CreateObject("ADODB.CONNECTION")
Set oRST = Server.CreateObject("ADODB.RECORDSET")
oCON.Provider = "Microsoft.Jet.OLEDB.4.0"
oCON.ConnectionString = "Data Source=" & Server.MapPath ("datos/database.mdb") & ";"
oCON.Open
End Sub
Public Function AgregarDatos(sSQL, sSQL2, indice)
Dim ultimo
oCON.Execute(sSQL)
Set ultimo = oCON.Execute(sSQL2)
AgregarDatos = ultimo.Fields(indice)
End Function
Public Function EditarDatos(sSQL, indice)
oCON.Execute(sSQL)
EditarDatos = indice
End Function
Public Function MostrarDatos(sSQL)
oRST.Open sSQL, oCON
If oRST.BOF And oRST.EOF then
MostrarDatos = false
Else
MostrarDatos = oRST.GetRows
End If
oRST.Close
End Function
Public Function BorrarDatos(sSQL)
oCON.Execute(sSQL)
BorrarDatos = 1
End Function
Private Sub Class_Terminate()
oCON.Close
Set oCON = nothing
Set oRST = nothing
End Sub
End Class
En resumen, me gustaria proteger la ejecución de las consultas frente a inyecciones SQL que pudiera suceder de forma fortuita.
¿Cuales son las mejores prácticas del ADODB.Command?