1, using ImportFile () function to achieve transfer
PowerBuilder is an excellent front-end tool for the development of C/s system, which provides a lot of functions and functions, in which DataWindow data window is an important part and has powerful function, in which the ImportFile () function can complete the transfer of data.
The implementation process is to create a table on the server that is the same as the database structure on the disk, create a Data Window object (Dw_fox), take the data source to create a data window, and use the ImportFile () function of the Data window object itself to transfer data to the Data window, using the update ( function to save the data to the table that is built on the server:
Dw_fox. IMPORTFI1E (Cipan_file_name)
Dw_fox. Update ()
Where Cipan_file_name is the file on disk and its path name. This processing is simple, but lacks the flexibility, has the high request to the table structure which constructs in the server database, guarantees the strict consistency, but may make the corresponding processing to the effective data processing after the transfer to own establishment table.
2. Use ODBC connection to realize transfer
ODBC is a standard application interface (API) that was first implemented by a Microsoft Windows system that allows one application to connect to multiple data sources at the same time, using standard SQL statements as its data query statements. In the process of the first through the ODBC artboard statically set up an ODBC connected to the disk of the Foxbase database, programming to create a local transaction object connected to the local database, through processing, the effective data sent to the server in advance design of a foxbase database similar to the table, It's OK to save valid data. In the process of actual processing, the disk file name is different in various places, so that the database file name and directory are connected to change, then in the design of the ODBC interface can not be fixed to design, in the processing of the general there are two ways, the front-end for a certain treatment, That is, by copying the directory and file names required by the system, and in order for the application to be more adaptable, we are not taking this approach, but another way to take a dynamic approach to establishing an ODBC connection.
Several important parameters are required in a PowerBuilder ODBC connection, and when you use ODBC to establish a connection Foxbase database (such as Foxbase), the following records are available when you view the Pb.ini file:
[Profile Foxtran]
Dbms=odbc
.......
dbparm=connectstring= ' Dsn=foxbase '
Prompt=0
Autocommit=0
The same opens the register in HKEY_CURRENT_USER Software\odbc\odbc. INI will find the registered Foxbase primary key, which provides important information for us to establish the ODBC connection dynamically.
In the specific settings, use the functions provided by PowerBuilder to register an ODBC connection, and then create a transaction object to connect to the local (disk) database, to do the appropriate processing of the required data to the server, specific actions are as follows:
Registryset ("Hkey_current_user\software\odbc\odbc.") Ini
\foxbase "," Default Dir ", regstring!, File_path)
Set Foxbase PRIMARY Key
Transaction Foxtran
Foxtran=create Transaction//below is initialized
Foxtran.dbms= "ODBC"
foxtran.dbparm= "connectstring= ' dsn=foxbase '"
Connect using Foxtran;
Where Foxbase is the name of the registered ODBC, Foxtran is a new transaction created in transaction object management to connect to the Foxbase database, and then initializes the transaction object, File_ Path is the path name of the disk database (which can be obtained based on the file path and file name entered by the user). Creating ODBC connections dynamically can also be flexible by connecting to other local databases such as Access or Sybase SQL anywhere.