Problem with Access-mdb/DAO

Fabian Cenedese Cenedese at indel.ch
Wed Dec 3 10:25:57 CST 2003


Hi

I have posted this problem already long time ago but I never found the
time to test it again.

http://www.winehq.org/hypermail/wine-devel/2002/11/1530.html

But now I tried with the actual wine from cvs (2003-12-03) and it's still
there. The problem is that if I try to create a table in a Access database
the last char of the name gets lost. I now have a small program which
shows this error, maybe someone can use it for finding this bug.
It's a simple VC6 Wizard generated Win32 command line app which
uses MFC for DAO.

The first time I tried was with SUSE 8.0, now I have Knoppix 3.3 (Debian).

Thanks

bye  Fabi



---------------------------- mdbtest.cpp
// mdbtest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <afxdao.h>			// MFC DAO database classes


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


LPCTSTR lpszTableNodeTable				= "Nodes";
LPCTSTR lpszTableNodeName				= "NodeName";
LPCTSTR lpszTableNodeNodeType			= "NodeType";
LPCTSTR lpszTableNodeBuildCL			= "BuildCL";
LPCTSTR lpszTableNodeEditCL				= "EditCL";
LPCTSTR lpszTableNodePath				= "Path";
LPCTSTR lpszTableNodeFlags				= "Flags";
LPCTSTR lpszTableNodeParam1				= "Param1";
LPCTSTR lpszTableNodeParam2				= "Param2";
LPCTSTR lpszTableNodeParam3				= "Param3";
LPCTSTR lpszTableNodeParam4				= "Param4";


/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

//-----------------------------------------------------------------------------

void CreateNodeTable(CDaoDatabase* pDB)	 // throws CDaoException and CMemoryException
{
	CDaoTableDef nodeDef(pDB);

	// attempt to create a new table def
	nodeDef.Create(lpszTableNodeTable);

	CDaoFieldInfo  DaoFieldInfo;

	// init members
	DaoFieldInfo.m_strName = lpszTableNodeName;
	DaoFieldInfo.m_nType = dbText;
	DaoFieldInfo.m_lSize = 255;
	DaoFieldInfo.m_lAttributes = dbVariableField;
	DaoFieldInfo.m_nOrdinalPosition = 0;
	DaoFieldInfo.m_bRequired = FALSE;
	DaoFieldInfo.m_bAllowZeroLength = TRUE;
	DaoFieldInfo.m_lCollatingOrder = 0;

	// create name field
	nodeDef.CreateField(DaoFieldInfo);

	// create type field
	DaoFieldInfo.m_strName = lpszTableNodeNodeType;
	DaoFieldInfo.m_lSize = 30;
	nodeDef.CreateField(DaoFieldInfo);

	// create path field
	DaoFieldInfo.m_strName = lpszTableNodePath;
	DaoFieldInfo.m_lSize = 255;
	nodeDef.CreateField(DaoFieldInfo);

	// create flags field
	nodeDef.CreateField(lpszTableNodeFlags, dbLong, 4, dbFixedField);

	// create build command line field
	DaoFieldInfo.m_strName = lpszTableNodeBuildCL;
	DaoFieldInfo.m_nType = dbMemo;
	nodeDef.CreateField(DaoFieldInfo);

	// create edit command line field
	DaoFieldInfo.m_strName = lpszTableNodeEditCL;
	DaoFieldInfo.m_nType = dbMemo;
	nodeDef.CreateField(DaoFieldInfo);

	DaoFieldInfo.m_nType = dbMemo;
	//DaoFieldInfo.m_lSize = 200;
	DaoFieldInfo.m_strName = lpszTableNodeParam1;
	nodeDef.CreateField(DaoFieldInfo);			// create Param cl field
	DaoFieldInfo.m_strName = lpszTableNodeParam2;
	nodeDef.CreateField(DaoFieldInfo);			// create Param cl field
	DaoFieldInfo.m_strName = lpszTableNodeParam3;
	nodeDef.CreateField(DaoFieldInfo);			// create Param cl field
	DaoFieldInfo.m_strName = lpszTableNodeParam4;
	nodeDef.CreateField(DaoFieldInfo);			// create Param cl field

	nodeDef.Append();       // append table def to database

	nodeDef.Close();

	// end CreateNodeTable
}


int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		cerr << _T("Fatal Error: MFC initialization failed") << endl;
		nRetCode = 1;
	}
	else
	{
		// TODO: code your application's behavior here.
		CString m_Path="test.mdb";

		CDaoDatabase db;
		CDaoRecordset rsNode(&db);					 // rs node

		try {
			// create database if not available
			cout << "Creating Database\n";
			try {
				db.Create(m_Path);
				db.Close();
			}
			catch (CDaoException* de) {
				// already exists I guess
				cout << "Database already existed\n";
				de->Delete();
			}

			cout << "Opening Database\n";
			// try to open database
			db.Open(m_Path, TRUE, FALSE, _T(""));

			// --- delete old node and dependency tables and save new ones ---
			cout << "Deleting Tabledef\n";
			try {
				// delete node table
				db.DeleteTableDef(lpszTableNodeTable);
			} catch (CDaoException* dde) {
				// catch error, maybe table def hasn't existed
				dde->Delete();
			}

			cout << "Creating new Tabledef\n";
			// create node table
			CreateNodeTable(&db);

			cout << "Opening Table\n";
			// try to open node table
			rsNode.Open(dbOpenDynaset, CString(_T("Select * From [")) + lpszTableNodeTable + _T("]"), 0);

			// look if recordset is updateable
			if (!rsNode.CanUpdate()) {
				cout << "No Update\n";
			}

			cout << "Closing Table\n";
			// close tables
			rsNode.Close();

			cout << "Closing Database\n";
			// close database
			db.Close();

			cout << "Deleting Database\n";
			DeleteFile(m_Path);
		}
		catch (CDaoException* de) {						 // catch database exception
			char msg[256];
			de->GetErrorMessage(msg, 256);
			cout << "Error:" << msg;
			de->Delete();
			goto failure_exit;
		}
		catch (CMemoryException* me) {					 // catch memory exception
			char msg[256];
			me->GetErrorMessage(msg, 256);
			cout << "Error:" << msg;
			me->Delete();
			goto failure_exit;
		}

		cout << "OK\n";
		return TRUE;

failure_exit:
		// do some cleanup after failure
		if (rsNode.IsOpen())
			rsNode.Close();
		if (db.IsOpen())
			db.Close();

	}

	cout << "ERROR!!\n";

	return nRetCode;
}





More information about the wine-devel mailing list