From: Igor V. C. <ig...@bo...> - 2006-12-14 19:04:37
|
Hello! I'm having problems with memo fields. See the code and explanation about the problem below: I have a lot of DBF files that I need to port to Postgres, but first I need to read it. I downloaded the 2.0.0 version of XBase and I'm developing in Slackware Linux with gcc 3.4.6. I installed and runned the example programs fine. So, I started to code a program, using the example4.cpp like a example, = to port my DBF file to the database, first writting the result at STDOUT. This is the code: // test.cpp #include <xbase/xbase.h> int main() { xbShort rc; xbShort clientNumber, clientRegist, docNumber, chkSum; xbLong memoSize ; char buf[40000]; xbXBase x; xbDbf MyFile( &x ); if(( rc =3D MyFile.OpenDatabase( "MYFILE.DBF" )) !=3D XB_NO_ERROR ) { cout << "\nError opening file rc =3D " << rc << "\n"; exit(1); } docNumber =3D MyFile.GetFieldNo( "NUMMEDICO" ); clientRegist =3D MyFile.GetFieldNo( "PRONTUARIO" ); clientNumber =3D MyFile.GetFieldNo( "NUMCLIENTE" ); chkSum =3D MyFile.GetFieldNo( "CHKSUM" ); cout << "\n Position of NUMCLIENTE -> " << clientNumber << " Type: " << MyFile.GetFieldType( clientNumber ); cout << "\n Position of NUMMEDICO -> " << docNumber << " Type: " << MyFile.GetFieldType( docNumber ); cout << "\n Position of PRONTUARIO -> " << clientRegist << " Type: " << MyFile.GetFieldType( clientRegist ); // memo! cout << "\n Position of CHKSUM -> " << chkSum << " Type:" << MyFile.GetFieldType( chkSum ); rc =3D MyFile.GetFirstRecord(); while( rc =3D=3D XB_NO_ERROR ) { rc =3D MyFile.GetNextRecord(); memoSize =3D MyFile.GetMemoFieldLen( clientRegist ); cout << " Memo Size =3D " << memoSize ; xbShort erro =3D MyFile.GetMemoField( 1, 40000, buf, F_SETLK ); cout << " Error cod. " << erro; switch (erro) { case XB_INVALID_FIELDNO: cout << "\nAn invalid field number was used"; break; case XB_NOT_MEMO_FIELD: cout << "\nNot a memo field"; break; case XB_NO_MEMO_DATA: cout << "\nNo memo data exists"; break; case XB_INVALID_BLOCK_NO: cout << "\nInternal error, notify tech support"; break; case XB_SEEK_ERROR : cout << "\nDisk Error"; break; case XB_READ_ERROR: cout << "\nDisk Error"; break; case XB_NO_ERROR: cout << "\nNo Error"; break; } if (MyFile.MemoFieldsPresent()) cout << "\nTHERE IS a memo register!" << endl; else cout << "\nTHERE ISN'T memo register!" << endl; } if(( rc =3D MyFile.PackDatabase( F_SETLKW )) !=3D XB_NO_ERROR ) cout << "\nError packing database rc =3D " << rc; else cout << "\n\n\n\nDatabase packed.\n"; MyFile.ExclusiveUnlock(); /* unlock the files */ MyFile.CloseDatabase(); /* close database */ return 0; } I compile without problens! But see the result at STDOUT: Position of NUMCLIENTE -> 0 Type: N Position of NUMMEDICO -> 2 Type: N Position of PRONTUARIO -> 1 Type: M Position of CHKSUM -> 3 Type:C (...) // a lot of ... Memo Size =3D 0 Error cod. -134 No memo data exists THERE IS a memo register! (...) Can anyone explain why MyFile.MemoFieldsPresent() say that there is a me= mo field but MyFile.GetMemoField and MyFile.GetMemoFieldLen() don't ???? Best regards -- ---- ------- -------- ~ Igor Vit=F3rio Cust=F3dio (igorvc) ' v ' PLACA - ENC 03 - UFSCar / / \ \ E-Mail: ig...@bo... / ( ) \ http://www.igor.uni.cc ^ ` ~ ' ^ Linux User: #322156 |