安装好MySQL后没有/usr/local/mysql 目录
源程序如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sql.h "
#include "sqlext.h "
void
check_return (RETCODE rc,
HENV henv,
HDBC hdbc,
HSTMT hstmt )
{
UCHAR state_str [SQL_MAX_MESSAGE_LENGTH];
SDWORD native_error;
UCHAR error_msg [SQL_MAX_MESSAGE_LENGTH];
SWORD error_msg_avail = SQL_MAX_MESSAGE_LENGTH - 1;
SWORD error_msg_len;
RETCODE local_rc;
if (rc != SQL_ERROR && rc != SQL_SUCCESS_WITH_INFO )
{
return;
}
local_rc = SQL_Error (henv,hdbc,hstmt,state_str,&native_error,error_msg,error_msg_avail,&error_msg_len);
if (local_rc != SQL_SUCCESS && rc !=SQL_SUCCESS_WITH_INFO)
{
fprintf(stderr, "Uninterpretable error; exiting \n ");
exit (EXIT_FAILURE);
}
if (rc == SQL_SUCCESS_WITH_INFO)
{
fprintf(stderr, "Fatal Error %s: %s\n ", state_str,error_msg);
return;
}
fprintf(stderr, "Fatal Error %s: %s\n ",state_str,error_msg);
exit (EXIT_FAILURE);
}
/*----------------------------------*/
int main (void)
{
HENV henv = SQL_NULL_HENV;
HDBC hdbc = SQL_NULL_HDBC;
HSTMT hstmt = SQL_NULL_HSTMT;
RETCODE rc;
char buf[257];
short buflen;
printf ( "Initialize the environment structure.\n ");
SQLAllocEnv (&henv);
printf ( "Initialize the connection structure.\n ");
SQLAllocConnect (henv,&hdbc);
printf( "Load the ODBC driver.\n ");
rc = SQLDriverConnect (hdbc,0, "DSN=baseball;UID=myloginWD=mypassword ",SQL_NTS,(UCHAR*) buf,sizeof (buf),&buflen,SQL_DRIVER_COMPLETE);
check_return (rc,henv,hdbc,hstmt);
&nbs