Click here to Skip to main content
Click here to Skip to main content

The alxBase classes for work with DBF files

By , 5 Nov 2002
 

Introduction

This classes is useful for work with dbf files. The current version supports formats: FoxPro, Visual FoxPro, dBASEIII - dBASE 5.x, Clipper and HiPer-SIx. The memo fields also are supported. CDBFRecordset provides all the useful functions for navigation and modification in table. CDBFCursorset it is possible to use for work only with the selected records. CDBFTableDef it is used for creation and updating of structure of the table.

Create/Update table structure

For creation/updating of structure of the table are available functions:

    <li><code>CreateTable
  • ModifyTable
  • AddField
  • InsertField
  • ModifyField
  • MoveField
  • DeleteField
  • UpdateTable

For cancels any pending updates you may call function CanselUpdateTable().

try
{
	CDBFTableDef mNewTable;
	// begin create
	mNewTable.CreateTable(szFileName);

	// add field
	FIELD_REC FieldRec;
	memset(&FieldRec, 0, sizeof(FIELD_REC));
	memcpy(FieldRec.field_name, szFieldName, 10);
	FieldRec.field_type = FLD_TYPE_CHARACTER;
	FieldRec.len_info.char_len = 20;
	mNewTable.AddField(&FieldRec);

	// ...

	// end create
	mNewTable.UpdateTable();
}
catch(CDBFException* e)
{
	e->ReportError();
	e->Delete();
}

Navigation

For navigation are supported functions:

    <li><code>Move
  • MoveNext
  • MovePrev
  • MoveFirst
  • MoveLast
  • SetAbsolutePosition

You also may use functions: IsEOF(), IsBOF(), GetRecordCount(), GetAbsolutePosition().

try
{
	CDBFRecordset m_Set;
	m_Set.Open("test.dbf");
	while(!m_Set.IsEOF())
	{
		// ...
		m_Set.MoveNext();
	}
}
catch(CDBFException* e)
{
	e->ReportError();
	e->Delete();
}

Append/Edit record

For addition, changes of record are functions:

    <li><code>AddNew
  • Edit
  • SetFieldValue
  • Delete
  • Undelete
  • Update

You also may use functions: LockRecord(), UnlockRecord(), GetFieldvalue().

try
{
	m_Set.Edit();
	m_Set.SetFieldValue("Key",varKey);
	m_Set.SetFieldValue("NAME",varName);
	m_Set.SetFieldValue("PHONE",varPhone);
	m_Set.Update();
}
catch(CDBFException* e)
{
	e->ReportError();
	e->Delete();
}

Find Functions

For find are supported functions:

    <li><code>FindFirst
  • FindNext
  • FindLast
  • FindPrev
try
{
	BOOL bFind = m_Set.FindFirst("LIKE('*Club*', NAME)");
	while(bFind)
	{
		// ...
		bFind = m_Set.FindNext();
	}
}
catch(CDBFException* e)
{
	e->ReportError();
	e->Delete();
}

Parameter of functions: FindFirst(), FindLast(), ... string expression of dBASE language.

Filter

For the filter SetFilter function is used:

    <li><code>SetFilter
try
{
	m_Set.SetFilter("LIKE('*Club*', NAME)");
	m_Set.Requery()
	// ...
}
catch(CDBFException* e)
{
	e->ReportError();
	e->Delete();
}

This function is supported only in classes CDBFCursorset and CDBFMemCursorset.

DBFView Demo

This sample shows some opportunities of library alxBASE.

More information about the product can be found at http://www.alxsoft.narod.ru.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Alexey
Web Developer
Russian Federation Russian Federation
Member
Year of birth - 1974.
Eeducation - was ended by Kaliningrad State University in 1997.
Now I work as the engineer-programmer in Kaliningrad (RUSSIA).

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralUsing the FindFirst functionmemberAlex Evans1 Nov '04 - 11:14 
Hi
 
Trying to use the FindFirst Function, it does not find anything, I wonder if anyone is using it succesfuly and can provide me with en example
 
Say I want an exact match on a column name ACCOUNT,it is a character field, with the value "ALEX" in one of te records, how should my code look to get a succesful match?
 
Thanks
Alex
GeneralRe: Using the FindFirst functionmemberEndlessWinter10 Feb '05 - 16:23 
Alex uses standard DBF syntaxis for finding records. You can simply google it for further description. As for your case, you can use this code
 
string condition = "ACCOUNT=="+name; // e.g "ALEX"
return table.FindFirst(condition.c_str());

GeneralConverted library for Windos CEmemberAlex Evans2 Oct '04 - 21:53 
OK,
 
Some conversion to make this UNICODE compatible, a few changes and additions - eg: CE does not have a class like CFileFind and other things.
 
I get my project to comile and linke with the new library but get 2 unresolved externals
 
LNK2001: unresolved external symbol "const type_info::`vftable'" (??_7type_info@@6B@)
error LNK2001: unresolved external symbol ___CxxLongjmpUnwind@4
 
Can not find anywhere what this is al bout...
 
Any help will be appreciated
 
Thanks
Alex
GeneralUsing this with Windows CEmemberAlex Evans1 Oct '04 - 20:51 
I am developing a WIndows CE 2003 application using eVC 4 / C++ and I tried building this library for that platform, any idea if that can work? I do not manage to build the DLL
 
Thanks
Alex
GenerallockRecord()memberthangoftin29 Aug '04 - 18:18 
Hi,
 
I used your code, it's great!
 
But when i locked the record on my LAN, it's no't work. I could modified the record after it's lock by other user.
 
mRcset.LockRecord();

mRcset.Edit();

COleVariant newtemp;
 
newtemp = "123456789111";

mRcset.SetFieldValue(1,newtemp);
 
mRcset.Update();

mRcset.UnlockRecord();
 
mRcset.Close();
 
Could you fix my problem ?
GeneralUsing the FindFirst functionmemberAlex Evans1 Nov '04 - 11:17 
Hi
 
Trying to use the FindFirst Function, it does not find anything, I wonder if anyone is using it successfully and can provide me with en example
 
I am using FoxPro tables, with no memo fields, no index either…
 
Say I want an exact match on a column name ACCOUNT, it is a character field, with the value "ALEX" in one of the records, how should my code look to get a successful match?
 
Thanks
Alex

QuestionHow can i insert/update/delete image file?memberMr.Ahn7 Jul '04 - 1:21 
Hi~
 
I'm use of the alxBase.
 
It's very useful library.
 
Are there some function or routine to insert/delete a image file or binary data?
 
Please, Help me?
QuestionHow to pack deleted recordmembersimranjeet11 Jun '04 - 3:08 
Sir , I'm long time use your alx library , I'm particulay working a database project for useing your lib . But now i have problem for packed the deleted record . I used the CDBFRecordset class . please sir help me how I packed the deleted record . I also read your artical for Pack record but it's working In CDBFMemCursorset . Sir how I utilize this in CDBFRecordset class .
 
Waiting you help .
 
jassy
AnswerRe: How to pack deleted recordmemberAlexey14 Jun '04 - 19:28 
See topic How to delete record in DBF files?
QuestionHow to pack deleted recordsusssimranjit11 Jun '04 - 3:02 
Sir , I'm long time use your alx library , I'm particulay working a database project for useing your lib . But now i have problem for packed the deleted record . I used the CDBFRecordset class . please sir help me how I packed the deleted record . I also read your artical for Pack record but it's working In CDBFMemCursorset . Sir how I utilize this in CDBFRecordset class .
 
Waiting you help .
 
jassy
QuestionSample db files?memberchenhuisheng13 Apr '04 - 15:21 
I am developing a similar project at http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=53109&lngWId=1 . I wish to find some sample db files so that I can develop it a little better. thanks in advance!
GeneralGreat!! - one questionmemberbdiamond29 Mar '04 - 3:30 
I was having problems with your classes a few days ago, so I stopped using them and opted to use ODBC functions instead to do multiple inserts. The problem was my own because I compiled a debug version of the .lib file and it was conflicting with the release version of my DLL. Now that I took care of that, everything is working great! SetFieldValue() is working about 100 times faster than using ODBC was!! But while I was using ODBC my boss asked me if I could make it also export to Excel, which was also easily done, but slow. Since I'm back using your classes now I'd like to know if you know if there's a way I can derive from your dbfrecordset class with the correct offset in the header fields to do the same thing with an .xls file? Any help would be greatly appreciated. I'm giving your article a rating of 5, by the way!
 
If it's broken, I probably did it
 
bdiamond
GeneralRe: Great!! - one questionmemberAlexey29 Mar '04 - 18:33 
.xls the file has more difficult structure. The file represents OLE container in which modified structures EXCEL 4 are stored. To use dbfrecordset will fail. It is possible to use, for example: ODBC, ActiveX. Except for that in EXCEL it is possible to open dbf files of the dBASE III version.
Generalcan't write header info correctlymemberbdiamond18 Mar '04 - 7:10 
this is my fault. I don't understand how to modify the header info correctly to specify the table type correctly (along with the other fields). I create a table, and using the sample viewer demo that came with this project, I can see the data in the table, even though a couple of the column header names are messed up. But when I try to open up the table in VFP I get a message telling me to specify the code page it was created in. I tried to modify the header info, but I can't seem to get this to work right. Can you please help?
 
If it's broken, I probably did it
 
bdiamond
GeneralRe: can't write header info correctlymemberAlexey18 Mar '04 - 19:42 
The code page is define 29 byte in head of dbf file. For an example: value 0x01 - code page 437 U.S. MS-DOS, 0x03 - 1252 Windows ANSI. It is possible to determine code page through a variable m_DBFHead.code_page at creation or updating of the table (before call functions UpdateTable()). By default m_DBFHead.code_page = 0.

Generale:\temp\alxBASE\SRC\ALXParserFuncDef.cpp(1221): error C2666: &#8220;pow&#8221; : 7 overloads have the similar conversionmemberTom_lyd17 Dec '03 - 20:10 
Compilier error, how can I resolve it ?
GeneralRe: e:\temp\alxBASE\SRC\ALXParserFuncDef.cpp(1221): error C2666: ?pow? : 7 overloads have the similar conversionmemberDmitry Naumov21 Jan '04 - 21:14 
The original code, created by Alexey, was created for VC6. The problem you're describing appears when you try to compile this library under VC7 or VC7.1 (which are parts of Visual Studio 2002 and Visual Studio 2003). IF you're still interested in the solution of this problem - just reply and I can give you a hint.
GeneralRe: e:\temp\alxBASE\SRC\ALXParserFuncDef.cpp(1221): error C2666: ?pow? : 7 overloads have the similar conversionmemberm0xx22 Jun '04 - 21:57 
Hello
I have the same problem while trying to compile the code under 7.1.
I tried with explicit cast in function arguments butt... seems to fail.
 
Please give me a hint.
 
Thanks
GeneralRe: e:\temp\alxBASE\SRC\ALXParserFuncDef.cpp(1221): error C2666: ?pow? : 7 overloads have the similar conversionmembershaunwerkhoven28 Sep '04 - 0:15 
Hi,
 
I am having this same problem too. Please provide the hint you mentioned (or a full solution even).
 
Thanks a lot,
 
Shaun
GeneralRe: e:\temp\alxBASE\SRC\ALXParserFuncDef.cpp(1221): error C2666: ?pow? : 7 overloads have the similar conversionsussGanjoo11 Oct '04 - 4:00 
Try typecasting the parameter of pow to whatever is appropriate e.g line # 1221 can be changed to:
 
V_R8(pvarResult) = floor(V_R8(pvarArguments[FIRST_ARG]) * pow(10, (float)V_R8(pvarArguments[SECOND_ARG])) + 0.5);
 
hope it solves the problem.
 
Ganjoo
 
PS: Sorry for not providing the exact answer, but I had the same error in another piece of code and I was searching for an answer when I accidently landed on this discussion.
GeneralRe: e:\temp\alxBASE\SRC\ALXParserFuncDef.cpp(1221): error C2666: ?pow? : 7 overloads have the similar conversionmemberAnthony_Yio17 May '05 - 23:11 
Ok, this is OT.
As mentioned, just cast it.
 
These work for me.
 
V_R8(pvarResult) = floor(V_R8(pvarArguments[FIRST_ARG]) * pow((double)10, (double)V_R8(pvarArguments[SECOND_ARG])) + 0.5);
 
V_R8(pvarResult) = V_R8(pvarResult) / pow((double)10, (double)V_R8(pvarArguments[SECOND_ARG]));
 
Sonork 100.41263:Anthony_Yio

GeneralHelp, I'm a newbiememberarktow6 Nov '03 - 8:06 
Hi, I just need to get some data from the dbf, and used it for validation in my program.
 
I don'r really know how to start out, I download the files for using it with VC++, but I'm kinda lost.
 
Thanks
GeneralRe: Help, I'm a newbiememberAlexey9 Nov '03 - 19:53 
1. Сreate your MFC project
 
2. Connect library to the project (see sample DBFView)
a. Add in the list of directories a path to library (menu Tools - Options - page Directories)
 
b. Connect .lib file (menu Project - Settings... page Link)
for debug version Object/library modules may be alxBASEd.lib for realise alxBASEr.lib (if your project use MFC as static library then alxBASEds.lib or alxBASErs.lib)
 
c. Connect .res file of library to the project - context menu of resources in your project - Resource Includes,
add in Read-only symbol directives - #include "DBFExceptionRes.h", in Compile-time directives - #include "alxBASE.rc" right after - #include "res\YourProgectName.rc2"
 
d. To add the directive - include, for example
#include "DBFRecordset.h" in .cpp file
 
3. To write a code of processing for validation in your program
GeneralAssertion Failed!memberdade8888817 Oct '03 - 0:20 
Thanks for the previous reply!
Now i got another problem....
 
recompiling the lib i solved the vc60.pcb error but when i try to open a dbf
with the following function
 
CDBFRecordset* m_pSet;
 
m_pSet->Open("C:\\1.DBF");
 

Debug Assertion Failed!
 
in ..\\AlexBase\Src\DbfRecordset.cpp
Line:248
 
am i doing something wrong??
GeneralRe: Assertion Failed!memberAlexey17 Oct '03 - 3:02 
Pointer m_pSet non correct. Where operator new ?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 6 Nov 2002
Article Copyright 2002 by Alexey
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid