Tutorials to .com

Tutorials to .com » Database » Foxpro » VFP table to track the realization of the log method

VFP table to track the realization of the log method

Print View , by: iSee ,Total views: 9 ,Word Count: 2927 ,Date: Sat, 18 Apr 2009 Time: 10:07 PM

Table tracking problem:

In the management of the normal operation of information systems, information security issues have become increasingly prominent. Although the network has provided us with a certain degree of data security, only authorized users can carry out day-to-day maintenance of data, but sometimes the user's misoperation could cause data loss or confusion; In addition, sometimes we need to leave a record of data changes and so on. Of important data files to record changes in each of the audit log data, the establishment of its corresponding log sheet to keep track of it by, delete and modify the operation is necessary. The log table records the when, where what the user operation, recorded by the user to add or remove any record of information, as well as the original record is modified and the revised information will be manipulated to back up off the record.

vfp trigger Technology:

Visual foxpro and its preliminary version of one of the major differences is the use of the database (Database) the power to become a real DataBase. VFP the database Container contains a table (Table) and the definition of the table a variety of attributes, but also belonging to the SQL back-end technology of the trigger (Trigger).

Trigger for the database in the use of the Table provides a record-level rules (that is, testing procedures). Trigger into Insert Trigger, Update Trigger and three operating Delete Trigger. Insert Trigger for the Table Add record when triggered by the detection program, Update Trigger for the Table to amend records kept by the trigger back to the testing process, Delete Trigger for the Table in the record was deleted by the trigger of the testing process. VFP allow any operation to set different rules, which can be expressions or user-defined function (UFD), if the true value in response to that trigger successful, false if the response value, that triggered the failure. User-defined function (UFD) in stored in the Database Container.

There are two ways to create a trigger:

1) Open the Table Properties "dialog box, in the INSERT, UPDATE or DELETE trigger box, enter the trigger expressions or user-defined function (UFD);

2) the use of CREATE TRIGGER command.

Create, edit, or remove the storage process in three ways:

1) In project management, select and start a database, select "stored procedure", and then select "New", "modify" or "remove" button;

2) in the database designer from the "Database" menu, select "Edit Stored Procedures" button;

3) in the COMMAND command window, use the command MODIFY PROCEDURE.

Table tracking design:

The use of Insert Trigger, Update Trigger and Delete Trigger three operating principles, we can construct further preparedё shovel did not scratch much envy seize ㄒ    ⒔  ask a favor of particular helmet oblique   ping Li Ne   Dangshan raise tobacco  rigger in order to achieve the tracking table. In this way, regardless of the user to use the procedures of manipulation of this table or directly open the table and modify the records of additions and deletions can be manipulated to stimulate Trigger will be recorded in the log records.

I constructed four common self-defined functions, Inslog (), Dellog (), Modlog () and addlog (), deposited in the Database Container storage process. The need for tables in the data files tracking Insert Trigger, Delete Trigger and Update Trigger joined in Inslog () function, Dellog () function and Modlog () function, so that the data recorded by the document, delete and modify both the excitation Trigger for the log records. addlog () has been used to create the log table to track table structure, the structural design of the log table has been tracking table contains all the field information, and increase the user signs opid, Date Time optime operations and field operations opmak signs. Log table for the naming of the table track the table before the 'L, to show the distinction, and I store data files in a separate subdirectory under the directory LOGDBFS, dedicated to the storage to manage the log table. Programming the four functions are as follows:

*Insert Trigger:
FUNCTION inslog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog() &&
ENDI
SCATTER MEMVAR
m.opmak=&&
m.opid=SYS(0) &&
m.optime=datetime() &&
INSERT INTO (m.logname) ;
FROM MEMVAR &&
RETURN .T.
*Delete Trigger:
FUNCTION dellog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog()
ENDI
SCATTER MEMVAR
m.opmak=&&
m.opid=SYS(0)
m.optime=datetime()
INSERT INTO (m.logname) ;
FROM MEMVAR &&
RETURN .T.
*Update Trigger:
FUNCTION modlog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog()
ENDI
DIME alog[FCOUNT()+3]
alog[FCOUNT()+2]=SYS(0)
alog[FCOUNT()+3]=datetime()
alog[FCOUNT()+1]=()
FOR i=1 TO FCOUNT()
alog[I]=oldval(field[I])
ENDFOR
INSERT INTO (m.logname) ;
FROM ARRAY alog &&
alog[FCOUNT()+1]=()
FOR i=1 TO FCOUNT()
alog[I]=EVALUATE(field[I])
ENDFOR
INSERT INTO (m.logname) ;
FROM ARRAY alog &&
RETURN .T.
*Insert Trigger:
FUNCTION inslog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog() &&
ENDI
SCATTER MEMVAR
m.opmak=&&
m.opid=SYS(0) &&
m.optime=datetime() &&
INSERT INTO (m.logname) ;
FROM MEMVAR &&
RETURN .T.
*Delete Trigger:
FUNCTION dellog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog()
ENDI
SCATTER MEMVAR
m.opmak=&&
m.opid=SYS(0)
m.optime=datetime()
INSERT INTO (m.logname) ;
FROM MEMVAR &&
RETURN .T.
*Update Trigger:
FUNCTION modlog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog()
ENDI
DIME alog[FCOUNT()+3]
alog[FCOUNT()+2]=SYS(0)
alog[FCOUNT()+3]=datetime()
alog[FCOUNT()+1]=()
FOR i=1 TO FCOUNT()
alog[I]=oldval(field[I])
ENDFOR
INSERT INTO (m.logname) ;
FROM ARRAY alog &&
alog[FCOUNT()+1]=()
FOR i=1 TO FCOUNT()
alog[I]=EVALUATE(field[I])
ENDFOR
INSERT INTO (m.logname) ;
FROM ARRAY alog &&
RETURN .T.
*Insert Trigger:
FUNCTION inslog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog() &&
ENDI
SCATTER MEMVAR
m.opmak=&&
m.opid=SYS(0) &&
m.optime=datetime() &&
INSERT INTO (m.logname) ;
FROM MEMVAR &&
RETURN .T.
*Delete Trigger:
FUNCTION dellog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog()
ENDI
SCATTER MEMVAR
m.opmak=&&
m.opid=SYS(0)
m.optime=datetime()
INSERT INTO (m.logname) ;
FROM MEMVAR &&
RETURN .T.
*Update Trigger:
FUNCTION modlog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog()
ENDI
DIME alog[FCOUNT()+3]
alog[FCOUNT()+2]=SYS(0)
alog[FCOUNT()+3]=datetime()
alog[FCOUNT()+1]=()
FOR i=1 TO FCOUNT()
alog[I]=oldval(field[I])
ENDFOR
INSERT INTO (m.logname) ;
FROM ARRAY alog &&
alog[FCOUNT()+1]=()
FOR i=1 TO FCOUNT()
alog[I]=EVALUATE(field[I])
ENDFOR
INSERT INTO (m.logname) ;
FROM ARRAY alog &&
RETURN .T.
*Insert Trigger:
FUNCTION inslog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog() &&
ENDI
SCATTER MEMVAR
m.opmak=&&
m.opid=SYS(0) &&
m.optime=datetime() &&
INSERT INTO (m.logname) ;
FROM MEMVAR &&
RETURN .T.
*Delete Trigger:
FUNCTION dellog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog()
ENDI
SCATTER MEMVAR
m.opmak=&&
m.opid=SYS(0)
m.optime=datetime()
INSERT INTO (m.logname) ;
FROM MEMVAR &&
RETURN .T.
*Update Trigger:
FUNCTION modlog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog()
ENDI
DIME alog[FCOUNT()+3]
alog[FCOUNT()+2]=SYS(0)
alog[FCOUNT()+3]=datetime()
alog[FCOUNT()+1]=()
FOR i=1 TO FCOUNT()
alog[I]=oldval(field[I])
ENDFOR
INSERT INTO (m.logname) ;
FROM ARRAY alog &&
alog[FCOUNT()+1]=()
FOR i=1 TO FCOUNT()
alog[I]=EVALUATE(field[I])
ENDFOR
INSERT INTO (m.logname) ;
FROM ARRAY alog &&
RETURN .T.
*Insert Trigger:
FUNCTION inslog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog() &&
ENDI
SCATTER MEMVAR
m.opmak=&&
m.opid=SYS(0) &&
m.optime=datetime() &&
INSERT INTO (m.logname) ;
FROM MEMVAR &&
RETURN .T.
*Delete Trigger:
FUNCTION dellog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog()
ENDI
SCATTER MEMVAR
m.opmak=&&
m.opid=SYS(0)
m.optime=datetime()
INSERT INTO (m.logname) ;
FROM MEMVAR &&
RETURN .T.
*Update Trigger:
FUNCTION modlog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog()
ENDI
DIME alog[FCOUNT()+3]
alog[FCOUNT()+2]=SYS(0)
alog[FCOUNT()+3]=datetime()
alog[FCOUNT()+1]=()
FOR i=1 TO FCOUNT()
alog[I]=oldval(field[I])
ENDFOR
INSERT INTO (m.logname) ;
FROM ARRAY alog &&
alog[FCOUNT()+1]=()
FOR i=1 TO FCOUNT()
alog[I]=EVALUATE(field[I])
ENDFOR
INSERT INTO (m.logname) ;
FROM ARRAY alog &&
RETURN .T.
*Insert Trigger:
FUNCTION inslog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog() &&
ENDI
SCATTER MEMVAR
m.opmak=&&
m.opid=SYS(0) &&
m.optime=datetime() &&
INSERT INTO (m.logname) ;
FROM MEMVAR &&
RETURN .T.
*Delete Trigger:
FUNCTION dellog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog()
ENDI
SCATTER MEMVAR
m.opmak=&&
m.opid=SYS(0)
m.optime=datetime()
INSERT INTO (m.logname) ;
FROM MEMVAR &&
RETURN .T.
*Update Trigger:
FUNCTION modlog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog()
ENDI
DIME alog[FCOUNT()+3]
alog[FCOUNT()+2]=SYS(0)
alog[FCOUNT()+3]=datetime()
alog[FCOUNT()+1]=()
FOR i=1 TO FCOUNT()
alog[I]=oldval(field[I])
ENDFOR
INSERT INTO (m.logname) ;
FROM ARRAY alog &&
alog[FCOUNT()+1]=()
FOR i=1 TO FCOUNT()
alog[I]=EVALUATE(field[I])
ENDFOR
INSERT INTO (m.logname) ;
FROM ARRAY alog &&
RETURN .T.
*Insert Trigger:
FUNCTION inslog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog() &&
ENDI
SCATTER MEMVAR
m.opmak=&&
m.opid=SYS(0) &&
m.optime=datetime() &&
INSERT INTO (m.logname) ;
FROM MEMVAR &&
RETURN .T.
*Delete Trigger:
FUNCTION dellog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog()
ENDI
SCATTER MEMVAR
m.opmak=&&
m.opid=SYS(0)
m.optime=datetime()
INSERT INTO (m.logname) ;
FROM MEMVAR &&
RETURN .T.
*Update Trigger:
FUNCTION modlog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog()
ENDI
DIME alog[FCOUNT()+3]
alog[FCOUNT()+2]=SYS(0)
alog[FCOUNT()+3]=datetime()
alog[FCOUNT()+1]=()
FOR i=1 TO FCOUNT()
alog[I]=oldval(field[I])
ENDFOR
INSERT INTO (m.logname) ;
FROM ARRAY alog &&
alog[FCOUNT()+1]=()
FOR i=1 TO FCOUNT()
alog[I]=EVALUATE(field[I])
ENDFOR
INSERT INTO (m.logname) ;
FROM ARRAY alog &&
RETURN .T.
*Insert Trigger:
FUNCTION inslog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog() &&
ENDI
SCATTER MEMVAR
m.opmak=&&
m.opid=SYS(0) &&
m.optime=datetime() &&
INSERT INTO (m.logname) ;
FROM MEMVAR &&
RETURN .T.
*Delete Trigger:
FUNCTION dellog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog()
ENDI
SCATTER MEMVAR
m.opmak=&&
m.opid=SYS(0)
m.optime=datetime()
INSERT INTO (m.logname) ;
FROM MEMVAR &&
RETURN .T.
*Update Trigger:
FUNCTION modlog()
m.path=substr(dbf(),1,rat(/,dbf()))
m. logname=m.path+LOGDBFS/L+SUBSTR(DBF(),LEN(m.path)+1)
IF NOT FILE(m.logname)
=addlog()
ENDI
DIME alog[FCOUNT()+3]
alog[FCOUNT()+2]=SYS(0)
alog[FCOUNT()+3]=datetime()
alog[FCOUNT()+1]=()
FOR i=1 TO FCOUNT()
alog[I]=oldval(field[I])
ENDFOR
INSERT INTO (m.logname) ;
FROM ARRAY alog &&
alog[FCOUNT()+1]=()
FOR i=1 TO FCOUNT()
alog[I]=EVALUATE(field[I])
ENDFOR
INSERT INTO (m.logname) ;
FROM ARRAY alog &&
RETURN .T.

* The establishment of the log table structure:

FUNCTION addlog()
*
COPY STRU TO tmp EXTEND
*、
INSERT INTO tmp.dbf ;
(field_name,field_type,field_len);
VALUES (OPMAK,C,6)
INSERT INTO tmp.dbf ;
(field_name,field_type,field_len);
VALUES (OPID,C,10)
INSERT INTO tmp.dbf ;
(field_name,field_type,field_len);
VALUES (OPTIME,T,8)
USE IN tmp
oldselect=SELECT() &&
SELE 0
CREATE (m.logname) FROM tmp
DELETE FILE tmp.dbf
SELECT (oldselect)
FUNCTION addlog()
*
COPY STRU TO tmp EXTEND
*、
INSERT INTO tmp.dbf ;
(field_name,field_type,field_len);
VALUES (OPMAK,C,6)
INSERT INTO tmp.dbf ;
(field_name,field_type,field_len);
VALUES (OPID,C,10)
INSERT INTO tmp.dbf ;
(field_name,field_type,field_len);
VALUES (OPTIME,T,8)
USE IN tmp
oldselect=SELECT() &&
SELE 0
CREATE (m.logname) FROM tmp
DELETE FILE tmp.dbf
SELECT (oldselect)


FoxPro Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.