It's about Firebird and ASP pages, the most interesting thing is that it shows how to use transactions within ASP pages, which is not so common.
Connect to Firebird and retrieve data in ASP:
... on error resume next dim adoConn dim adoRS dim counter set adoConn = Server.CreateObject("ADODB.Connection") set adoRS = Server.CreateObject("ADODB.Recordset") adoConn.ConnectionString = "DRIVER={Firebird/Interbase(r) Driver};DBNAME=localhost:C:\Programmi\Firebird\Firebird_1_5\examples\EMPLOYEE.FDB;UID=SYSDBA;PWD=masterkey" adoConn.Open adoRS.ActiveConnection = adoConn if adoConn.errors.count = 0 then response.write "Fields In The 'Contacts' Table:" adoRS.Open "select e.first_name, e.last_name, d.department, p.proj_name from employee e right outer join department d on e.dept_no = d.dept_no left outer join employee_project ep on e.emp_no = ep.emp_no left outer join project p on ep.proj_id = p.proj_id", adoConn nfields = adoRS.fields.count while not adoRS.EOF for i = 0 to nfields -1 response.write adoRS.fields(i).name & ": " & adoRS.fields(i).value & " " next response.write "
" adoRS.MoveNext wend else response.write "ERROR: Couldn't connect to database" end if adoRS.Close if adoConn.errors.count = 0 then response.write "Second example:
" adoRS.Open "select count(e.emp_no) as emp_4_proj, d.department, p.proj_name from employee e right outer join department d on e.dept_no = d.dept_no left outer join employee_project ep on e.emp_no = ep.emp_no left outer join project p on ep.proj_id = p.proj_id group by d.department, p.proj_name", adoConn nfields = adoRS.fields.count while not adoRS.EOF for i = 0 to nfields -1 response.write adoRS.fields(i).name & ": " & adoRS.fields(i).value & " " next response.write "
" adoRS.MoveNext wend else response.write "ERROR: Couldn't connect to database" end if adoConn.Close Set adoRS = nothing Set adoConn = nothing ...
Using transactions within ASP pages:
if adoConn.errors.count = 0 then 'here we begin a transaction adoConn.begintrans 'now we add a row to the “country” table adoConn.execute "insert into country values ('Portugal', 'Escudo')" 'we commit the transaction, thus saving changes adoConn.CommitTrans 'now we start another transaction adoConn.begintrans 'here we delete the newly added row adoconn.execute "delete from country where country = 'Portugal'" 'this time we rollback the transaction, not saving the changes adoconn.rollbacktrans 'this query will show that the commit and rollback sequence has been executed and the row with ‘Portugal’ and ‘Escudo’ is present adoRS.Open "select * from country", adoConn
Note that your decision on transaction usage and the commit/rollback sequence must be business driven, no guesswork at all!!
The original paper is available here (PDF)
No comments:
Post a Comment