Index: driver/options.c =================================================================== --- driver/options.c (revision 971) +++ driver/options.c (working copy) @@ -476,15 +476,16 @@ case SQL_ATTR_CURRENT_CATALOG: - if (reget_current_catalog(dbc)) + if (is_connected(dbc) && reget_current_catalog(dbc)) { result= SQL_ERROR; } else { - *StringLengthPtr= (SQLSMALLINT) (strmake((char*)ValuePtr,dbc->database, - BufferLength) - - (char*) ValuePtr); + char *end= strmake((char*)ValuePtr, + dbc->database ? dbc->database : "", + BufferLength); + *StringLengthPtr= (SQLSMALLINT) (end - (char*) ValuePtr); } break; Index: test/my_info.c =================================================================== --- test/my_info.c (revision 971) +++ test/my_info.c (working copy) @@ -223,6 +223,7 @@ SQLSMALLINT conn_out_len; SQLCHAR rgbValue[MAX_NAME_LEN]; SQLSMALLINT pcbInfo; + SQLINTEGER attrlen; /* The connection string must not include DATABASE. */ sprintf((char *)conn, "DRIVER=%s;SERVER=localhost;" \ @@ -247,10 +248,10 @@ is_str(rgbValue, "null", pcbInfo); ok_con(hdbc1, SQLGetConnectAttr(hdbc1, SQL_ATTR_CURRENT_CATALOG, - rgbValue, MAX_NAME_LEN, &pcbInfo)); + rgbValue, MAX_NAME_LEN, &attrlen)); - is_num(pcbInfo, 4); - is_str(rgbValue, "null", pcbInfo); + is_num(attrlen, 4); + is_str(rgbValue, "null", attrlen); ok_stmt(hstmt1, SQLFreeStmt(hstmt1, SQL_DROP)); ok_con(hdbc1, SQLDisconnect(hdbc1)); @@ -260,6 +261,27 @@ } +/* + Bug#16653 + MyODBC 3 / truncated UID when performing Data Import in MS Excel +*/ +DECLARE_TEST(t_bug16653) +{ + SQLHANDLE hdbc1; + SQLCHAR buf[50]; + ok_env(henv, SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1)); + + /* this would cause a crash if we arent connected */ + ok_con(hdbc1, SQLGetConnectAttr(hdbc1, SQL_ATTR_CURRENT_CATALOG, + buf, 50, NULL)); + is_str(buf, "", 1); + + ok_con(hdbc1, SQLFreeHandle(SQL_HANDLE_DBC, hdbc1)); + + return OK; +} + + BEGIN_TESTS ADD_TEST(sqlgetinfo) ADD_TEST(t_gettypeinfo) @@ -270,6 +292,7 @@ ADD_TEST(t_bug14639) ADD_TEST(t_bug31055) ADD_TEST(t_bug3780) + ADD_TEST(t_bug16653) END_TESTS Index: util/MYODBCUtilWriteConnectStr.c =================================================================== --- util/MYODBCUtilWriteConnectStr.c (revision 971) +++ util/MYODBCUtilWriteConnectStr.c (working copy) @@ -37,156 +37,158 @@ return FALSE; if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszDATABASE, nMaxLen, &nIndex ) ) return FALSE; + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; } if ( pDataSource->pszDESCRIPTION ) { - if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) - return FALSE; if ( !MYODBCUtilInsertStr( pszStr, "DESCRIPTION=", nMaxLen, &nIndex ) ) return FALSE; if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszDESCRIPTION, nMaxLen, &nIndex ) ) return FALSE; + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; } if ( pDataSource->pszDRIVER && pDataSource->nConnect == MYODBCUTIL_DATASOURCE_CONNECT_DRIVER ) { - if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) - return FALSE; if ( !MYODBCUtilInsertStr( pszStr, "DRIVER=", nMaxLen, &nIndex ) ) return FALSE; if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszDRIVER, nMaxLen, &nIndex ) ) return FALSE; + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; } if ( pDataSource->pszDSN && pDataSource->nConnect == MYODBCUTIL_DATASOURCE_CONNECT_DSN ) { - if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) - return FALSE; if ( !MYODBCUtilInsertStr( pszStr, "DSN=", nMaxLen, &nIndex ) ) return FALSE; if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszDSN, nMaxLen, &nIndex ) ) return FALSE; + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; } if ( pDataSource->pszOPTION ) { - if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) - return FALSE; if ( !MYODBCUtilInsertStr( pszStr, "OPTION=", nMaxLen, &nIndex ) ) return FALSE; if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszOPTION, nMaxLen, &nIndex ) ) return FALSE; + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; } if ( pDataSource->pszPASSWORD ) { - if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) - return FALSE; if ( !MYODBCUtilInsertStr( pszStr, "PWD=", nMaxLen, &nIndex ) ) return FALSE; if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszPASSWORD, nMaxLen, &nIndex ) ) return FALSE; + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; } if ( pDataSource->pszPORT ) { - if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) - return FALSE; if ( !MYODBCUtilInsertStr( pszStr, "PORT=", nMaxLen, &nIndex ) ) return FALSE; if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszPORT, nMaxLen, &nIndex ) ) return FALSE; + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; } if ( pDataSource->pszSERVER ) { - if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) - return FALSE; if ( !MYODBCUtilInsertStr( pszStr, "SERVER=", nMaxLen, &nIndex ) ) return FALSE; if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszSERVER, nMaxLen, &nIndex ) ) return FALSE; + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; } if ( pDataSource->pszSOCKET ) { - if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) - return FALSE; if ( !MYODBCUtilInsertStr( pszStr, "SOCKET=", nMaxLen, &nIndex ) ) return FALSE; if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszSOCKET, nMaxLen, &nIndex ) ) return FALSE; + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; } if ( pDataSource->pszSTMT ) { - if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) - return FALSE; if ( !MYODBCUtilInsertStr( pszStr, "STMT=", nMaxLen, &nIndex ) ) return FALSE; if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszSTMT, nMaxLen, &nIndex ) ) return FALSE; + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; } if ( pDataSource->pszUSER ) { - if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) - return FALSE; if ( !MYODBCUtilInsertStr( pszStr, "UID=", nMaxLen, &nIndex ) ) return FALSE; if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszUSER, nMaxLen, &nIndex ) ) return FALSE; + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; } if ( pDataSource->pszSSLCA ) { - if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) - return FALSE; if ( !MYODBCUtilInsertStr( pszStr, "SSLCA=", nMaxLen, &nIndex ) ) return FALSE; if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszSSLCA, nMaxLen, &nIndex ) ) return FALSE; + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; } if ( pDataSource->pszSSLCAPATH ) { - if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) - return FALSE; if ( !MYODBCUtilInsertStr( pszStr, "SSLCAPATH=", nMaxLen, &nIndex ) ) return FALSE; if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszSSLCAPATH, nMaxLen, &nIndex ) ) return FALSE; + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; } if ( pDataSource->pszSSLCERT ) { - if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) - return FALSE; if ( !MYODBCUtilInsertStr( pszStr, "SSLCERT=", nMaxLen, &nIndex ) ) return FALSE; if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszSSLCERT, nMaxLen, &nIndex ) ) return FALSE; + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; } if ( pDataSource->pszSSLCIPHER ) { - if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) - return FALSE; if ( !MYODBCUtilInsertStr( pszStr, "SSLCIPHER=", nMaxLen, &nIndex ) ) return FALSE; if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszSSLCIPHER, nMaxLen, &nIndex ) ) return FALSE; + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; } if ( pDataSource->pszSSLKEY ) { - if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) - return FALSE; if ( !MYODBCUtilInsertStr( pszStr, "SSLKEY=", nMaxLen, &nIndex ) ) return FALSE; if ( !MYODBCUtilInsertStr( pszStr, pDataSource->pszSSLKEY, nMaxLen, &nIndex ) ) return FALSE; + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; } if (pDataSource->pszCHARSET) @@ -198,6 +200,8 @@ if (!MYODBCUtilInsertStr(pszStr, pDataSource->pszCHARSET, nMaxLen, &nIndex)) return FALSE; + if (nIndex && !MYODBCUtilInsertStr(pszStr, ";", nMaxLen, &nIndex)) + return FALSE; } return TRUE;