ODBC 问题请教

betty_betty2008 2009-12-10
环境:WinXP+dmd1.053+phobos+dwt3.x+dbi0.25+juno0.51.

请问下面的问题有可能出在哪里?谢谢。俺用
implib/system odbc32.lib odbc32.dll


生成新的odbc32.lib替换了DMD自带的,还是不行.另外俺在用dbi测试ODBC的时候也差不多如此。


F:\DLang\DEx\D1Ex\database>dmd msaccess_odbc.d odbc32.lib
OPTLINK (R) for Win32  Release 8.00.2
Copyright (C) Digital Mars 1989-2009  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
msaccess_odbc.obj(msaccess_odbc)
 Error 42: Symbol Undefined _SQLFreeStmt@8
msaccess_odbc.obj(msaccess_odbc)
 Error 42: Symbol Undefined _SQLDisconnect@4
msaccess_odbc.obj(msaccess_odbc)
 Error 42: Symbol Undefined _SQLAllocHandle@12
msaccess_odbc.obj(msaccess_odbc)
 Error 42: Symbol Undefined _SQLFreeHandle@8
msaccess_odbc.obj(msaccess_odbc)
 Error 42: Symbol Undefined _SQLDriverConnect@32
msaccess_odbc.obj(msaccess_odbc)
 Error 42: Symbol Undefined _SQLExecDirect@12
msaccess_odbc.obj(msaccess_odbc)
 Error 42: Symbol Undefined _SQLFetch@4
msaccess_odbc.obj(msaccess_odbc)
 Error 42: Symbol Undefined _SQLGetData@24
--- errorlevel 8



D源码如下:
module msaccess_odbc;
// -------------------------------------------------------------
// Program:      msaccess_odbc
// Purpose:      C program to demo ODBC on a Microsoft Access database table
// by:           David Brown
// date:         August 17, 2002
// Compiler:     LCC-WIN32
// Environment:  Windows 2000 SP2 on Pentium III
// Style:        Win32 console application
// DBMS:         Database db1.mdb with table Artists and fields artistID (long int) and artistName (char[50])
// ODBC:         Assumes Microsoft Access drivers installed
// Acknowledgments:
//				 With minor amendments for Microsoft Access this is based upon the original program by Rock Cogar
//				 that I downloaded from John Findlay's web site at http://www.john.findlay1.btinternet.co.uk/
// -------------------------------------------------------------


import std.stdio;
import std.c.stdio;
import std.c.stdlib;
import std.c.string;
import win32.windows;
import win32.sql;
import win32.sqlext;
import win32.sqltypes;

static const int SZLEN=50;

int main(char[][] args)
{
	process();
	readln;
	return 0;
}

void process()
{
	long   liid = 0;
	char       szartist[SZLEN+1];
	HSTMT      hstmt = cast(void*)SQL_NULL_HSTMT;
	SQLRETURN  retcode;
	HENV       henv = cast(void*)SQL_NULL_HANDLE;
	HDBC       hdbc = cast(void*)SQL_NULL_HANDLE;
	char       szSql[256];
	char       szout[256];
	char	   szdatabase[] = "DSN=MS Access Database;DBQ=db1.mdb;FIL=MS Access;";

	retcode = SQLAllocHandle(SQL_HANDLE_ENV,cast(SQLHANDLE)SQL_NULL_HANDLE,cast(SQLHANDLE*)&henv);              /* Environment handle*/

	if (retcode != SQL_SUCCESS)
	{
		dbError( "SQLAllocEnv()",henv,hdbc,hstmt);
		return;
	}

	retcode = SQLAllocHandle(SQL_HANDLE_DBC,cast(SQLHANDLE)henv, cast(SQLHANDLE*)&hdbc); /* Connection handle */

	if (retcode != SQL_SUCCESS)
	{
		dbError( "SQLAllocConnect()",henv,hdbc,hstmt);
		SQLFreeHandle(SQL_HANDLE_ENV,cast(SQLHANDLE)henv);
		return;
	}

	retcode = SQLDriverConnect(cast(SQLHANDLE)hdbc, null, cast(SQLCHAR *)szdatabase, 
			cast(short) (strlen(szdatabase.ptr)+1), 
			null, 0, null, SQL_DRIVER_NOPROMPT); /* Connect to data source */

/* If there was a DSN already set-up instead of SQLDriverConnect you could use

	retcode = SQLConnect(hdbc, "my_dsn", SQL_NTS, NULL, 0, NULL, 0);
*/
	if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
	{
		dbError( "SQLDriverConnect()",henv,hdbc,hstmt);
		SQLFreeHandle(SQL_HANDLE_ENV,cast(SQLHANDLE)henv);
		return;
	}

	retcode = SQLAllocHandle(SQL_HANDLE_STMT,cast(SQLHANDLE)hdbc, cast(SQLHANDLE*)&hstmt); /* Statement handle */

	if (retcode != SQL_SUCCESS)
	{
		dbError( "SQLAllocStmt()",henv,hdbc,hstmt);
		SQLFreeHandle(SQL_HANDLE_ENV,cast(SQLHANDLE)henv);
		return;
	}

	lstrcpy( szSql.ptr,"SELECT artistID, artistName FROM Artists ORDER BY artistName"); /* Select statement */

	retcode = SQLExecDirect(cast(SQLHANDLE)hstmt, cast(ubyte*)szSql.ptr, SQL_NTS);

	if (retcode != SQL_SUCCESS)
	{
		dbError( " SQLExecDirect()",henv,hdbc,hstmt);
	}

	if (retcode == SQL_SUCCESS)
	{

	while (TRUE)
		{
		retcode = SQLFetch(cast(SQLHANDLE)hstmt);

		if (retcode == SQL_ERROR || retcode == SQL_SUCCESS_WITH_INFO)
		{
			dbError( "SQLFetch()",henv,hdbc,hstmt);
		}

		if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
		{
			retcode = SQLGetData(cast(SQLHANDLE)hstmt, 1, SQL_C_DEFAULT, &liid, 0, NULL);
			if (retcode != SQL_SUCCESS)
				{
					dbError( "SQLGetData(1)",henv,hdbc,hstmt);
					SQLFreeHandle(SQL_HANDLE_ENV,cast(SQLHANDLE)henv);
					return;
				}

			memset(cast(void*)szartist.ptr, 0, SZLEN+1);
			retcode = SQLGetData(cast(SQLHANDLE)hstmt, 2, SQL_CHAR, szartist.ptr, SZLEN, null);
			if (retcode != SQL_SUCCESS)
				{
					dbError( "SQLGetData(2)",henv,hdbc,hstmt);
					SQLFreeHandle(SQL_HANDLE_ENV,cast(SQLHANDLE)henv);
					return;
				}

			fprintf(stdout, "ID: %d\tArtist: %s\n", liid, szartist.ptr);
		}
		else
		{
			break;
		}
		}
	}

	SQLFreeStmt(cast(SQLHANDLE)hstmt, SQL_DROP);
	SQLDisconnect(cast(SQLHANDLE)hdbc);
	SQLFreeHandle(SQL_HANDLE_DBC,cast(SQLHANDLE)hdbc);
	SQLFreeHandle(SQL_HANDLE_ENV,cast(SQLHANDLE)henv);
}
// -------------------------------------------------------------

// -------------------------------------------------------------
void dbError( LPSTR lp, HENV henv,HDBC hdbc,HSTMT hstmt)
{
	ubyte buf[250];
	ubyte sqlstate[15];
	
	/*Not done yet...
	SQLError( henv, hdbc, hstmt, sqlstate, null,buf.ptr, buf.sizeof,null);
	SQLError(henv, hdbc, hstmt, szSqlState, pfNativeError, szErrorMsg, cbErrorMsgMax, pcbErrorMsg) 

	SQLGetDiagRec(HandleType, Handle, RecNumber, szSqlstate, pfNativeErrorPtr, szErrorMsg, cbErrorMsgMax, pcbErrorMsg)
	*/
	fprintf(stderr, "%s. %s, SQLSTATE=%s\n",lp, buf.ptr, sqlstate);
}
// -------------------------------------------------------------
ideage 2009-12-10
写个def文件后用implib

Error 42: Symbol Undefined _SQLFreeStmt@8 和下面是对应的,有几个错误的写几个.

1.def文件如下:
LIBRARY 'odbc.dll'

EXPORTS
_SQLFreeStmt@8=SQLFreeStmt


2.执行命令:
implib odbc.lib odbc.def



betty_betty2008 2009-12-11
ideage 写道
写个def文件后用implib

Error 42: Symbol Undefined _SQLFreeStmt@8 和下面是对应的,有几个错误的写几个.

1.def文件如下:
LIBRARY 'odbc.dll'

EXPORTS
_SQLFreeStmt@8=SQLFreeStmt


2.执行命令:
implib odbc.lib odbc.def





多谢了!管用。
hqs7636 2011-11-11
谁有最新的odbcd?
Global site tag (gtag.js) - Google Analytics