Click here to Skip to main content
Licence 
First Posted 20 May 2002
Views 216,921
Downloads 2,046
Bookmarked 45 times

The alxBase classes for work with DBF files

By | 5 Nov 2002 | Article
The alxBase classes for work with dbf files.
 
Part of The SQL Zone sponsored by
See Also

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. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionAssertion Failed! PinmemberGoa7:36 3 Jul '07  
Hello! I get Assertion Failed on line 146 in DBFTableDef.cpp
 
My code is:
 
CDBFTableDef t;
t.CreateTable("aaaa.dbf");
FIELD_REC FieldRec;
memset(&FieldRec, 0, sizeof(FIELD_REC));
memcpy(FieldRec.field_name, "f2", 2);
FieldRec.field_type = FLD_TYPE_NUMERIC;
t.AddField(&FieldRec);
memcpy(FieldRec.field_name, "f3", 2);
FieldRec.field_type = FLD_TYPE_CHARACTER;
t.AddField(&FieldRec);
t.UpdateTable();
t.Close();
 
CDBFRecordset m_Set;
m_Set.Open("aaaa.dbf");
m_Set.AddNew();
COleVariant var;
var.vt = VT_I4;
var.intVal = 11;
m_Set.SetFieldValue("f1", &var);
var.vt = VT_BSTR;
var.bstrVal = L"aaaaa";
m_Set.SetFieldValue("f2", &var);
m_Set.Update();
m_Set.Close();

 
Can't find mistake Frown | :(
Please help!
AnswerRe: Assertion Failed! PinmemberGoa5:18 4 Jul '07  
QuestionalxBase without mfc Pinmemberjoviens5:44 19 Dec '06  
AnswerRe: alxBase without mfc PinmemberS Mario18:08 26 Oct '09  
Generalfield content PinmemberJoao Araujo15:51 21 Jan '06  
GeneralDelete records Pinmemberpgiustinoni6:49 7 Jul '05  
GeneralGood work But... Pinmemberali TEKE3:37 11 Apr '05  
GeneralProblem in adding new records PinmemberMr.V.Stephen23:04 29 Jan '05  
GeneralRe: Problem in adding new records PinmemberEndlessWinter16:18 10 Feb '05  
GeneralIts really a very nice project Pinmembervstephen200223:37 21 Jan '05  
GeneralUsing the FindFirst function PinmemberAlex Evans11:14 1 Nov '04  
GeneralRe: Using the FindFirst function PinmemberEndlessWinter16:23 10 Feb '05  
GeneralConverted library for Windos CE PinmemberAlex Evans21:53 2 Oct '04  
GeneralUsing this with Windows CE PinmemberAlex Evans20:51 1 Oct '04  
GenerallockRecord() Pinmemberthangoftin218:18 9 Aug '04  
GeneralUsing the FindFirst function PinmemberAlex Evans11:17 1 Nov '04  
QuestionHow can i insert/update/delete image file? PinmemberMr.Ahn1:21 7 Jul '04  
QuestionHow to pack deleted record Pinmembersimranjeet3:08 11 Jun '04  
AnswerRe: How to pack deleted record PinmemberAlexey19:28 14 Jun '04  
QuestionHow to pack deleted record Pinsusssimranjit3:02 11 Jun '04  
QuestionSample db files? Pinmemberchenhuisheng15:21 13 Apr '04  
GeneralGreat!! - one question Pinmemberbdiamond3:30 29 Mar '04  
GeneralRe: Great!! - one question PinmemberAlexey18:33 29 Mar '04  
Generalcan't write header info correctly Pinmemberbdiamond7:10 18 Mar '04  
GeneralRe: can't write header info correctly PinmemberAlexey19:42 18 Mar '04  

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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