示例#1
0
int CDBase::CreateDSN(_ConnStr ConnStr)
{ 
//	'DSN=SQL_DSNName112;DESCRIPTION=SQL DSN description;SERVER=AW\SQLEXPRESS;DATABASE=ADM;'
   int nRetCode;  
   CString s;
   s="DSN="+ConnStr.DSNname+";";
   s=s+"DESCRIPTION="+ConnStr.Desc+";";
   s=s+"SERVER="+ConnStr.Server+";";
   s=s+"DATABASE="+ConnStr.Database+";";
 
   //printf("ConnStr=%s\n",s.GetBuffer());

   char *szAttributes=s.GetBuffer(s.GetLength()); 
    printf("Attributes='%s'\n",szAttributes);
   for(int i=0;i<s.GetLength();i++) 
   { 
	if(*(szAttributes+i)==(unsigned char)';') 
		*(szAttributes+i)=NULL; 
   }  
    try
    {
		nRetCode = SQLConfigDataSource(NULL, ODBC_ADD_DSN, ConnStr.Driver.GetBuffer(), szAttributes);
	}
    catch(CDBException *err)
    {
		//MessageBox(NULL,err->m_strError,"SQL Error"	,MB_OK);
    	printf("%s \n",err->m_strStateNativeOrigin);	
		printf("%s \n",err->m_strError);
		err->Delete();
	}
	{
	   //printf("Error create DSN in registry!\n"); 
    }
   return nRetCode;	
}
示例#2
0
void OdbcConnectionUtil::SetupDbaseDSN()
{
    const char* module = GetTestDataPath();
	if (module != NULL && module[0] != '\0')
	{
        // Remove the slash at the end of string
        char newModule[MAX_PATH];
        strcpy(newModule, module);
        int nLen = strlen(newModule);
        if (nLen > 0 && newModule[nLen-1] == '\\')
            newModule[nLen-1] = '\0';

        char teststr[1024];
        m_SetupDbaseDSNdone = true;

        FdoStringP dsnNameP = m_SetupValues->GetPropertyValue( L"DSNDbase" );
        const char * dsnName = (const char*)dsnNameP;
        sprintf (teststr, "DSN=%s%cDescription=Test dBASE datastore for FDO ODBC provider%cDefaultDir=%s%c%c", dsnName, 
            '\0', '\0', newModule, '\0', '\0');
        if (!SQLConfigDataSource (NULL, ODBC_ADD_DSN, (const char*)DBASE_ODBC_DRIVER_NAME, teststr))
        {
            DWORD error;
            WORD count;
            SQLInstallerError (1, &error, teststr, sizeof (teststr), &count);
            printf (teststr);
            throw FdoException::Create (L"dBASE DSN setup failed");
		}
	}
}
示例#3
0
void OdbcConnectionUtil::SetupExcelDSN()
{
    char module[MAX_PATH];
    char teststr[1024];
    DWORD nchars;
    char* last;
    m_SetupExcelDSNdone = true;
    nchars = GetModuleFileName (NULL, module, MAX_PATH);
    if (0 != nchars)
    {   
        // scan the string for the last occurrence of a slash
        last = strrchr (module, '\\');
        if (NULL != last)
        {
            last++; // move past the slash
            *last = '\0'; // null terminate it there
            sprintf (teststr, "DSN=%s%cDescription=Test Excel datastore for FDO ODBC provider%cDBQ=%sMSTest.xls%c%c", (const char*)(FdoStringP)m_SetupValues->GetPropertyValue( L"DSNExcel" ),
				'\0', '\0', module, '\0', '\0');
            if (!SQLConfigDataSource (NULL, ODBC_ADD_DSN, (const char*)EXCEL_ODBC_DRIVER_NAME, teststr))
			{
                DWORD error;
                WORD count;
                SQLInstallerError (1, &error, teststr, sizeof (teststr), &count);
                printf (teststr);
                throw FdoException::Create (L"Excel DSN setup failed");
			}
		}
	}
}
示例#4
0
static BOOL
AddMyDSN()
{
	char attrs[200];

	CreateAttributeString(attrs, sizeof(attrs));

	/* I choose to remove the DSN if it already existed */
	SQLConfigDataSource(NULL, ODBC_REMOVE_SYS_DSN, DriverName, attrs);

	/* then create a new DSN */
	if (!SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, DriverName, attrs) &&
	    ProcessSQLErrorMessages("SQLConfigDataSource"))
		return FALSE;

	return TRUE;
}
示例#5
0
void OdbcConnectionUtil::SetupMySqlDSN()
{
    // Get the name of MySQL ODBC Driver
    char driverDesc[1024];
    char driverAttrs[1024];
    char theMySQLDriverName[1024] = "";
    BOOL ret = false;
    SQLRETURN rc = SQL_ERROR;

    SQLHENV sqlenv = SQL_NULL_HENV;
    rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HENV, &sqlenv);
    if ( SQLRETURN_OK(rc) )
        rc = SQLSetEnvAttr(sqlenv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);

    if ( SQLRETURN_OK(rc) )
    {
        SQLUSMALLINT direction = SQL_FETCH_FIRST;
        SQLSMALLINT driverDescLength = 0;
        SQLSMALLINT driverAttrsLength = 0;
        do
        {
            driverDescLength = 0;
            driverAttrsLength = 0;
            rc = SQLDrivers(sqlenv, direction, (SQLCHAR *) driverDesc, (SQLSMALLINT) sizeof(driverDesc), &driverDescLength,
                (SQLCHAR *) driverAttrs, (SQLSMALLINT) sizeof(driverAttrs), &driverAttrsLength);
            if (SQLRETURN_OK(rc))
            {
                if (NULL != strstr(driverDesc, "MySQL"))
                    strcpy(theMySQLDriverName, driverDesc);
            }
            direction = SQL_FETCH_NEXT;
        }
        while ( SQLRETURN_OK(rc) && SQL_NO_DATA != rc && '\0' == theMySQLDriverName[0] );
    }

    if (sqlenv != SQL_NULL_HENV)
        SQLFreeHandle(SQL_HANDLE_ENV, sqlenv);

    if ('\0' != theMySQLDriverName[0])
        MYSQL_ODBC_DRIVER_NAME = theMySQLDriverName;

    char teststr[1024];
    sprintf (teststr, "DSN=%s%cDescription=Test MySql DSN for FDO ODBC provider%cSERVER=%s%cDATABASE=%ls%cOPTION=3%c%c", (const char*)(FdoStringP)m_SetupValues->GetPropertyValue( L"DSNMySql" ), 
        '\0','\0', (const char*)(FdoStringP)m_SetupValues->GetPropertyValue( L"serviceMySql" ), '\0', (FdoString*)(UnitTestUtil::GetEnviron("datastore", L"")), '\0', '\0', '\0');
    m_SetupMySqlDSNdone = true;
#if 0
    if (!SQLConfigDataSource (NULL, ODBC_ADD_DSN, (const char*)MYSQL_ODBC_DRIVER_NAME, teststr))
    {
        DWORD error;
        WORD count;
        SQLInstallerError (1, &error, teststr, sizeof (teststr), &count);
        printf (teststr);
        throw FdoException::Create (L"MySql DSN setup failed");
    }
#endif
}
示例#6
0
static BOOL
RemoveMyDSN()
{
	char buf[200];
	char *p;

	snprintf(buf, sizeof(buf), "DSN=%s;", DataSourceName);
	for (p = buf; *p; p++)
		if (*p == ';')
			*p = 0;
	SQLConfigDataSource(NULL, ODBC_REMOVE_SYS_DSN, DriverName, buf);
	return TRUE;
}
示例#7
0
void OdbcConnectionUtil::TeardownSqlServerDSN()
{
    char pString[SQL_MAX_MESSAGE_LENGTH];
    DWORD error;
    WORD count;
	sprintf( pString, "DSN=%s%c%c", (const char*)(FdoStringP)m_SetupValues->GetPropertyValue( L"DSNSqlServer" ), '\0', '\0');
    if (!SQLConfigDataSource (NULL, ODBC_REMOVE_DSN, "SQL Server", pString))
    {
        SQLInstallerError (1, &error, pString, sizeof (pString), &count);
		printf ("\nSqlServer DSN teardown failed:\n");
        printf (pString);
    }
}
示例#8
0
void OdbcConnectionUtil::TeardownMySqlDSN()
{
#if 0
    char pString[SQL_MAX_MESSAGE_LENGTH];
    DWORD error;
    WORD count;
    sprintf( pString, "DSN=%s%c%c", (const char*)(FdoStringP)m_SetupValues->GetPropertyValue( L"DSNMySql" ), '\0', '\0');
    if (!SQLConfigDataSource (NULL, ODBC_REMOVE_DSN, (const char*)MYSQL_ODBC_DRIVER_NAME, pString))
    {
        SQLInstallerError (1, &error, pString, sizeof (pString), &count);
        printf ("\nMySql DSN teardown failed:\n");
        printf (pString);
    }
#endif
}
示例#9
0
void OdbcConnectionUtil::TeardownDbaseDSN()
{
    char pString[SQL_MAX_MESSAGE_LENGTH];
    DWORD error;
    WORD count;
    FdoStringP dsnNameP = m_SetupValues->GetPropertyValue( L"DSNDbase" );
    const char * dsnName = (const char*)dsnNameP;
	sprintf( pString, "DSN=%s%c%c", dsnName, '\0', '\0');
    if (!SQLConfigDataSource (NULL, ODBC_REMOVE_DSN, (const char*)DBASE_ODBC_DRIVER_NAME, pString))
    {
        SQLInstallerError (1, &error, pString, sizeof (pString), &count);
		printf ("\ndBASE DSN teardown failed:\n");
        printf (pString);
    }
}
示例#10
0
void OdbcConnectionUtil::SetupSqlServerDSN()
{
    char teststr[1024];
    sprintf (teststr, "DSN=%s%cDescription=Test SqlServer DSN for FDO ODBC provider%cSERVER=%s%cDATABASE=%ls%c%c", (const char*)(FdoStringP)m_SetupValues->GetPropertyValue( L"DSNSqlServer" ), 
		'\0', '\0', (const char*)(FdoStringP)m_SetupValues->GetPropertyValue( L"serviceSqlServer" ), '\0', (FdoString*)(UnitTestUtil::GetEnviron("datastore", L"")), '\0', '\0', '\0');
    m_SetupSqlServerDSNdone = true;
    if (!SQLConfigDataSource (NULL, ODBC_ADD_DSN, "SQL Server", teststr))
    {
        DWORD error;
        WORD count;
        SQLInstallerError (1, &error, teststr, sizeof (teststr), &count);
        printf (teststr);
        throw FdoException::Create (L"SqlServer DSN setup failed");
    }
}
示例#11
0
void OdbcConnectionUtil::TeardownOracleDSN()
{
	if (m_SetupValues->PropertyExist( L"enableOracleSetup" ))
	{
		FdoStringP pValue = m_SetupValues->GetPropertyValue( L"enableOracleSetup" );
		if (pValue != L"true")
			return;
	}
    char pString[SQL_MAX_MESSAGE_LENGTH];
    DWORD error;
    WORD count;
	sprintf( pString, "DSN=%s%c%c", (const char*)(FdoStringP)m_SetupValues->GetPropertyValue( L"DSNOracle" ), '\0', '\0');
    if (!SQLConfigDataSource (NULL, ODBC_REMOVE_DSN, theOracleDriverName, pString))
    {
        SQLInstallerError (1, &error, pString, sizeof (pString), &count);
		printf ("\nOracle DSN teardown failed:\n");
        printf (pString);
    }
}
示例#12
0
void OdbcConnectionUtil::SetupAccessDSN()
{
    const char* module = GetTestDataPath();
	if (module != NULL && module[0] != '\0')
	{
        char teststr[1024];
        m_SetupAccessDSNdone = true;
        sprintf (teststr, "DSN=%s%cDescription=Test Access datastore for FDO ODBC provider%cDBQ=%sMSTest.mdb%c%c", (const char*)(FdoStringP)m_SetupValues->GetPropertyValue( L"DSNAccess" ), 
            '\0', '\0', module, '\0', '\0');
        if (!SQLConfigDataSource (NULL, ODBC_ADD_DSN, (const char*)ACCESS_ODBC_DRIVER_NAME, teststr))
		{
            DWORD error;
            WORD count;
            SQLInstallerError (1, &error, teststr, sizeof (teststr), &count);
            printf (teststr);
            throw FdoException::Create (L"Access DSN setup failed");
		}
	}
}
示例#13
0
void CODBCCreate::accept()
{
	if ( fds->isOn())
	{
		QString conn_str;
		char out_str[ 4095 ];
		const char *in_str;
		SQLHENV henv;
		SQLHDBC hdbc;
		SQLSMALLINT len;
		SQLRETURN ret;
		QString fname = file_edit->text();

		// Make sure it ends with .dsn
	
		if ( fname.right( 4 ).lower().compare( ".dsn" ))
		{
			fname.append( ".dsn" );
			file_edit->setText( fname );
		}

		conn_str = "DRIVER={" + current_driver + "};SAVEFILE=" + fname + ";";

		if ( extra_keywords.length() > 0 )
		{
			int start = 0;
			int end = 0;

			while( start < extra_keywords.length() )
			{
				end = extra_keywords.find( '\n', start );

				if ( end == -1 )
				{
					end = extra_keywords.length();
				}

				conn_str += extra_keywords.mid( start, end-start ) + ";";
				start = end + 1;
			}
		}
		in_str = (const char*)conn_str;

		if ( verify )
		{
			SQLAllocEnv( &henv );
			SQLAllocConnect( henv, &hdbc );

			ret = SQLDriverConnect( hdbc, (SQLHWND)1, 
					(SQLCHAR*)in_str, strlen( in_str ), (SQLCHAR*)out_str, 
					sizeof( out_str ), &len, SQL_DRIVER_COMPLETE );
	
			SQLFreeConnect( hdbc );
			SQLFreeEnv( henv );

			if ( ret != SQL_SUCCESS ) 
			{
				int create = QMessageBox::No;

				create = QMessageBox::information( NULL, "Create Data Source", "A connection could not be made using the file data source parameters entered. Save non-verified file DSN?", QMessageBox::Yes, QMessageBox::No );
				if ( create == QMessageBox::No )
				{
					inst_logPushMsg( __FILE__, __FILE__, __LINE__, LOG_CRITICAL, ODBC_ERROR_CREATE_DSN_FAILED, "" );
					ret_code = false;
#ifdef QT_V4LAYOUT
					Q3Wizard::reject();
#else
					QWizard::reject();
#endif
					return;
				}
				else 
				{
					strcpy( out_str, in_str );
					if ( !createDsn())
					{
						ret_code = false;
#ifdef QT_V4LAYOUT
						Q3Wizard::reject();
#else
						QWizard::reject();
#endif
						return;
					}
				}
			}
		}
		else
		{
			strcpy( out_str, in_str );
			if ( !createDsn())
			{
				ret_code = false;
#ifdef QT_V4LAYOUT
				Q3Wizard::reject();
#else
				QWizard::reject();
#endif
				return;
			}
		}
	
		ret_code = true;
	}
	else
	{
		int mode;

		if ( sds -> isOn())
		{
			mode = ODBC_ADD_SYS_DSN;
		}
		else
		{
			mode = ODBC_ADD_DSN;
		}

		if ( dsn.length() > 0 )
		{
			ret_code = SQLConfigDataSource((HWND) 1, mode, current_driver, dsn.prepend( "DSN=" ));
		}
		else
		{
			ret_code = SQLConfigDataSource((HWND) 1, mode, current_driver, "" );
		}
	}

#ifdef QT_V4LAYOUT
	Q3Wizard::accept();
#else
	QWizard::accept();
#endif
}
示例#14
0
文件: inst.c 项目: CompassHXM/h-store
static BOOL
InUn(int remove, char *drivername, char *dllname, char *dll2name, char *dsname)
{
    char path[301], driver[300], attr[300], inst[400], inst2[400];
    WORD pathmax = sizeof (path) - 1, pathlen;
    DWORD usecnt, mincnt;

    if (SQLInstallDriverManager(path, pathmax, &pathlen)) {
	char *p;

	sprintf(driver, "%s;Driver=%s;Setup=%s;",
		drivername, dllname, dllname);
	p = driver;
	while (*p) {
	    if (*p == ';') {
		*p = '\0';
	    }
	    ++p;
	}
	usecnt = 0;
	SQLInstallDriverEx(driver, NULL, path, pathmax, &pathlen,
			   ODBC_INSTALL_INQUIRY, &usecnt);
	sprintf(driver, "%s;Driver=%s\\%s;Setup=%s\\%s;",
		drivername, path, dllname, path, dllname);
	p = driver;
	while (*p) {
	    if (*p == ';') {
		*p = '\0';
	    }
	    ++p;
	}
	sprintf(inst, "%s\\%s", path, dllname);
	if (dll2name) {
	    sprintf(inst2, "%s\\%s", path, dll2name);
	}
	if (!remove && usecnt > 0) {
	    /* first install try: copy over driver dll, keeping DSNs */
	    if (GetFileAttributes(dllname) != INVALID_FILE_ATTRIBUTES &&
		CopyFile(dllname, inst, 0) &&
		CopyOrDelModules(dllname, path, 0)) {
		if (dll2name != NULL) {
		    CopyFile(dll2name, inst2, 0);
		}
		return TRUE;
	    }
	}
	mincnt = remove ? 1 : 0;
	while (usecnt != mincnt) {
	    if (!SQLRemoveDriver(driver, TRUE, &usecnt)) {
		break;
	    }
	}
	if (remove) {
	    if (!SQLRemoveDriver(driver, TRUE, &usecnt)) {
		ProcessErrorMessages("SQLRemoveDriver");
		return FALSE;
	    }
	    if (!usecnt) {
		char buf[512];

		DeleteFile(inst);
		/* but keep inst2 */
		CopyOrDelModules(dllname, path, 1);
		if (!quiet) {
		    sprintf(buf, "%s uninstalled.", drivername);
		    MessageBox(NULL, buf, "Info",
			       MB_ICONINFORMATION|MB_OK|MB_TASKMODAL|
			       MB_SETFOREGROUND);
		}
	    }
	    if (nosys) {
		goto done;
	    }
	    sprintf(attr, "DSN=%s;Database=sqlite.db;", dsname);
	    p = attr;
	    while (*p) {
		if (*p == ';') {
		    *p = '\0';
		}
		++p;
	    }
	    SQLConfigDataSource(NULL, ODBC_REMOVE_SYS_DSN, drivername, attr);
	    goto done;
	}
	if (GetFileAttributes(dllname) == INVALID_FILE_ATTRIBUTES) {
	    return FALSE;
	}
	if (!CopyFile(dllname, inst, 0)) {
	    char buf[512];

	    sprintf(buf, "Copy %s to %s failed", dllname, inst);
	    MessageBox(NULL, buf, "CopyFile",
		       MB_ICONSTOP|MB_OK|MB_TASKMODAL|MB_SETFOREGROUND); 
	    return FALSE;
	}
	if (dll2name != NULL && !CopyFile(dll2name, inst2, 0)) {
	    char buf[512];

	    sprintf(buf, "Copy %s to %s failed", dll2name, inst2);
	    MessageBox(NULL, buf, "CopyFile",
		       MB_ICONSTOP|MB_OK|MB_TASKMODAL|MB_SETFOREGROUND); 
	    /* but go on hoping that an SQLite engine is in place */
	}
	if (!CopyOrDelModules(dllname, path, 0)) {
	    return FALSE;
	}
	if (!SQLInstallDriverEx(driver, path, path, pathmax, &pathlen,
				ODBC_INSTALL_COMPLETE, &usecnt)) {
	    ProcessErrorMessages("SQLInstallDriverEx");
	    return FALSE;
	}
	if (nosys) {
	    goto done;
	}
	sprintf(attr, "DSN=%s;Database=sqlite.db;", dsname);
	p = attr;
	while (*p) {
	    if (*p == ';') {
		*p = '\0';
	    }
	    ++p;
	}
	SQLConfigDataSource(NULL, ODBC_REMOVE_SYS_DSN, drivername, attr);
	if (!SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN, drivername, attr)) {
	    ProcessErrorMessages("SQLConfigDataSource");
	    return FALSE;
	}
    } else {
	ProcessErrorMessages("SQLInstallDriverManager");
	return FALSE;
    }
done:
    return TRUE;
}
BOOL INSTAPI
SQLRemoveDefaultDataSource (void)
{
  return SQLConfigDataSource (NULL, ODBC_REMOVE_DEFAULT_DSN, NULL, NULL);
}
int test_fun_odbc_api_Oracle__dynDNS()
{
	int nFunRes = 0;

	// Drop and re-create a Msorcl10.dll (version 1.0) data source.
	nFunRes = SQLConfigDataSource( NULL, ODBC_REMOVE_DSN,	"Microsoft ODBC for Oracle", "DSN=Oracle12343DYN\0");

	nFunRes = SQLConfigDataSource( NULL,
		ODBC_ADD_DSN,
		"Microsoft ODBC for Oracle",
		"Description=My Description Text\0"
		"Server=TRANSACT\0"
		"DSN=Oracle12343DYN\0"
		"PWD=IT271350_5\0"
		"UID=IT271350_5\0"
		);


	SQLHENV m_hEnviroment;
	SQLHDBC m_hDatabaseConnection;
	SQLHSTMT m_hStatement;
	SQLRETURN retcode;

	/*Allocate environment handle */
	retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &m_hEnviroment);
	if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) 
	{
		return nFunRes;
	}

	/* Set the ODBC version environment attribute */
	retcode = SQLSetEnvAttr(m_hEnviroment, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
	if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) 
	{
		retcode = SQLFreeHandle(SQL_HANDLE_ENV, m_hEnviroment);
		return nFunRes;
	}

	/* Allocate connection handle */
	retcode = SQLAllocHandle(SQL_HANDLE_DBC, m_hEnviroment, &m_hDatabaseConnection);
	if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) 
	{
		retcode = SQLFreeHandle(SQL_HANDLE_ENV, m_hEnviroment);
		return nFunRes;
	}


	/* Set login timeout to 5 seconds. */
	//SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, 5, 0);

	/* Connect to data source */
	retcode = SQLConnect(m_hDatabaseConnection, 
		(SQLCHAR*) "Oracle12343DYN", SQL_NTS,
		(SQLCHAR*) "IT271350_5", SQL_NTS,
		(SQLCHAR*) "IT271350_5", SQL_NTS);
	if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) 
	{
		retcode = SQLFreeHandle(SQL_HANDLE_DBC, m_hDatabaseConnection);
		retcode = SQLFreeHandle(SQL_HANDLE_ENV, m_hEnviroment);
		return nFunRes;
	}


	/* Allocate statement handle */
	retcode = SQLAllocHandle(SQL_HANDLE_STMT, m_hDatabaseConnection, &m_hStatement);
	if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) 
	{
		retcode = SQLDisconnect(m_hDatabaseConnection);
		retcode = SQLFreeHandle(SQL_HANDLE_DBC, m_hDatabaseConnection);
		retcode = SQLFreeHandle(SQL_HANDLE_ENV, m_hEnviroment);
		return nFunRes;
	}

	retcode = SQLExecDirect(m_hStatement,(SQLCHAR*)"select pkey from recipient_info", SQL_NTS);
	if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
	{
		retcode = SQLFreeHandle(SQL_HANDLE_STMT, m_hStatement);
		retcode = SQLDisconnect(m_hDatabaseConnection);
		retcode = SQLFreeHandle(SQL_HANDLE_DBC, m_hDatabaseConnection);
		retcode = SQLFreeHandle(SQL_HANDLE_ENV, m_hEnviroment);
		return nFunRes;
	}


	/* get return data Row count */
	SQLINTEGER l_siIdCount = 0;
	retcode = SQLRowCount(m_hStatement, &l_siIdCount);
	if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
	{
		retcode = SQLFreeHandle(SQL_HANDLE_STMT, m_hStatement);
		retcode = SQLDisconnect(m_hDatabaseConnection);
		retcode = SQLFreeHandle(SQL_HANDLE_DBC, m_hDatabaseConnection);
		retcode = SQLFreeHandle(SQL_HANDLE_ENV, m_hEnviroment);
		return nFunRes;
	}

	while (true)
	{
		//fecth data use SQLFetch() return SQL_SUCCESS  then no data
		retcode = SQLFetch(m_hStatement);
		if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
		{
			break;
		}

		SQLINTEGER l_siID;
		SQLINTEGER l_siIDLength = 0;

		retcode = SQLGetData(m_hStatement, 1, SQL_C_ULONG, &l_siID, 0, &l_siIDLength);
		if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
		{
			break;
		}
	}//while (true)


	/* Process data */
	retcode = SQLFreeHandle(SQL_HANDLE_STMT, m_hStatement);
	retcode = SQLDisconnect(m_hDatabaseConnection);
	retcode = SQLFreeHandle(SQL_HANDLE_DBC, m_hDatabaseConnection);
	retcode = SQLFreeHandle(SQL_HANDLE_ENV, m_hEnviroment);



	nFunRes = SQLConfigDataSource( NULL, ODBC_REMOVE_DSN,	"Microsoft ODBC for Oracle", "DSN=Oracle12343DYN\0");

	return nFunRes;
}
int test_fun_odbc_api_Mysql__DBPOOL_DYN()
{
	int nFunRes = 0;

	nFunRes = SQLConfigDataSource( NULL, ODBC_REMOVE_DSN,	"MySQL ODBC 5.2 Unicode Driver", "DSN=Mysql12343DYN\0");

	// Drop and re-create a Msorcl10.dll (version 1.0) data source.
	SQLConfigDataSource(NULL, ODBC_ADD_DSN, "MySQL ODBC 5.2 Unicode Driver",
		"DSN=Mysql12343DYN;UID=IT271350_5;PWD=IT271350_5;SERVER=192.168.123.43;DATABASE=tra_occ");


	SQLHENV m_hEnviroment;
	SQLHDBC m_hDatabaseConnection;
	SQLHSTMT m_hStatement;
	SQLRETURN retcode;

	////http://support.microsoft.com/kb/164221/en-us

	////http://www.informixchina.net/club/thread-5924-1-1.html

	/*Allocate environment handle */
	retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &m_hEnviroment);
	if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) 
	{
		return nFunRes;
	}
	// set the ODBC behavior version.
	/* Set the ODBC version environment attribute */
	retcode = SQLSetEnvAttr(m_hEnviroment, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0);
	if (!SQL_SUCCEEDED(retcode))  
	{
		retcode = SQLFreeHandle(SQL_HANDLE_ENV, m_hEnviroment);
		return nFunRes;
	}


	// make process level cursor pooling
	retcode = SQLSetEnvAttr(m_hEnviroment, SQL_ATTR_CONNECTION_POOLING,	(SQLPOINTER)SQL_CP_ONE_PER_DRIVER, SQL_IS_UINTEGER);
	if (!SQL_SUCCEEDED(retcode)) 
	{
		retcode = SQLFreeHandle(SQL_HANDLE_ENV, m_hEnviroment);
		return nFunRes;
	}




	//set the matching condition for using an existing connection in the pool
	retcode = SQLSetEnvAttr(m_hEnviroment, SQL_ATTR_CP_MATCH, (SQLPOINTER)SQL_CP_RELAXED_MATCH, 0);//SQL_IS_INTEGER
	if (!SQL_SUCCEEDED(retcode))  
	{
		printf("SQLSetEnvAttr/SQL_ATTR_CP_MATCH error\n");
		retcode = SQLFreeHandle(SQL_HANDLE_ENV, m_hEnviroment);
		return nFunRes;
	}


	int nIndex = 0;
	while (nIndex < 10) 
	{
		/* Allocate connection handle */
		retcode = SQLAllocHandle(SQL_HANDLE_DBC, m_hEnviroment, &m_hDatabaseConnection);
		if (!SQL_SUCCEEDED(retcode))  
		{
			printf("SQLAllocHandle error\n");
			retcode = SQLFreeHandle(SQL_HANDLE_ENV, m_hEnviroment);
			return nFunRes;
		}



		/* Set login timeout to 5 seconds. */
		//SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, 5, 0);

		/* Connect to data source */
		retcode = SQLConnect(m_hDatabaseConnection, 
			(SQLCHAR*) "Mysql12343DYN", SQL_NTS,
			(SQLCHAR*) "IT271350_5", SQL_NTS,
			(SQLCHAR*) "IT271350_5", SQL_NTS);
		if (!SQL_SUCCEEDED(retcode))  
		{
			printf("SQLConnect error\n");
			retcode = SQLFreeHandle(SQL_HANDLE_DBC, m_hDatabaseConnection);
			retcode = SQLFreeHandle(SQL_HANDLE_ENV, m_hEnviroment);
			return nFunRes;
		}
		else
		{
			printf("Connect successfully %d times\n", nIndex);
		}


		//////////////////////////////////////////////////////////////////////////

		/* Allocate statement handle */
		retcode = SQLAllocHandle(SQL_HANDLE_STMT, m_hDatabaseConnection, &m_hStatement);
		if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) 
		{
			retcode = SQLDisconnect(m_hDatabaseConnection);
			retcode = SQLFreeHandle(SQL_HANDLE_DBC, m_hDatabaseConnection);
			retcode = SQLFreeHandle(SQL_HANDLE_ENV, m_hEnviroment);
			return nFunRes;
		}

		retcode = SQLExecDirect(m_hStatement,(SQLCHAR*)"select pkey from recipient_info", SQL_NTS);
		if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
		{
			retcode = SQLFreeHandle(SQL_HANDLE_STMT, m_hStatement);
			retcode = SQLDisconnect(m_hDatabaseConnection);
			retcode = SQLFreeHandle(SQL_HANDLE_DBC, m_hDatabaseConnection);
			retcode = SQLFreeHandle(SQL_HANDLE_ENV, m_hEnviroment);
			return nFunRes;
		}


		/* get return data Row count */
		SQLINTEGER l_siIdCount = 0;
		retcode = SQLRowCount(m_hStatement, &l_siIdCount);
		if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
		{
			retcode = SQLFreeHandle(SQL_HANDLE_STMT, m_hStatement);
			retcode = SQLDisconnect(m_hDatabaseConnection);
			retcode = SQLFreeHandle(SQL_HANDLE_DBC, m_hDatabaseConnection);
			retcode = SQLFreeHandle(SQL_HANDLE_ENV, m_hEnviroment);
			return nFunRes;
		}

		while (true)
		{
			//fecth data use SQLFetch() return SQL_SUCCESS  then no data
			retcode = SQLFetch(m_hStatement);
			if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
			{
				break;
			}

			SQLINTEGER l_siID;
			SQLINTEGER l_siIDLength = 0;

			retcode = SQLGetData(m_hStatement, 1, SQL_C_ULONG, &l_siID, 0, &l_siIDLength);
			if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
			{
				break;
			}
		}//while (true)


		//the first time, the application calls SQLDisconenct, it will return
		//the connection to the //pool
		retcode = SQLFreeHandle(SQL_HANDLE_STMT, m_hStatement);
		retcode = SQLDisconnect(m_hDatabaseConnection);
		retcode = SQLFreeHandle(SQL_HANDLE_DBC, m_hDatabaseConnection);

		//////////////////////////////////////////////////////////////////////////

		nIndex++;
	}//while (nIndex < 10) 

	retcode = SQLFreeHandle(SQL_HANDLE_ENV, m_hEnviroment);


	nFunRes = SQLConfigDataSource( NULL, ODBC_REMOVE_DSN,	"MySQL ODBC 5.2 Unicode Driver", "DSN=Mysql12343DYN\0");

	return nFunRes;
}
示例#18
0
// Establish an Oracle DSN.  Oracle does not have a constant name, but rather
// a formulated one based on installed instance.  We'll look for the substrings
// "Oracle" and "10g", unless the user has overridden this pattern using
// the "odbcoracledriver" environment variable.
void OdbcConnectionUtil::SetupOracleDSN()
{
    char driverDesc[1024];
    char driverAttrs[1024];
    theOracleDriverName[0] = '\0';
	char teststr[1024];
	BOOL ret = false;
	SQLRETURN rc = SQL_ERROR;
    m_SetupOracleDSNdone = true;

    SQLHENV sqlenv = SQL_NULL_HENV;
    rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HENV, &sqlenv);
    if ( SQLRETURN_OK(rc) )
        rc = SQLSetEnvAttr(sqlenv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);

    if ( SQLRETURN_OK(rc) )
    {
        SQLUSMALLINT direction = SQL_FETCH_FIRST;
        SQLSMALLINT driverDescLength = 0;
        SQLSMALLINT driverAttrsLength = 0;
        do
        {
            driverDescLength = 0;
            driverAttrsLength = 0;
            rc = SQLDrivers(sqlenv, direction, (SQLCHAR *) driverDesc, (SQLSMALLINT) sizeof(driverDesc), &driverDescLength,
                (SQLCHAR *) driverAttrs, (SQLSMALLINT) sizeof(driverAttrs), &driverAttrsLength);
            if (SQLRETURN_OK(rc))
            {
                #ifdef WIN32
                #pragma message("TODO: update this with each Oracle version update")
                #endif
                if (NULL != strstr(driverDesc, "Oracle") && (NULL != strstr(driverDesc, "10") || NULL != strstr(driverDesc, "11")))
                    strcpy(theOracleDriverName, driverDesc);
            }
            direction = SQL_FETCH_NEXT;
        }
        while ( SQLRETURN_OK(rc) && SQL_NO_DATA != rc && '\0' == theOracleDriverName[0] );
	    
        if (m_SetupValues->PropertyExist( L"enableOracleSetup" ))
	    {
		    FdoStringP pValue = m_SetupValues->GetPropertyValue( L"enableOracleSetup" );
		    if (pValue != L"true")
			    return;
	    }
        if (SQL_NO_DATA == rc)
            rc = SQL_SUCCESS;
		direction = SQL_FETCH_FIRST;
		FdoStringP pDSNOracle = m_SetupValues->GetPropertyValue( L"DSNOracle");
		while(SQLRETURN_OK(SQLDataSources(sqlenv, direction, (SQLCHAR *)teststr, sizeof(teststr), &driverAttrsLength, (SQLCHAR *)driverDesc, sizeof(driverDesc), &driverDescLength)))
		{
			direction = SQL_FETCH_NEXT;
			if (pDSNOracle == (FdoStringP)teststr)
			{
				SQLFreeHandle(SQL_HANDLE_ENV, sqlenv);
				return;
			}
		}
    }
    if (SQLRETURN_OK(rc) && '\0' != theOracleDriverName[0])
    {
        char* datastoreUpper = driverDesc;
        sprintf(datastoreUpper, "%ls", (FdoString*) UnitTestUtil::GetEnviron("datastore", L""));
        (void) _strupr_s(datastoreUpper, 1024);

        sprintf ( teststr, "DSN=%s%cDescription=Oracle DSN for FDO ODBC provider%cServerName=%s%cUserID=%s%c%c", (const char*)(FdoStringP)m_SetupValues->GetPropertyValue( L"DSNOracle"), '\0',
            '\0', (const char*)(FdoStringP)m_SetupValues->GetPropertyValue( L"serviceOracle" ), '\0', datastoreUpper, '\0', '\0', '\0');
		ret = SQLConfigDataSource (NULL, ODBC_ADD_DSN, theOracleDriverName, teststr);
    }

    if (!SQLRETURN_OK(rc))
    {
    	SQLSMALLINT cRecNmbr = 1;
	    UCHAR		szSqlState[MAX_PATH] = "";
	    UCHAR 	 	szErrorMsg[MAX_PATH] = "";
	    SDWORD		pfNativeError = 0L;
	    SWORD	 	pcbErrorMsg = 0;

		rc = SQLGetDiagRec(SQL_HANDLE_ENV, sqlenv, 1, szSqlState, &pfNativeError, szErrorMsg, MAX_PATH-1, &pcbErrorMsg);
        printf("%.200s\n", (char *)szErrorMsg);
        throw FdoException::Create (L"Oracle DSN setup failed");
    }
	if (sqlenv != SQL_NULL_HENV)
		SQLFreeHandle(SQL_HANDLE_ENV, sqlenv);
    if (!ret )
    {
        DWORD error;
        WORD count;
        SQLInstallerError (1, &error, teststr, sizeof (teststr), &count);
        printf (teststr);
        throw FdoException::Create (L"Oracle DSN setup failed");
    }

    if ('\0' == theOracleDriverName[0])
        throw FdoException::Create (L"Oracle DSN setup failed");
}
示例#19
0
BOOL CRecorderApp::InitInstance()
{
	

	// InitCommonControlsEx() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// Set this to include all the common control classes you want to use
	// in your application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();


	AfxEnableControlContainer();

	// Create the shell manager, in case the dialog contains
	// any shell tree view or shell list view controls.
	CShellManager *pShellManager = new CShellManager;

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	// of your final executable, you should remove from the following
	// the specific initialization routines you do not need
	// Change the registry key under which our settings are stored
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));
	
	//the Initialization for the call of external dll and lib!!!
	bool res = false,res1=false,res2=false,res3=false;
		res = mclInitializeApplication(NULL,0);
	if (!res)
	{
		AfxMessageBox(_T("��ʼ��Application������"));
	}
	res = InitializeInitialize();
	res1 = TrainingInitialize();
	res2 = IncTrainInitialize();
	res3 = TestSpeechInitialize();
	if (!res||!res1||!res2||!res3)
	{
		AfxMessageBox(_T("��ʼ��Lib������"));
	}

	

	CString sPath;
	GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
	sPath.ReleaseBuffer();
	int nPos;
	nPos=sPath.ReverseFind ('\\');
	sPath=sPath.Left (nPos);

	CString lpszFile = sPath + "\\SR1.accdb";
	
	//AfxMessageBox(lpszFile);//
	

	CString str;
	str.Format(_T("DSN=%s? DBQ=%s? FIL=MicrosoftAccess? DEFAULTDIR=%s?? "),_T("SRDSN"),lpszFile,sPath);

	int mlen = str.GetLength();
    for (int i=0; i<mlen; i++)
	{
		if (str.GetAt(i) == '?')
			str.SetAt(i,'\0');
	}

  if (FALSE == SQLConfigDataSource(NULL,ODBC_ADD_DSN,_T("Microsoft Access Driver (*.mdb, *.accdb)\0"),str))
		AfxMessageBox(_T("SQLConfigDataSource Failed"));
  
  //seek for the folder,if not exist,create it.
	CString folderName = _T("E:\\Speechdata");
	
	if(!PathIsDirectory(folderName)){
		CreateDirectory(folderName,NULL);
	}
	folderName = _T("E:\\Speechdata\\Test");
	if(!PathIsDirectory(folderName)){
		CreateDirectory(folderName,NULL);
	}
	CFirstPageDlg cfpdlg;
	cfpdlg.DoModal();

	


	// Delete the shell manager created above.
	if (pShellManager != NULL)
	{
		delete pShellManager;
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.

	InitializeTerminate();
	TrainingTerminate();
	IncTrainTerminate();
	TestSpeechTerminate();
	res = mclTerminateApplication();
	if (!res)
	{
		AfxMessageBox(_T("����Application����!"));
	}
	return FALSE;
}