Say in front
have been trying to write something about visual FoxPro 7, but not the pen. There are two reasons: one is busy, lazy to write, and then visual FoxPro 7 new features do not float on the surface, a very difficult to understand, not to mention written article.
Difficult, or to write. I am not a professional Visual FoxPro programmer, I am a fan, so I do not have the concerns of professional programmers: versioning issues, compatibility issues, reliability issues; Visual FoxPro 7 is the most important and profoundly changing version since Visual FoxPro 3. is worthy of our in-depth study. From this point on, I will discuss with you some new features of visual FoxPro 7 and hope you enjoy it.
Body
DBF class Database (file) of the unsafe and its fast, flexible, powerful are from the "womb" brought, can be said to be difficult to change. Ms This launch of Visual FoxPro 7 is a great product (my opinion) and it tries to improve this shortcoming of DBF data by other means.
1. Database events (DBC event)
The first is the visual FoxPro 7 the most beautiful features-database events, event-driven is the operating mode of Windows, a Delphi master proudly said to me: the development tool under the windows of the good or bad to see it on the event package, it is clear that Delphi is the best. Visual FoxPro 7 7 introduces database events, so to speak: the management of DBC will enter a new era (of course there is a DBC object is better!) )。
For more information about database events, you can view an instance of the visual FoxPro 7 from: Home () + "sample\solution\".
2. Database events are not always valid
Visual FoxPro 6 and older versions do not support database events (database events will be ignored), and Visual FoxPro ODBC and OLE DB drivers do not support database count events; even visual FoxPro 7 itself, Database events are not always valid, and you can turn off database events in two ways:
A.dbsetprop (<dbcname>, ' Database ', ' dbcevents ',. F.)
B. Do not select Set Event on in the graphical interface (Figure 3)
So it is not enough to rely solely on database events for security management. From the very beginning, I felt that database events should be used primarily for database management rather than security management--this is a gentleman.
3._CRYPT.VCX Encryption Class
This is MS for us to encapsulate the data encryption class, support string and file encryption, is the Windows API package, the code is very complex, I am not free to see, I will only use (this is the essence of RAD).
For its use, you can see: Do FORM Home (2) + "\solution\ffc\crypto.scx"
4. Combining database events with _CRYPT.VCX encryption classes
At this year's Visual FoxPro developer conference, the Microsoft Fox team demonstrated the idea of combining "database events" with the "_crypt.vcx encryption class" data security model. Its idea is: Data security by "_CRYPT.VCX encryption class" completed, but when encryption, decryption by "database events" management.
The benefits of this approach are:
Skip "Database Events", the encrypted data will not be decrypted, you will see a heap of garbled
Database events provide a good management mechanism for managing encryption and decryption, and reduce the workload of programs. As long as database events are available, nothing can escape the event mechanism
Face is a routine I wrote:
To write a database event, you can use the following steps:
Open the Database container (Figure 1)
Right-click, pop-up menu. Select Properties. (Figure 2)
Select Set Event on (Figure 3)
Double-click a database event name
Figure 1
Figure 2
Figure 3
Here we set up two database events:
* Database Event code
* If you open the Employees table, ask for a password and decrypt the name field only if the password is "Admin"
PROCEDURE dbc_afteropentable (Ctablename)
*after a table or view is opened.
Local Cencrypt as String
Local ox as Object
IF ctablename= "Employee"
IF Alltrim ("Please enter database user password", "INPUTBOX Visual FoxPro 7 security Improvements!") "," USER ") = =" Admin "
Ox=newobject ("_cryptapi", Home () + "FFC\_CRYPT.VCX")
UPDATE Employee Set name =iif (ox.decryptsessionstreamstring (name, "1234", @cEncrypt), Cencrypt, name)
Release Ox
UPDATE flag Set flag value =0 WHERE flag id=1
ENDIF
ENDIF
Endproc
* Encrypt the Name field before closing the Employees table
PROCEDURE dbc_beforeclosetable (Ctablename)
*just before a table or view is closed.
Local Cencrypt as String
Local ox as Object
IF ctablename= "Employee"
SELECT flag value from flag WHERE flag id=1 into ARRAY myarray
IF myarray[1]=0
Ox=newobject ("_cryptapi", Home () + "FFC\_CRYPT.VCX")
UPDATE Employee Set name =iif (ox.encryptsessionstreamstring (name, "1234", @cEncrypt), Cencrypt, name)
UPDATE flag Set flag value =1 WHERE flag id=1
ENDIF
ENDIF
Endproc
*end Database Event code
5. Some considerations (regardless of the application's decompile)
A. Is this code securely stored in the database container DBC?
Of course it's not safe. Fortunately, Visual FoxPro 7 allows database event code to be written in PRG files and compiled into a program.
B._CRYPT.VCX encryption, decryption speed
I did the experiment (Win2000 server-Acharon 1.2G cpu-256mddr memory) in the same way as the previous example (Scan-endscan-replace more slowly):
The encryption width is 20 field, the record quantity is 30,000, the encryption needs 9.04 seconds, the decryption time and the encryption is similar. Therefore, the improper mass of data is frequently encrypted and decrypted.
Applicability of C._CRYPT.VCX
This kind of small table is appropriate for user password tables, and is appropriate for large amounts of data archive encryption.
4. Support Chinese encryption and decryption