Contacts

An example of working with DBF on c. How to open DBF? Removing entries in the DBF file

DBF is a widespread data storage format that appeared in the 80s of the last century. For the first time, the format was used in the DBASE DBMS family. Due to the popularity and widespread DBASE distribution, many dbase-likes were created. software productswho received the collective name Xbase. Despite the significant age of the format, it is still widely used. This article discusses ways to work with DBF from "1C: Enterprise".

In "1C: Enterprise" to work with DBF format files (DBASE III version), a special program object is used - XBase. Working with this object usually does not cause difficulties.

Attention!

When working with DBF files, you should remember that the file name must satisfy the limit 8.3.

Attention!

The XBEE object is available both on the client side and on the server side. Client-server interaction should be thought out when solving each specific task.

Reading DBF file

Reading data from dBF file Performed for several consecutive stages:

  1. Creating an XBASE object;
  2. Opening a file;
  3. Sequential enumeration of all file rows and reading field values;
  4. Closing the file.
DBF \u003d New xbase; DBF. Openfile ("D: \\ MyFile.dbf"); // Stage 2. Opening a File While the truth is cycle // Stage 3. Switching File Rings Notify (dBF. Name); If not DBF. Next () then // Positioning on the next post Interrupt; Ended; EndCycle; DBF. Closel (); // Stage 4. File Closing

You can use a multiple algorithm for the part of the file rows:

Until the DBF is. Inkonce () cycle report (DBF. Name); DBF. Next(); EndCycle;

Unloading to DBF file

Stages of unloading to the DBF file:

  1. Creating an XBASE object;
  2. Specifying the encoding (if not specified, the ANSI encoding will be used);
  3. Field description;
  4. Creating a file;
  5. Cycle with adding and filling rows;
  6. Closing the file.

Consider this process on the example:

DBF \u003d New xbase; // Stage 1. Creating an XBase object DBF. Encoding \u003d encodingXBase. OEM; // Stage 2. Signing the encoding DBF. Fields. Add ("Code", "s", 9); // Stage 3. Description of the name and type of field DBF. Fields. Add ("Name", "s", 40); DBF. Create file ("D: \\ MyFile.dbf"); // Stage 4. Creating a File Sampling \u003d References. Nomenclature. Choose(); While sample. Next () DBF cycle. Add (); // Adding string DBF. Code \u003d sampling. The code; // Filling the field value DBF. Name \u003d sample. Name; DBF. Write down (); // Record line of the endCycle; DBF. Closel(); // Stage 6. File Closing

When specifying an encoding, uses the type of encodingXBase, which can take two values:

  • Ansi. - Windows format;
  • OEM. - DOS format.

Adding a new field when describing the structure has a syntax

Add (< Имя>, < Тип>, < Длина>, < Точность>)

The following types are available:

  • "N" - a number;
  • "S" - line;
  • "D" - date;
  • "L" - Boolewo;
  • "F" - similar to "N" - a number.

The field length is mandatory for the types of "n", "f" and "s" fields.

Working with indexes

Together with the DBF file, an index file can be used, which may contain information about one or more index. The presence of indexes makes it possible to use the search, and not just the consistent enumeration of all the file rows.

While creating index file. You should set:

  • List of indexes;
  • Path save the index file (at step 4 of unloading).

An example of creating an index file:

DBF . Indices. Add ("Indcode", "Code"); DBF. Create File("D: \\ MyFile.dbf", "D: \\ index.cdx");

The procedure for adding a new index has a syntax:

Add (< Имя>, < Выражение>, <Уникальность>, < Убывание>, < Фильтр >)

To use indexes when reading from the DBF file, follows:

  • Specify the path to the index file (at step 2 of downloads);
  • Set the current index.

An example of opening a DBF file using an index file:

DBF . Openfile ("D: \\ MyFile.dbf", "d: \\ index.cdx"); DBF. Tenderindex \u003d DBF. Indices. Indcode.;

Attention!

When you open the DBF file, positioning occurs on the first entry in the file. The first entry in the file does not match the first entry in the index. In this regard, when using indexes before consistently bypass the rows, it is necessary to be signed on the first line of the index. This can be done by the first () method (), for example:

DBF. First ();

To search, one of two functions can be used:

  • To find (< Ключ>, < Режим >) ;
  • Found Point (< Режим >) .

As a result of the work of both functions, the value with the buvene type is returned (a record with specified conditions or not). In the case of a successful search, the current pointer is set at the found line. As a search mode, one of the values \u200b\u200bcan be used:

  • «>=»;
  • «>»;
  • «<=»;
  • «<«.

Consider the search in the DBF file on the examples:

DBF \u003d New xbase; DBF. Openfile ("D: \\ MyFile.dbf", "d: \\ index.cdx"); // When you open the DBF file, the index file is additionally specified. DBF. Tenderindex \u003d DBF. Indices. Indcode; // Setting the current index // Search for method Find: If DBF. Find ("000000003", "\u003d") then to report (+ DBF. Name); Otherwise, to report ("not found"); Ended; // Find the Finding method: DBF. Key. Code \u003d "000000002"; If DBF. Find Point ("\u003d") then to report ( "Found. Name of the item:" + DBF. Name); Otherwise, to report ("not found"); Ended; DBF. Closel();

Removing entries in the DBF file

Delete recording is made by the Delete method ():

DBF . Delete();

But when using this method, the recording is not deleted from the file permanently, it is assigned a reference mark. When crossing rows marked to remove records are skipped. If you need to get around the entire file, including marked to delete recording, you must assign the value of the truth to the property. Displayed XBASE object. You can find a removal entry or not using the recording function (). To remove the removal, the restore () method is used.

DBF . Displayed \u003d truth; Until the DBF is. VKONCE () cycle if DBF. Added tolene () then DBF. Restore(); Ended; DBF. Next(); EndCycle;

To directly delete marked records, it is used to compress () method:

DBF . Squeeze();

If you need to delete all entries in the file directly, you can use the Clear File () method:

DBF . ClearFile();

Loading from DBF with ADO

ADO technology can be used to work with DBF files. ADO drivers are part of the Windows operating system and install them additionally.

Consider a sample code for reading from the DBF file according to ADO technology:

Ado \u003d New CONNECTION ("adodb.connection"); // Creating a COM object Ado. Open ( "Provider \u003d microsoft.jet.oledb.4.0; | data source \u003d" "" d: \\ ""; | extended properties \u003d dbase iii "); DB \u003d ado. Execute ("SELECT * FROM MyFile"); // Request to obtain all entries from the MyFile.dbf file While database Eof \u003d 0 cycle // Cycle by Records DBF File Report (database. Fields ("Name"). Value); // An example of an appeal to the field value Database MoveNenext (); // Go to the next post EndCycle; Ado. Close ();

The example of the connection line "Provider \u003d Microsoft.jet.oledb.4.0; Data Source \u003d" D: \\ "; Extended Properties \u003d DBASE III. In this line:

  • Provider is a driver used;
  • Data Source - the path where the DBF file is located. The path is indicated with an accuracy of the catalog. The file name is used as a table name in queries;
  • Extended Properties - In the case of accessing DBF files is a mandatory parameter. You can specify the file format

Attention!

When reading the specified method, the default encoding is OEM. In order to change the encoding on ANSI, you must assign the HKEY_LOCAL_MACHINE \\ SOFTWARE \\ WOW6432NODE \\ MICROSOPT \\ JET \\ DATACODEPAGE parameter in the Windows registry.

DBF format tables are known from the distant 1980. Since then, DBase format has evolved, developed, DBASE II, DBASE III and DBASE IV appeared, many popular programs working with databases are developed to date, in which the DBF format tables are used to this day. The DBF table format is quite old, but it continues to be used to create both large and ambitious and small projects, DBF tables are used for educational purposes, for dating and studying basic knowledge and presentation of the organization databases. DBFnavigator is a free program for viewing and editing the DBF format tables, a simple and convenient utility.

With the DBFnavigator program, you can open and view the DBF tables, edit tables - change, add and delete records. Using DBFnavigator, you can change the table structure, add, change and delete the table fields, compress the DBF tables to clean them from remote records (garbage collection), change the Windows-\u003e DOS table encoding and vice versa. In the program, you can sort the table entry, copy the records and individual fields, display the rows of the printing table, perform the search and apply to view the filter table records, change the options for opening DBF files.

Screenshots of the DBFnavigator program



DBF Viewer 2000 ® - App for viewing and editing DBF all types - Clipper, Dbase, FoxPro, Visual Foxpro, Visual Dbase.

The program performs various actions: requests, deleting duplicates or export to various formats - faster than you expect!

DBF editor dynamically creates visual forms based on the DBF file structure for editing and queries. The program also allows you to view and edit the Memo fields of the following formats: DBASE III, DBASE IV, FOXPRO, VFP and DBASE LEVEL 7.

The fullness program supports the use of a command line for the following: Import, Export, Deleting Duplicate Records or Replacing Data in DBF files. Works independently of various DBMS - all you need to view and edit a DBF file to install the application!

Why DBF Viewer 2000
unique?

Simple and intuitive interface

The application interface is quite simple and convenient, allows you to save a lot of time with everyday work.

Convenient modification of the DBF file structure in DBF Viewer 2000

You can add, delete, rename, change the order of fields and optimize the structure of DBF files.

Import data from various formats with DBF Viewer 2000

DBF Viewer 2000 Allows you to import data from the following formats: TXT, CSV, Excel (XLS, XLSX), DBF and PARADOX. Import data can be performed with preview or from a command line.

DBF Viewer 2000 offers extended export opportunities

The application allows you to export DBF files in Excel (XLS, XLSX), CSV, TXT, SQL, SDF, XML, HTML, PRG, and MS SQL, MySQL, Oracle, PostgreSQL scripts.

DBF Viewer 2000 helps remove duplicates

Removing duplicate records is easy as 1-2-3.

Works on all platforms

DBF Viewer 2000 launches on all versions of Windows from 95 to XP, Vista, 7/8/10 and Server Editions (32/64-bit)

The most common problem, due to which users cannot open this file, is an incorrectly assigned program. To fix it in Windows, you need to right-click on the file, in the context menu, bring the mouse to "Open Using" item, and select the Select Program item drop-down menu. As a result, you will see a list of installed programs on your computer, and you can choose a suitable one. We also recommend checking the box opposite the item "Use this application for all DBF files".

Another problem with which our users also occur quite often - the DBF file is damaged. Such a situation may arise in cases of cases. For example: the file was downloaded not fully as a result of server error, the file was damaged initially, etc. To eliminate this problem, use one of the recommendations:

  • Try finding the desired file in another source on the Internet. You may be lucky to find a more suitable version. Google search example: "File FileType: DBF". Just replace the word "file" to the name you need;
  • Ask you to send you the source file again, it may have been damaged during transmission;

The DBF format (Data Base File) was introduced to the use of Ashton-Tate in 1980, in the first DBMS of the DBASE database management systems family - dBASE II.

Open data format and the popularity of the original system led to the appearance of many different DBMS analogues, such as FOXPRO, DBFast, Xbase ++ and others. At the same time, the developers made various changes to the basic format associated with functionality (adding new data types, changing the header structure or table field structure, etc.).

The absence of any rigid standardization and similar changes have affected the lack of guarantees that the program being developed can correctly perform the read / write operation with any DBF file. However, basic compatibility is preserved between different DBF formats.

The DBF file consists of 2 partitions: the title and directly the data table itself. The title contains general information about the DBF file: the file structure, the number of entries used by the DBF version, the amount of memory occupied by title and table, etc. The composition of the header structure is different in various versions of the format.

The end of the file is marked with an EOF (End of File).

To speed up working with DBF files, it is possible to use index files in which the key field values \u200b\u200bare listed (or a set of key fields if the multi index file) and identifiers of the corresponding records.

In 1C, work with DBF files can be carried out in several ways:

  • XBase object;
  • Programming interface

XBASE object

The XBase object provides the ability to work with DBF format databases using the built-in 1C: Enterprise.

This object provides access to the collection of fields and DBF-table indexes, allows you to perform any actions on the data (creating new and read existing tables, add, adjusting and deleting records).

For each DBF file with which you want to create a separate XBASE object.

Programming Interface ADO.

ADO (ActiveX Data Objects) is a programming interface for data access that allows you to obtain data from various sources.

Basic ADO objects allowing to perform manipulations with a DBF file:

With the full list of objects and their properties can be found in MSDN.

Connection - an object directly providing access to a DBF file

Open (ConnectionString) Opens the data source session. The parameter is transmitted a line of connection of the "Provider \u003d Microsoft.jet.oledb.4.0; Data Source \u003d;
Extended properties \u003d dbase iv; user id \u003d; password \u003d; "
The DataSource parameter specifies the folder in which the DBF files are located.
Close () Closes connection to the data source
Provider. Contains the name of the used provider. When performing the OPEN method, the provider is automatically filled from the connection string.
ConnetionString Contains the connection string. When executing the OPEN method, the ConnectionString function parameter is automatically filled
ConNetimeout. Contains the number of expectations when connected. Default - 15
CommandTimeout. Contains the number of expectation seconds when executing the command. Default - 30
Execute (CommandText) Performs a query, calls the stored procedure or any other command available on the provider side.

Recordset - object representing a set of records (strings) of data table

ActiveConnection. Specifies the object of the Connection type. As a value, you can specify both an object of type Connection and a text string of a similar view, as well as the ConnectionString property with the Connection object
ActiveCommand. Specifies the object of type Command as a result of the execution of which this Recordset was received
Filter. Contains the data filter that needs to be applied to this Recordset.
Close Closes the RecordSet object
Requery. Performs an object update by re-requesting to the table. Similar to serial call Close () Open ()
BOF / EOF. Signs of start / end table. If bof \u003d truth, then the pointer is to be before the first record of the Recordset object. If eof \u003d truth, then the pointer is after the last record of the Recordset object
Move. Exercises the shift of the current entry forward to the specified number of records (or back, if it is negative)
MoveFirst. Exercises the shift of the pointer to the first record
MoveLast. Exercises shift pointer to the last entry
MoveNext. Exercises a pointer shift to the following entry
MovePrevious. Exercises the pointer shift to the previous entry
Fields. Contains a collection of fields. Through the design ("Point name"). Value can get the value specified in the current line.
Find. Search for a row on specified criteria.
GetString Allows you to get a string representation of the current line

Command - an object providing execution of commands or SQL queries



Did you like the article? Share it