Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » Can I create DBF files?
Re: Can I create DBF files? [message #5038 is a reply to message #5009] Thu, 31 August 2006 20:49 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14261
Registered: November 2005
Ultimate Member
Best I can do now is to post some snippets from my apps using BbfStreams. Be aware, it is combined with Oracle SQL... (usually, these are some imports/exports DBF<->Oracle).

	DbfStream dbf;
	if(!dbf.Open(String(~importcm.file), false)) {
		Exclamation("Nelze otevřít vstupní soubor !");
		return;
	}
	Progress pi;
	pi.SetText("Parcela %d");
	while(dbf.Fetch()) {
		if(pi.StepCanceled()) break;
		int q = SQL % Select(PARCELA_SEQ).From(PARCELA)
		              .Where(KU == ~importcm.ku &&
		                     SKUPINA == dbf["PARSKUP"] &&
		                     CISLO == dbf["PARCIS"] &&
		                     LOM == dbf["PARPOD"] &&
		                     PODLOM == dbf["PARDIL"]);
		if(!IsNull(q)) {
			SQL * Delete(EN_CENOMAPA).Where(PARCELA_SEQ == q && DTM_OD == ~importcm.datum);
			SQL * Insert(EN_CENOMAPA)
					(EN_CENOMAPA_SEQ, ++SeqEN)
					(PARCELA_SEQ, q)
					(DTM_OD, ~importcm.datum)
					(CENA, dbf["CENA2001"]);
		}
	}


void ExportCRO(const Array<OsobaRef>& list)
{
	AddressCache cache;
	if(!cache.Load())
	{
		PromptOK("Načítání adres bylo přeru¨eno u¸ivatelem.");
		return;
	}
	String fn = "lidi.dbf";
	ReadConfigItem(fn, config);
	if(!FileDlg(FDLG_SAVE, fn, "dbf", "DBF soubory (*.dbf)|*.dbf||"))
		return;
	
	static const struct FldDesc
	{
		const char *name;
		byte        width;
	}
	field_map[] =
	{
		{ "PRIJMENI",  0x1B },
		{ "JMENO",     0x0F },
		{ "RPRIJMENI", 0x1B },
		{ "RC",        0x0A },
		{ "TP_OBEC",   0x14 },
		{ "TP_COBCE",  0x0C },
		{ "TP_ULICE",  0x14 },
		{ "TP_CP",     0x05 },
	};

	Array<DbfStream::Field> fields;
	int i;
	for(i = 0; i < __countof(field_map); i++)
		fields << DbfStream::Field::Text(field_map[i].name, field_map[i].width);
	DbfStream output;
	if(!output.Create(fn, fields, CHARSET_MJK))
	{
		PromptOK("Nelze vytvořit soubor [* \1" + fn + "\1].");
		return;
	}
	WriteConfigItem(fn, config);

	ProgressMeter progress("Exportuji osobu %d...", 1000, list.GetCount(), 0);
	for(i = 0; i < list.GetCount(); i++)
	{
		const OsobaRef& ref = list[i];
		Adresa a = cache[ref.TRV_BYDL];
		Vector<Value> values;
		values.Add(ref.GetPrijm());
		values.Add(ref.GetJmeno());
		values.Add(ref.GetRodPrijm());
		values.Add(ref.GetRcIco());
		values.Add(a.obec);
		values.Add(a.ctvrt);
		values.Add(a.ulice);
		values.Add(a.cpop);
		output.WriteRow(values);
		if(progress.StepCancelled())
		{
			PromptOK("Export byl přeru¨en u¸ivatelem.\n"
				"Soubor [* \1" + fn + "\1] obsahuje neúplná data.");
			break;
		}
	}

	if(!output.Close())
		PromptOK("Chyba při zápisu do souboru [* \1" + fn + "\1].");
}

 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: build CppSQLite failed
Next Topic: OkCommit problem
Goto Forum:
  


Current Time: Sun Jun 22 20:16:07 CEST 2025

Total time taken to generate the page: 0.04695 seconds