Added:
MYODBCIns/MYODBCInsLib/MYODBCIns.cpp
MYODBCIns/MYODBCInsLib/MYODBCInsDataSource.cpp
MYODBCIns/MYODBCInsLib/MYODBCInsDriver.cpp
MYODBCIns/MYODBCInsLib/MYODBCInsDriverConnect.cpp
MYODBCIns/include/MYODBCInsDataSource.h
MYODBCIns/include/MYODBCInsDriver.h
MYODBCIns/include/MYODBCInsDriverConnect.h
Removed:
MYODBCIns/MYODBCInsLib/MYODBCInsAllocDataSource.c
MYODBCIns/MYODBCInsLib/MYODBCInsAllocDriver.c
MYODBCIns/MYODBCInsLib/MYODBCInsClearDataSource.c
MYODBCIns/MYODBCInsLib/MYODBCInsClearDriver.c
MYODBCIns/MYODBCInsLib/MYODBCInsDefaultDataSource.c
MYODBCIns/MYODBCInsLib/MYODBCInsDumpDataSource.c
MYODBCIns/MYODBCInsLib/MYODBCInsDumpDriver.c
MYODBCIns/MYODBCInsLib/MYODBCInsExistsDataSource.c
MYODBCIns/MYODBCInsLib/MYODBCInsFreeDataSource.c
MYODBCIns/MYODBCInsLib/MYODBCInsFreeDriver.c
MYODBCIns/MYODBCInsLib/MYODBCInsGetDataSourceNames.c
MYODBCIns/MYODBCInsLib/MYODBCInsGetDriverNames.c
MYODBCIns/MYODBCInsLib/MYODBCInsInsertStr.c
MYODBCIns/MYODBCInsLib/MYODBCInsReadConnectStr.c
MYODBCIns/MYODBCInsLib/MYODBCInsReadDataSource.c
MYODBCIns/MYODBCInsLib/MYODBCInsReadDataSourceStr.c
MYODBCIns/MYODBCInsLib/MYODBCInsReadDriver.c
MYODBCIns/MYODBCInsLib/MYODBCInsWriteConnectStr.c
MYODBCIns/MYODBCInsLib/MYODBCInsWriteDataSource.c
MYODBCIns/MYODBCInsLib/MYODBCInsWriteDataSourceStr.c
MYODBCIns/MYODBCInsLib/MYODBCInsWriteDriver.c
Modified:
MYODBCIns/MYODBCIns.vpj
MYODBCIns/MYODBCInsLib/MYODBCInsInternal.h
MYODBCIns/MYODBCInsLib/MYODBCInsLib.pro
MYODBCIns/MYODBCInsLib/MYODBCInsLib.vpj
MYODBCIns/include/MYODBCIns.h
root.pro
Log:
UNICODE: certianly need to revisit this to address
cross-platform/cross-locales issues but mostly done
Modified: MYODBCIns/MYODBCIns.vpj
===================================================================
--- MYODBCIns/MYODBCIns.vpj 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCIns.vpj 2005-12-26 20:17:46 UTC (rev 16)
@@ -189,6 +189,9 @@
Name="Header Files"
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if">
<F N="include/MYODBCIns.h"/>
+ <F N="include/MYODBCInsDataSource.h"/>
+ <F N="include/MYODBCInsDriver.h"/>
+ <F N="include/MYODBCInsDriverConnect.h"/>
</Folder>
<Folder
Name="Resource Files"
Added: MYODBCIns/MYODBCInsLib/MYODBCIns.cpp
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCIns.cpp 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCIns.cpp 2005-12-26 20:17:46 UTC (rev 16)
@@ -0,0 +1,32 @@
+/*!
+ \file MYODBCIns.cpp
+ \author Peter Harvey <pharvey@stripped>
+ Copyright (C) MySQL AB 2004-2005, Released under GPL.
+ \version Connector/ODBC v5
+ \date 2005
+ \brief Code to provide abstraction and portability for I/O of ODBC installer
information.
+
+ \license Copyright (C) 2000-2005 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ There are special exceptions to the terms and conditions of the GPL as it
+ is applied to this software. View the full text of the exception in file
+ EXCEPTIONS in the directory of this software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+#include "MYODBCInsInternal.h"
+
+
+
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsAllocDataSource.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsAllocDataSource.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsAllocDataSource.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,34 +0,0 @@
-/* Copyright (C) 2000-2004 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-MYODBC_INS_DATASOURCE *MYODBCInsAllocDataSource( MYODBC_INS_DATASOURCE_MODE nMode )
-{
- MYODBC_INS_DATASOURCE *p = (MYODBC_INS_DATASOURCE*)malloc(
sizeof(MYODBC_INS_DATASOURCE) );
-
- memset( p, 0, sizeof(MYODBC_INS_DATASOURCE) );
- p->nMode = nMode;
- p->nConnect = MYODBC_INS_DATASOURCE_CONNECT_DRIVER;
- p->nPrompt = MYODBC_INS_DATASOURCE_PROMPT_NOPROMPT;
-
- return p;
-}
-
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsAllocDriver.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsAllocDriver.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsAllocDriver.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,31 +0,0 @@
-/* Copyright (C) 2000-2004 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-MYODBC_INS_DRIVER *MYODBCInsAllocDriver()
-{
- MYODBC_INS_DRIVER *p = (MYODBC_INS_DRIVER*)malloc( sizeof(MYODBC_INS_DRIVER) );
-
- memset( p, 0, sizeof(MYODBC_INS_DRIVER) );
-
- return p;
-}
-
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsClearDataSource.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsClearDataSource.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsClearDataSource.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,50 +0,0 @@
-/* Copyright (C) 2000-2004 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-void MYODBCInsClearDataSource( MYODBC_INS_DATASOURCE *pDataSource )
-{
- if ( !pDataSource )
- return;
-
- MYODBCCFree( pDataSource->pszDATABASE );
- pDataSource->pszDATABASE = NULL;
- MYODBCCFree( pDataSource->pszDESCRIPTION );
- pDataSource->pszDESCRIPTION = NULL;
- MYODBCCFree( pDataSource->pszDSN );
- pDataSource->pszDSN = NULL;
- MYODBCCFree( pDataSource->pszOPTION );
- pDataSource->pszDSN = NULL;
- MYODBCCFree( pDataSource->pszPASSWORD );
- pDataSource->pszPASSWORD = NULL;
- MYODBCCFree( pDataSource->pszPORT );
- pDataSource->pszPORT = NULL;
- MYODBCCFree( pDataSource->pszSERVER );
- pDataSource->pszSERVER = NULL;
- MYODBCCFree( pDataSource->pszSOCKET );
- pDataSource->pszSOCKET = NULL;
- MYODBCCFree( pDataSource->pszSTMT );
- pDataSource->pszSTMT = NULL;
- MYODBCCFree( pDataSource->pszUSER );
- pDataSource->pszUSER = NULL;
-}
-
-
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsClearDriver.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsClearDriver.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsClearDriver.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,36 +0,0 @@
-/* Copyright (C) 2000-2004 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-void MYODBCInsClearDriver( MYODBC_INS_DRIVER *pDriver )
-{
- if ( !pDriver )
- return;
-
- MYODBCCFree( pDriver->pszDRIVER );
- pDriver->pszDRIVER = NULL;
- MYODBCCFree( pDriver->pszName );
- pDriver->pszName = NULL;
- MYODBCCFree( pDriver->pszSETUP );
- pDriver->pszSETUP = NULL;
-}
-
-
Added: MYODBCIns/MYODBCInsLib/MYODBCInsDataSource.cpp
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsDataSource.cpp 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsDataSource.cpp 2005-12-26 20:17:46 UTC (rev 16)
@@ -0,0 +1,645 @@
+/*!
+ \file MYODBCInsDataSource.cpp
+ \author Peter Harvey <pharvey@stripped>
+ Copyright (C) MySQL AB 2004-2005, Released under GPL.
+ \version Connector/ODBC v5
+ \date 2005
+ \brief Code to provide abstraction and portability for I/O of ODBC installer
information.
+
+ \license Copyright (C) 2000-2005 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ There are special exceptions to the terms and conditions of the GPL as it
+ is applied to this software. View the full text of the exception in file
+ EXCEPTIONS in the directory of this software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+#include "MYODBCInsInternal.h"
+
+#define MYODBC_INS_ODBCINI_HEADER_SECTION "ODBC Data Sources"
+
+MYODBCInsDataSource::MYODBCInsDataSource( MYODBC_INS_DATASOURCE_MODE nMode )
+{
+ UWORD n = MYODBC_INS_DATASOURCE_SCOPE_BOTH;
+
+ this->nMode = nMode;
+ nScope = MYODBC_INS_DATASOURCE_SCOPE_BOTH;
+ SQLGetConfigMode( &n );
+ nScope = (MYODBC_INS_DATASOURCE_SCOPE)n;
+}
+
+bool MYODBCInsDataSource::setDriverFileName( const QString &stringDriverFileName )
+{
+ this->stringDriverFileName = stringDriverFileName;
+ return true;
+}
+
+bool MYODBCInsDataSource::setDSN( const QString &stringDSN )
+{
+ this->stringDSN = stringDSN;
+ return true;
+}
+
+bool MYODBCInsDataSource::setDRIVER( const QString &stringDRIVER )
+{
+ this->stringDRIVER = stringDRIVER;
+ return true;
+}
+
+bool MYODBCInsDataSource::setDESCRIPTION( const QString &stringDESCRIPTION )
+{
+ this->stringDESCRIPTION = stringDESCRIPTION;
+ return true;
+}
+
+bool MYODBCInsDataSource::setSERVER( const QString &stringSERVER )
+{
+ this->stringSERVER = stringSERVER;
+ return true;
+}
+
+bool MYODBCInsDataSource::setUSER( const QString &stringUSER )
+{
+ this->stringUSER = stringUSER;
+ return true;
+}
+
+bool MYODBCInsDataSource::setPASSWORD( const QString &stringPASSWORD )
+{
+ this->stringPASSWORD = stringPASSWORD;
+ return true;
+}
+
+bool MYODBCInsDataSource::setDATABASE( const QString &stringDATABASE )
+{
+ this->stringDATABASE = stringDATABASE;
+ return true;
+}
+
+bool MYODBCInsDataSource::setPORT( const QString &stringPORT )
+{
+ this->stringPORT = stringPORT;
+ return true;
+}
+
+bool MYODBCInsDataSource::setSOCKET( const QString &stringSOCKET )
+{
+ this->stringSOCKET = stringSOCKET;
+ return true;
+}
+
+bool MYODBCInsDataSource::setSTMT( const QString &stringSTMT )
+{
+ this->stringSTMT = stringSTMT;
+ return true;
+}
+
+bool MYODBCInsDataSource::setOPTION( const QString &stringOPTION )
+{
+ this->stringOPTION = stringOPTION;
+ return true;
+}
+
+bool MYODBCInsDataSource::setMode( MYODBC_INS_DATASOURCE_MODE nMode )
+{
+ this->nMode = nMode;
+ return true;
+}
+
+bool MYODBCInsDataSource::setScope( MYODBC_INS_DATASOURCE_SCOPE nScope )
+{
+ this->nScope = nScope;
+ return true;
+}
+
+QString MYODBCInsDataSource::getDriverFileName()
+{
+ return stringDriverFileName;
+}
+
+QString MYODBCInsDataSource::getDSN()
+{
+ return stringDSN;
+}
+
+QString MYODBCInsDataSource::getDRIVER()
+{
+ return stringDRIVER;
+}
+
+QString MYODBCInsDataSource::getDESCRIPTION()
+{
+ return stringDESCRIPTION;
+}
+
+QString MYODBCInsDataSource::getSERVER()
+{
+ return stringSERVER;
+}
+
+QString MYODBCInsDataSource::getUSER()
+{
+ return stringUSER;
+}
+
+QString MYODBCInsDataSource::getPASSWORD()
+{
+ return stringPASSWORD;
+}
+
+QString MYODBCInsDataSource::getDATABASE()
+{
+ return stringDATABASE;
+}
+
+QString MYODBCInsDataSource::getPORT()
+{
+ return stringPORT;
+}
+
+QString MYODBCInsDataSource::getSOCKET()
+{
+ return stringSOCKET;
+}
+
+QString MYODBCInsDataSource::getSTMT()
+{
+ return stringSTMT;
+}
+
+QString MYODBCInsDataSource::getOPTION()
+{
+ return stringOPTION;
+}
+
+MYODBC_INS_DATASOURCE_MODE MYODBCInsDataSource::getMode()
+{
+ return nMode;
+}
+
+MYODBC_INS_DATASOURCE_SCOPE MYODBCInsDataSource::getScope()
+{
+ return nScope;
+}
+
+QStringList MYODBCInsDataSource::getDataSourceNames( MYODBC_INS_DATASOURCE_SCOPE nScope )
+{
+ char szBuffer[50000];
+ int nChars = 0;
+ int nChar = 0;
+ QStringList stringlistFriendlyNames;
+ QString stringFriendlyName = QString::null;
+ UWORD nScopeToRestore = ODBC_BOTH_DSN;
+
+ if ( !SQLGetConfigMode( &nScopeToRestore ) )
+ return stringlistFriendlyNames;
+
+ SQLSetConfigMode( (UWORD)nScope );
+
+#if defined(WIN32)
+ /*
+ This returns no data as does having a NULL for 1st arg!?
+
+ nChars = SQLGetPrivateProfileString( "ODBC 32 bit Data Sources", NULL, NULL,
pszBuffer, nBuffer - 1, "ODBC.INI" );
+ */
+ /*
+ This returns our data sources but includes "ODBC 32 bit Data Sources" as a data
sources
+ and does not respect config mode. Probably best until we use registery (MS is
getting sloppy
+ in supporting SQLGetPrivateProfileString).
+ */
+ nChars = GetPrivateProfileString( NULL, NULL, NULL, pszBuffer, nBuffer - 1,
"ODBC.INI" );
+#else
+ nChars = SQLGetPrivateProfileString( NULL, NULL, "", szBuffer, sizeof(szBuffer) - 1,
"ODBC.INI" );
+#endif
+ if ( nChars < 1 )
+ goto getDataSourceNamesExit1;
+
+ /*! \warning assumes that we are *not* using wide char :o */
+ for ( nChar = 0; nChar < nChars; nChar++ )
+ {
+ if ( szBuffer[nChar] )
+ {
+ stringFriendlyName += szBuffer[nChar];
+ }
+ else
+ {
+ if ( !stringFriendlyName.isEmpty() )
+ stringlistFriendlyNames += stringFriendlyName;
+ stringFriendlyName = QString::null;
+ /* check for end (double null) in case nChars is invalid */
+ if ( !szBuffer[nChar+1] )
+ break;
+ }
+ }
+
+
+getDataSourceNamesExit1:
+ SQLSetConfigMode( nScopeToRestore );
+
+ return stringlistFriendlyNames;
+}
+
+bool MYODBCInsDataSource::isExistsDataSourceName( const QString
&stringDataSourceName, MYODBC_INS_DATASOURCE_SCOPE nScope )
+{
+ char szSectionNames[SQL_MAX_DSN_LENGTH * MYODBC_INS_MAX_DSN_NAMES];
+ char * pszSectionName;
+ bool bReturn = false;
+ UWORD nScopeToRestore = ODBC_BOTH_DSN;
+
+ if ( !SQLGetConfigMode( &nScopeToRestore ) )
+ return bReturn;
+
+ if ( stringDataSourceName.isEmpty() )
+ return bReturn;
+
+ SQLSetConfigMode( (UWORD)nScope );
+
+ /*!
+ Get all section names. It would seem to be safest to get all sections
+ names and then scan the result for match rather than try to do this
+ with a single call to SQLGetPrivateProfileString() in off-chance that
+ the section name exists with no name/value pairs.
+ */
+
+#if defined(WIN32)
+ /*!
+ \note WIN
+
+ SQLGetPrivateProfileString does not work when NULL for first arg.
+ so we provide first arg and hope that there is at least one
+ attribute (its likley anyway).
+ */
+ if ( SQLGetPrivateProfileString( stringDataSourceName.toLocal8Bit(), NULL, "",
szSectionNames, sizeof( szSectionNames ) - 1, "ODBC.INI" ) > 0 )
+ {
+ bReturn = true;
+ goto isExistsDataSourceNameExit1;
+ }
+ else
+ goto isExistsDataSourceNameExit1;
+#else
+ if ( SQLGetPrivateProfileString( NULL, NULL, "", szSectionNames, sizeof(
szSectionNames ) - 1, "ODBC.INI" ) < 1 )
+ goto isExistsDataSourceNameExit1;
+#endif
+ /*!
+ Scan result and return MYODBC_C_TRUE if we find a match.
+ */
+ pszSectionName = szSectionNames;
+ while( *pszSectionName )
+ {
+ QString stringSectionName( pszSectionName );
+
+ if ( QString::localeAwareCompare( stringSectionName.toUpper(),
stringDataSourceName.toUpper() ) == 0 )
+ {
+ bReturn = true;
+ goto isExistsDataSourceNameExit1;
+ }
+
+ pszSectionName += strlen( pszSectionName ) + 1;
+ }
+
+isExistsDataSourceNameExit1:
+ SQLSetConfigMode( nScopeToRestore );
+
+ return bReturn;
+}
+
+bool MYODBCInsDataSource::doRead( const QString &stringDataSourceName,
MYODBC_INS_DATASOURCE_SCOPE nScope )
+{
+ char szEntryNames[SQL_MAX_DSN_LENGTH * MYODBC_INS_MAX_DSN_NAMES];
+ char * pszEntryName;
+ char szValue[4096];
+ int nChars = 0;
+ UWORD nScopeToRestore = ODBC_BOTH_DSN;
+ bool bReturn = false;
+
+ if ( stringDataSourceName.isEmpty() )
+ return false;
+
+ if ( !SQLGetConfigMode( &nScopeToRestore ) )
+ return false;
+
+ SQLSetConfigMode( (UWORD)nScope );
+
+ *szEntryNames = '\0';
+ if ( ( nChars = SQLGetPrivateProfileString( stringDataSourceName.toLocal8Bit(), NULL,
NULL, szEntryNames, sizeof( szEntryNames ) - 1, "ODBC.INI" ) ) < 1 )
+ goto doReadExit1;
+
+#if defined(WIN32)
+ {
+ int nLen = strlen( szEntryNames );
+
+ /*!
+ \note XP
+
+ Bug in SQLGetPrivateProfileString when mode is ODBC_BOTH_DSN and we
are looking for a system
+ DSN. In this case SQLGetPrivateProfileString will find the system dsn
but return a corrupt
+ list of attributes.
+
+ A corrupt list of attributes can be identified because the first
attribute (if any) will be
+ followed by more than one '\0'.
+
+ The solution is to detect this condition and set mode to
ODBC_SYSTEM_DSN and try again. We
+ also ensure we reset the mode when done - regardless of outcome.
+ */
+ if ( nScope == MYODBC_INS_DATASOURCE_SCOPE_BOTH && nLen < nChars
&& szEntryNames[nLen + 1 ] == '\0' )
+ {
+ *szEntryNames = '\0';
+ SQLSetConfigMode( ODBC_SYSTEM_DSN );
+
+ if ( ( nChars = SQLGetPrivateProfileString( pszDSN, NULL, NULL, szEntryNames,
sizeof( szEntryNames ) - 1, "ODBC.INI" ) ) < 1 )
+ goto doReadExit1;
+ }
+ }
+#endif
+
+ /*!
+ Looks like things are going to work. Lets set DSN.
+ */
+ stringDSN = stringDataSourceName;
+
+ /*!
+ Scan result and return MYODBC_C_TRUE if we find a match.
+ */
+ pszEntryName = szEntryNames;
+ while ( *pszEntryName )
+ {
+ *szValue = '\0';
+#if defined(WIN32)
+ if ( SQLGetPrivateProfileString( stringDataSourceName.toLocal8Bit(),
pszEntryName, NULL, szValue, sizeof( szValue ) - 1, "ODBC.INI" ) > 0 )
+#else
+ if ( SQLGetPrivateProfileString( stringDataSourceName.toLocal8Bit(),
pszEntryName, "", szValue, sizeof( szValue ) - 1, "ODBC.INI" ) > 0 )
+#endif
+ {
+ QString stringEntryName( pszEntryName );
+ QString stringEntryNameUpper = stringEntryName.toUpper();
+ QString stringValue( szValue );
+
+ /*!
+ \internal ODBC Rule
+ (SQLDriverConnect)
+
+ The driver uses any information it retrieves from the system information
+ to augment the information passed to it in the connection string. If the
+ information in the system information duplicates information in the
+ connection string, the driver uses the information in the connection
+ string.
+ */
+ if ( QString::localeAwareCompare( stringEntryNameUpper, "DATABASE" ) == 0 ||
QString::localeAwareCompare( stringEntryNameUpper, "DB" ) == 0 )
+ {
+ if ( stringDATABASE.isNull() )
+ stringDATABASE = szValue;
+ }
+ else if ( QString::localeAwareCompare( stringEntryNameUpper, "DESCRIPTION" )
== 0 || QString::localeAwareCompare( stringEntryNameUpper, "DESC" ) == 0 )
+ {
+ if ( stringDESCRIPTION.isNull() )
+ stringDESCRIPTION = szValue;
+ }
+ else if ( QString::localeAwareCompare( stringEntryNameUpper, "DRIVER" ) == 0
)
+ {
+#if defined(WIN32)
+ if ( stringDriverFileName.isEmpty() )
+ stringDriverFileName = szValue;
+#else
+ if ( *szValue == '/' )
+ {
+ if ( stringDriverFileName.isEmpty() )
+ stringDriverFileName = szValue;
+ }
+ else
+ {
+ if ( stringDRIVER.isEmpty() )
+ stringDRIVER = szValue;
+ }
+#endif
+ }
+ else if ( QString::localeAwareCompare( stringEntryNameUpper, "OPTION" ) == 0
)
+ {
+ if ( stringOPTION.isNull() )
+ stringOPTION = szValue;
+ }
+ else if ( QString::localeAwareCompare( stringEntryNameUpper, "PWD" ) == 0 ||
QString::localeAwareCompare( stringEntryNameUpper, "PASSWORD" ) == 0 )
+ {
+ if ( stringPASSWORD.isNull() )
+ stringPASSWORD = szValue;
+ }
+ else if ( QString::localeAwareCompare( stringEntryNameUpper, "PORT" ) == 0 )
+ {
+ if ( stringPORT.isNull() )
+ stringPORT = szValue;
+ }
+ else if ( QString::localeAwareCompare( stringEntryNameUpper, "SERVER" ) == 0
)
+ {
+ if ( stringSERVER.isNull() )
+ stringSERVER = szValue;
+ }
+ else if ( QString::localeAwareCompare( stringEntryNameUpper, "SOCKET" ) == 0
)
+ {
+ if ( stringSOCKET.isNull() )
+ stringSOCKET = szValue;
+ }
+ else if ( QString::localeAwareCompare( stringEntryNameUpper, "STMT" ) == 0 )
+ {
+ if ( stringSTMT.isNull() )
+ stringSTMT = szValue;
+ }
+ else if ( QString::localeAwareCompare( stringEntryNameUpper, "UID" ) == 0 ||
QString::localeAwareCompare( stringEntryNameUpper, "USER" ) == 0 )
+ {
+ if ( stringUSER.isNull() )
+ stringUSER = szValue;
+ }
+ else
+ {
+ /* What the ? */
+ fprintf( stderr, "[%s][%d][ERROR] Unknown attribute (%s).\n", __FILE__,
__LINE__, pszEntryName );
+ }
+ }
+ else
+ fprintf( stderr, "[%s][%d][WARNING] Failed to get value for attribute
(%s).\n", __FILE__, __LINE__, pszEntryName );
+
+ pszEntryName += strlen( pszEntryName ) + 1;
+ } /* while */
+
+
+ /* try harder to get the friendly driver name */
+ if ( stringDRIVER.isEmpty() )
+ {
+ if ( SQLGetPrivateProfileString( MYODBC_INS_ODBCINI_HEADER_SECTION, NULL, NULL,
szEntryNames, sizeof( szEntryNames ) - 1, "ODBC.INI" ) < 1 )
+ goto doReadExit1;
+
+ pszEntryName = szEntryNames;
+ while ( *pszEntryName )
+ {
+ QString stringEntryName( pszEntryName );
+ *szValue = '\0';
+ if ( SQLGetPrivateProfileString( MYODBC_INS_ODBCINI_HEADER_SECTION,
pszEntryName, NULL, szValue, sizeof( szValue ) - 1, "ODBC.INI" ) > 0 )
+ {
+
+ if ( QString::localeAwareCompare( stringEntryName.toUpper(),
stringDataSourceName.toUpper() ) == 0 )
+ {
+ stringDRIVER = szValue;
+ break;
+ }
+ }
+ pszEntryName += strlen( pszEntryName ) + 1;
+ }
+ }
+
+#if defined(WIN32)
+ /*!
+ XP
+
+ Some people have reported that the friendly driver name is never found so...
+ */
+ if ( stringDRIVER.isEmpty() )
+ stringDRIVER = MYODBCINST_DRIVER_NAME;
+#endif
+ bReturn = true;
+
+doReadExit1:
+ SQLSetConfigMode( nScopeToRestore );
+
+ return bReturn;
+}
+
+bool MYODBCInsDataSource::doRead( const QString &stringDataSourceName )
+{
+ return doRead( stringDataSourceName, nScope );
+}
+
+bool MYODBCInsDataSource::doRead()
+{
+ return doRead( stringDSN, nScope );
+}
+
+bool MYODBCInsDataSource::doWrite( MYODBC_INS_DATASOURCE_SCOPE nScope )
+{
+ bool bReturn = false;
+ UWORD nScopeToRestore = ODBC_BOTH_DSN;
+
+ if ( !SQLGetConfigMode( &nScopeToRestore ) )
+ return false;
+
+ SQLSetConfigMode( (UWORD)nScope );
+
+ /*
+ SQLWriteDSNToIni is *supposed* to replace any existing DSN
+ with same name but fails (at least on unixODBC) to do so.
+ So we ensure that any existing DSN with same name is removed
+ with the following call.
+ */
+ if ( !SQLRemoveDSNFromIni( stringDSN.toLocal8Bit() ) )
+ goto doReadExit1;
+
+ /* create/replace data source name */
+ if ( !SQLWriteDSNToIni( stringDSN.toLocal8Bit(), stringDRIVER.toLocal8Bit() ) )
+ goto doReadExit1;
+
+ /* add details */
+ if ( !stringDATABASE.isNull() &&
+ !SQLWritePrivateProfileString( stringDSN.toLocal8Bit(), "DATABASE",
stringDATABASE.toLocal8Bit(), "odbc.ini" ) )
+ goto doReadExit1;
+ if ( !stringDESCRIPTION.isNull() &&
+ !SQLWritePrivateProfileString( stringDSN.toLocal8Bit(), "DESCRIPTION",
stringDESCRIPTION.toLocal8Bit(), "odbc.ini" ) )
+ goto doReadExit1;
+ if ( !stringOPTION.isNull() &&
+ !SQLWritePrivateProfileString( stringDSN.toLocal8Bit(), "OPTION",
stringOPTION.toLocal8Bit(), "odbc.ini" ) )
+ goto doReadExit1;
+ if ( !stringPASSWORD.isNull() &&
+ !SQLWritePrivateProfileString( stringDSN.toLocal8Bit(), "PWD",
stringPASSWORD.toLocal8Bit(), "odbc.ini" ) )
+ goto doReadExit1;
+ if ( !stringPORT.isNull() &&
+ !SQLWritePrivateProfileString( stringDSN.toLocal8Bit(), "PORT",
stringPORT.toLocal8Bit(), "odbc.ini" ) )
+ goto doReadExit1;
+ if ( !stringSERVER.isNull() &&
+ !SQLWritePrivateProfileString( stringDSN.toLocal8Bit(), "SERVER",
stringSERVER.toLocal8Bit(), "odbc.ini" ) )
+ goto doReadExit1;
+ if ( !stringSOCKET.isNull() &&
+ !SQLWritePrivateProfileString( stringDSN.toLocal8Bit(), "SOCKET",
stringSOCKET.toLocal8Bit(), "odbc.ini" ) )
+ goto doReadExit1;
+ if ( !stringSTMT.isNull() &&
+ !SQLWritePrivateProfileString( stringDSN.toLocal8Bit(), "STMT",
stringSTMT.toLocal8Bit(), "odbc.ini" ) )
+ goto doReadExit1;
+ if ( !stringUSER.isNull() &&
+ !SQLWritePrivateProfileString( stringDSN.toLocal8Bit(), "UID",
stringUSER.toLocal8Bit(), "odbc.ini" ) )
+ goto doReadExit1;
+
+ bReturn = true;
+
+doReadExit1:
+ SQLSetConfigMode( nScopeToRestore );
+
+ return bReturn;
+}
+
+bool MYODBCInsDataSource::doWrite()
+{
+ return doWrite( nScope );
+}
+
+void MYODBCInsDataSource::doClear()
+{
+ /* do not change the nMode nor nScope */
+ stringDATABASE = QString::null;
+ stringDESCRIPTION = QString::null;
+ stringDRIVER = QString::null;
+ stringDriverFileName= QString::null;
+ stringDSN = QString::null;
+ stringOPTION = QString::null;
+ stringPASSWORD = QString::null;
+ stringPORT = QString::null;
+ stringSERVER = QString::null;
+ stringSOCKET = QString::null;
+ stringSTMT = QString::null;
+ stringUSER = QString::null;
+}
+
+MYODBCInsDataSource MYODBCInsDataSource::operator=( MYODBCInsDataSource rval )
+{
+ stringDATABASE = rval.stringDATABASE;
+ stringDESCRIPTION = rval.stringDESCRIPTION;
+ stringDRIVER = rval.stringDRIVER;
+ stringDriverFileName= rval.stringDriverFileName;
+ stringDSN = rval.stringDSN;
+ stringOPTION = rval.stringOPTION;
+ stringPASSWORD = rval.stringPASSWORD;
+ stringPORT = rval.stringPORT;
+ stringSERVER = rval.stringSERVER;
+ stringSOCKET = rval.stringSOCKET;
+ stringSTMT = rval.stringSTMT;
+ stringUSER = rval.stringUSER;
+ nScope = rval.nScope;
+
+ return *this;
+}
+
+QTextStream &operator<<( QTextStream &stream, MYODBCInsDataSource rval )
+{
+ stream << "DATABASE : " << rval.getDATABASE() << endl;
+ stream << "DESCRIPTION : " << rval.getDESCRIPTION() << endl;
+ stream << "DRIVER : " << rval.getDRIVER() << endl;
+ stream << "DriverFileName: " << rval.getDriverFileName() << endl;
+ stream << "DSN : " << rval.getDSN() << endl;
+ stream << "OPTION : " << rval.getOPTION() << endl;
+ stream << "PASSWORD : " << rval.getPASSWORD() << endl;
+ stream << "PORT : " << rval.getPORT() << endl;
+ stream << "SERVER : " << rval.getSERVER() << endl;
+ stream << "SOCKET : " << rval.getSOCKET() << endl;
+ stream << "STMT : " << rval.getSTMT() << endl;
+ stream << "USER : " << rval.getUSER() << endl;
+
+ return stream;
+}
+
+
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsDefaultDataSource.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsDefaultDataSource.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsDefaultDataSource.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,66 +0,0 @@
-/* Copyright (C) 2000-2005 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-MYODBC_C_BOOL MYODBCInsDefaultDataSource( MYODBC_INS_DATASOURCE *pDataSource )
-{
- if ( pDataSource->pszSERVER && !pDataSource->pszSERVER[0] )
- {
- MYODBCCFree( pDataSource->pszSERVER );
- pDataSource->pszSERVER = NULL;
- }
-
- if ( pDataSource->pszDATABASE && !pDataSource->pszDATABASE[0] )
- {
- MYODBCCFree( pDataSource->pszDATABASE );
- pDataSource->pszDATABASE = NULL;
- }
-
- if ( pDataSource->pszUSER && !pDataSource->pszUSER[0] )
- {
- MYODBCCFree( pDataSource->pszUSER );
- pDataSource->pszUSER = NULL;
- }
-
- if ( pDataSource->pszPASSWORD && !pDataSource->pszPASSWORD[0] )
- {
- MYODBCCFree( pDataSource->pszPASSWORD );
- pDataSource->pszPASSWORD = NULL;
- }
-
- if ( !pDataSource->pszPORT )
- pDataSource->pszPORT = MYODBCCStrDup( "0", SQL_NTS );
-
- if ( !pDataSource->pszOPTION )
- pDataSource->pszOPTION = MYODBCCStrDup( "0", SQL_NTS );
-
-#ifndef _UNIX_
- /* Here we actually unset socket for non-UNIX as it does not apply. */
- if ( pDataSource->pszSOCKET )
- {
- MYODBCCFree( pDataSource->pszSOCKET );
- pDataSource->pszSOCKET = NULL;
- }
-#endif
-
- return MYODBC_C_TRUE;
-}
-
Added: MYODBCIns/MYODBCInsLib/MYODBCInsDriver.cpp
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsDriver.cpp 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsDriver.cpp 2005-12-26 20:17:46 UTC (rev 16)
@@ -0,0 +1,216 @@
+/*!
+ \file MYODBCInsDriver.cpp
+ \author Peter Harvey <pharvey@stripped>
+ Copyright (C) MySQL AB 2004-2005, Released under GPL.
+ \version Connector/ODBC v5
+ \date 2005
+ \brief Code to provide abstraction and portability for I/O of ODBC installer
information.
+
+ \license Copyright (C) 2000-2005 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ There are special exceptions to the terms and conditions of the GPL as it
+ is applied to this software. View the full text of the exception in file
+ EXCEPTIONS in the directory of this software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+#include "MYODBCInsInternal.h"
+
+
+bool MYODBCInsDriver::setFriendlyName( const QString &stringFriendlyName )
+{
+ this->stringFriendlyName = stringFriendlyName;
+ return true;
+}
+
+bool MYODBCInsDriver::setDRIVER( const QString &stringDriverFileName )
+{
+ stringDRIVER = stringDriverFileName;
+ return true;
+}
+
+bool MYODBCInsDriver::setSETUP( const QString &stringSetupFileName )
+{
+ stringSETUP = stringSetupFileName;
+ return true;
+}
+
+QString MYODBCInsDriver::getFriendlyName()
+{
+ return stringFriendlyName;
+}
+
+QString MYODBCInsDriver::getDRIVER()
+{
+ return stringDRIVER;
+}
+
+QString MYODBCInsDriver::getSETUP()
+{
+ return stringSETUP;
+}
+
+/*!
+ \internal
+ \brief Get a list of installed drivers.
+
+ \note XP
+
+ SQLGetPrivateProfileString() with a NULL 1st arg does
+ not return anything - ever. To return a list of drivers
+ we can use SQLGetInstalledDrivers() instead.
+
+ \param
+
+ \returns
+*/
+QStringList MYODBCInsDriver::getDriverNames()
+{
+ char szBuffer[50000];
+ int nChars = 0;
+ int nChar = 0;
+ QStringList stringlistFriendlyNames;
+ QString stringFriendlyName = QString::null;
+
+#if defined(WIN32)
+ nChars = ( SQLGetInstalledDrivers( szBuffer, sizeof(szBuffer) - 1, NULL ) ? 1 : 0 );
+#else
+ nChars = SQLGetPrivateProfileString( NULL, NULL, "", szBuffer, sizeof(szBuffer) - 1,
"ODBCINST.INI" );
+#endif
+ if ( nChars < 1 )
+ {
+ fprintf( stderr, "[%s][%d][INFO] Call returned no data. Could be an error or just
no data to return.\n", __FILE__, __LINE__ );
+ return stringlistFriendlyNames;
+ }
+
+ /*! \warning assumes that we are *not* using wide char :o */
+ for ( nChar = 0; nChar < nChars; nChar++ )
+ {
+ if ( szBuffer[nChar] )
+ {
+ stringFriendlyName += szBuffer[nChar];
+ }
+ else
+ {
+ if ( !stringFriendlyName.isEmpty() )
+ stringlistFriendlyNames += stringFriendlyName;
+ stringFriendlyName = QString::null;
+ /* check for end (double null) in case nChars is invalid */
+ if ( !szBuffer[nChar+1] )
+ break;
+ }
+ }
+
+ return stringlistFriendlyNames;
+}
+
+bool MYODBCInsDriver::doRead( const QString &stringFriendlyName )
+{
+ char szEntryNames[SQL_MAX_DSN_LENGTH * MYODBC_INS_MAX_DSN_NAMES];
+ char * pszEntryName;
+ char szValue[4096];
+
+ if ( stringFriendlyName.isEmpty() )
+ return false;
+
+ if ( SQLGetPrivateProfileString( stringFriendlyName.toLocal8Bit(), NULL, "",
szEntryNames, sizeof( szEntryNames ) - 1, "ODBCINST.INI" ) < 1 )
+ return false;
+
+ /* we do not do a doClear() here because we want to 'merge' the data - not replace it
*/
+
+ /* commit ourselves to getting the data */
+ this->stringFriendlyName = stringFriendlyName;
+
+ /*!
+ Scan result and return 'true' if we find a match.
+ */
+ pszEntryName = szEntryNames;
+ while ( *pszEntryName )
+ {
+ *szValue = '\0';
+ if ( SQLGetPrivateProfileString( stringFriendlyName.toLocal8Bit(), pszEntryName,
"", szValue, sizeof( szValue ) - 1, "ODBCINST.INI" ) > 0 )
+ {
+ QString stringEntryName( pszEntryName );
+
+ if ( QString::localeAwareCompare( stringEntryName.toUpper(), "DRIVER" ) == 0
)
+ {
+ if ( stringDRIVER.isEmpty() )
+ stringDRIVER = szValue;
+ }
+ else if ( QString::localeAwareCompare( stringEntryName.toUpper(), "SETUP" )
== 0 )
+ {
+ if ( stringSETUP.isEmpty() )
+ stringSETUP = szValue;
+ }
+ else
+ {
+ /* What the ? */
+ }
+ }
+ pszEntryName += strlen( pszEntryName ) + 1;
+ } /* while */
+
+ return true;
+}
+
+bool MYODBCInsDriver::doWrite()
+{
+ if ( !stringFriendlyName.isEmpty() &&
+ !SQLWritePrivateProfileString( stringFriendlyName.toLocal8Bit(), NULL, NULL,
"ODBCINST.INI" ) )
+ return false;
+ if ( !stringDRIVER.isEmpty() &&
+ !SQLWritePrivateProfileString( stringFriendlyName.toLocal8Bit(), "DRIVER",
stringDRIVER.toLocal8Bit(), "ODBCINST.INI" ) )
+ return false;
+ if ( !stringSETUP.isEmpty() &&
+ !SQLWritePrivateProfileString( stringFriendlyName.toLocal8Bit(), "SETUP",
stringSETUP.toLocal8Bit(), "ODBCINST.INI" ) )
+ return false;
+
+ return true;
+}
+
+void MYODBCInsDriver::doClear()
+{
+ stringFriendlyName = QString::null;
+ stringDRIVER = QString::null;
+ stringSETUP = QString::null;
+}
+
+MYODBCInsDriver MYODBCInsDriver::operator=( MYODBCInsDriver rval )
+{
+ stringFriendlyName = rval.stringFriendlyName;
+ stringDRIVER = rval.stringDRIVER;
+ stringSETUP = rval.stringSETUP;
+
+ return *this;
+}
+
+/*!
+ \internal
+ \brief Dumps the contents to stdout.
+
+ This is useful for debugging.
+
+ \param pDriver A pointer to a valid MYODBC_INS_DRIVER (may be null).
+*/
+QTextStream &operator<<( QTextStream &stream, MYODBCInsDriver rval )
+{
+ stream << "FriendlyName: " << rval.getFriendlyName() << endl;
+ stream << "DRIVER : " << rval.getDRIVER() << endl;
+ stream << "SETUP : " << rval.getSETUP() << endl;
+
+ return stream;
+}
+
+
Added: MYODBCIns/MYODBCInsLib/MYODBCInsDriverConnect.cpp
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsDriverConnect.cpp 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsDriverConnect.cpp 2005-12-26 20:17:46 UTC (rev 16)
@@ -0,0 +1,321 @@
+/*!
+ \file MYODBCInsDriverConnect.cpp
+ \author Peter Harvey <pharvey@stripped>
+ Copyright (C) MySQL AB 2004-2005, Released under GPL.
+ \version Connector/ODBC v5
+ \date 2005
+ \brief Code to provide abstraction and portability for I/O of ODBC installer
information.
+
+ \license Copyright (C) 2000-2005 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ There are special exceptions to the terms and conditions of the GPL as it
+ is applied to this software. View the full text of the exception in file
+ EXCEPTIONS in the directory of this software distribution.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+#include "MYODBCInsInternal.h"
+
+MYODBCInsDriverConnect::MYODBCInsDriverConnect( MYODBC_INS_DRIVERCONNECT_METHOD
nConnectMethod, MYODBC_INS_DRIVERCONNECT_PROMPT nPrompt )
+ : MYODBCInsDataSource( MYODBC_INS_DATASOURCE_MODE_CONNECT )
+{
+ this->nConnectMethod = nConnectMethod;
+ this->nPrompt = nPrompt;
+}
+
+bool MYODBCInsDriverConnect::setConnectString( const QString &stringConnectString )
+{
+ MYODBC_INS_ATTR_PARSE_STATE nState = MYODBC_INS_ATTR_PARSE_STATE_NAME_START;
+ int nAnchorChar = 0;
+ int nScanChar = 0;
+ QString stringName;
+
+ /* short circuit if we have not been given stuff to parse */
+ if ( stringConnectString.isEmpty() )
+ return false;
+
+ /* scan the input */
+ while ( 1 )
+ {
+ switch ( nState )
+ {
+ case MYODBC_INS_ATTR_PARSE_STATE_NAME_START:
+ {
+ if ( stringConnectString[nScanChar].isLetter() ||
stringConnectString[nScanChar] == QChar( '{' ) )
+ {
+ nAnchorChar = nScanChar;
+ nState = MYODBC_INS_ATTR_PARSE_STATE_NAME;
+ }
+ }
+ break;
+ case MYODBC_INS_ATTR_PARSE_STATE_NAME:
+ {
+ if ( (!stringConnectString[nScanChar].isLetter() &&
!stringConnectString[nScanChar].isDigit() && stringConnectString[nScanChar] !=
QChar( '}' )) || stringConnectString[nScanChar] == QChar( '=' ) )
+ {
+ stringName = stringConnectString.mid( nAnchorChar, nScanChar -
nAnchorChar );
+
+ if ( stringConnectString[nScanChar] == QChar( '=' ) )
+ nState = MYODBC_INS_ATTR_PARSE_STATE_VALUE_START;
+ else
+ nState = MYODBC_INS_ATTR_PARSE_STATE_EQUAL;
+ }
+ }
+ break;
+ case MYODBC_INS_ATTR_PARSE_STATE_EQUAL:
+ {
+ if ( stringConnectString[nScanChar] == QChar( '=' ) )
+ nState = MYODBC_INS_ATTR_PARSE_STATE_VALUE_START;
+ }
+ break;
+ case MYODBC_INS_ATTR_PARSE_STATE_VALUE_START:
+ {
+ if ( !stringConnectString[nScanChar].isSpace() )
+ {
+ nAnchorChar = nScanChar;
+ nState = MYODBC_INS_ATTR_PARSE_STATE_VALUE;
+ }
+ }
+ break;
+ case MYODBC_INS_ATTR_PARSE_STATE_VALUE:
+ {
+ /*
+ \internal ODBC Rule
+
+ If any keywords are repeated in the connection string, the driver
uses the value
+ associated with the first occurrence of the keyword. If the DSN
and DRIVER keywords
+ are included in the same connection string, the Driver Manager
and the driver use
+ whichever keyword appears first.
+ */
+
+ /* ';' terminates name/value but we may not find one for last */
+ if ( stringConnectString[nScanChar] == QChar( ';' ) || nScanChar ==
stringConnectString.length() )
+ {
+ if ( stringName.localeAwareCompare( "DATABASE" ) == 0 ||
stringName.localeAwareCompare( "DB" ) == 0 )
+ {
+ if ( stringDATABASE.isNull() )
+ stringDATABASE = stringConnectString.mid( nAnchorChar,
nScanChar - nAnchorChar );
+ }
+ else if ( stringName.localeAwareCompare( "DESCRIPTION" ) == 0 ||
stringName.localeAwareCompare( "DESC" ) == 0 )
+ {
+ if ( stringDESCRIPTION.isNull() )
+ stringDESCRIPTION = stringConnectString.mid( nAnchorChar,
nScanChar - nAnchorChar );
+ }
+ else if ( stringName.localeAwareCompare( "DRIVER" ) == 0 )
+ {
+ if ( stringDRIVER.isEmpty() && stringDSN.isEmpty() )
/* we use one or other - whichever comes 1st */
+ {
+ stringDRIVER = stringConnectString.mid( nAnchorChar,
nScanChar - nAnchorChar ); /* friendly name such as; "MySQL ODBC 3.51 Driver" */
+ nConnectMethod = MYODBC_INS_DRIVERCONNECT_METHOD_DRIVER;
+ }
+ }
+ else if ( stringName.localeAwareCompare( "DSN" ) == 0 )
+ {
+ if ( stringDSN.isEmpty() && stringDRIVER.isEmpty() )
/* we use one or other - whichever comes 1st */
+ {
+ stringDSN = stringConnectString.mid( nAnchorChar,
nScanChar - nAnchorChar );
+ nConnectMethod = MYODBC_INS_DRIVERCONNECT_METHOD_DSN;
+ }
+ }
+ else if ( stringName.localeAwareCompare( "OPTION" ) == 0 )
+ {
+ if ( stringOPTION.isNull() )
+ stringOPTION = stringConnectString.mid( nAnchorChar,
nScanChar - nAnchorChar );
+ }
+ /*
+ \internal MYODBC Rule
+
+ We will 'read' variants on the standard keywords (but only
write standard version).
+ */
+ else if ( stringName.localeAwareCompare( "PWD" ) == 0 ||
stringName.localeAwareCompare( "PASSWORD" ) == 0 )
+ {
+ if ( stringPASSWORD.isNull() )
+ stringPASSWORD = stringConnectString.mid( nAnchorChar,
nScanChar - nAnchorChar );
+ }
+ else if ( stringName.localeAwareCompare( "PORT" ) == 0 )
+ {
+ if ( stringPORT.isNull() )
+ stringPORT = stringConnectString.mid( nAnchorChar,
nScanChar - nAnchorChar );
+ }
+ else if ( stringName.localeAwareCompare( "SERVER" ) == 0 )
+ {
+ if ( stringSERVER.isNull() )
+ stringSERVER = stringConnectString.mid( nAnchorChar,
nScanChar - nAnchorChar );
+ }
+ else if ( stringName.localeAwareCompare( "SOCKET" ) == 0 )
+ {
+ if ( stringSOCKET.isNull() )
+ stringSOCKET = stringConnectString.mid( nAnchorChar,
nScanChar - nAnchorChar );
+ }
+ else if ( stringName.localeAwareCompare( "STMT" ) == 0 )
+ {
+ if ( stringSTMT.isNull() )
+ stringSTMT = stringConnectString.mid( nAnchorChar,
nScanChar - nAnchorChar );
+ }
+ /*
+ \internal MYODBC Rule
+
+ We will 'read' variants on the standard keywords (but only
write standard version).
+ */
+ else if ( stringName.localeAwareCompare( "UID" ) == 0 ||
stringName.localeAwareCompare( "USER" ) == 0 )
+ {
+ if ( stringUSER.isNull() )
+ stringUSER = stringConnectString.mid( nAnchorChar,
nScanChar - nAnchorChar );
+ }
+ else
+ {
+ /* What the ? */
+ }
+
+ stringName = QString::null;
+ }
+ }
+ break;
+ default:
+ fprintf( stderr, "[%s][%d][ERROR] Unhandled state.\n", __FILE__, __LINE__
);
+ return false;
+ }
+
+ /* ';' is used to terminate a name/value pair */
+ if ( stringConnectString[nScanChar] == QChar( ';' ) )
+ nState = MYODBC_INS_ATTR_PARSE_STATE_NAME_START;
+
+ /* have we advanced to end of string */
+ if ( nScanChar == stringConnectString.length() )
+ break;
+
+ nScanChar++;
+
+ } /* while scan */
+
+ return true;
+}
+
+bool MYODBCInsDriverConnect::setConnectMethod( MYODBC_INS_DRIVERCONNECT_METHOD
nConnectMethod )
+{
+ this->nConnectMethod = nConnectMethod;
+ return true;
+}
+
+bool MYODBCInsDriverConnect::setPrompt( MYODBC_INS_DRIVERCONNECT_PROMPT nPrompt )
+{
+ this->nPrompt = nPrompt;
+ return true;
+}
+
+QString MYODBCInsDriverConnect::getConnectString()
+{
+ QString stringConnect;
+
+ if ( !stringDATABASE.isNull() )
+ {
+ stringConnect += "DATABASE=";
+ stringConnect += stringDATABASE;
+ }
+
+ if ( !stringDESCRIPTION.isNull() )
+ {
+ if ( !stringConnect.isEmpty() )
+ stringConnect += QChar( ';' );
+ stringConnect += "DESCRIPTION=";
+ stringConnect += stringDATABASE;
+ }
+
+ if ( nConnectMethod == MYODBC_INS_DRIVERCONNECT_METHOD_DRIVER )
+ {
+ if ( !stringConnect.isEmpty() )
+ stringConnect += QChar( ';' );
+ stringConnect += "DRIVER=";
+ stringConnect += stringDRIVER;
+ }
+
+ if ( nConnectMethod == MYODBC_INS_DRIVERCONNECT_METHOD_DSN )
+ {
+ if ( !stringConnect.isEmpty() )
+ stringConnect += QChar( ';' );
+ stringConnect += "DSN=";
+ stringConnect += stringDSN;
+ }
+
+ if ( !stringOPTION.isNull() )
+ {
+ if ( !stringConnect.isEmpty() )
+ stringConnect += QChar( ';' );
+ stringConnect += "OPTION=";
+ stringConnect += stringOPTION;
+ }
+
+ if ( !stringPASSWORD.isNull() )
+ {
+ if ( !stringConnect.isEmpty() )
+ stringConnect += QChar( ';' );
+ stringConnect += "PWD=";
+ stringConnect += stringPASSWORD;
+ }
+
+ if ( !stringPORT.isNull() )
+ {
+ if ( !stringConnect.isEmpty() )
+ stringConnect += QChar( ';' );
+ stringConnect += "PORT=";
+ stringConnect += stringPORT;
+ }
+
+ if ( !stringSERVER.isNull() )
+ {
+ if ( !stringConnect.isEmpty() )
+ stringConnect += QChar( ';' );
+ stringConnect += "SERVER=";
+ stringConnect += stringSERVER;
+ }
+
+ if ( !stringSOCKET.isNull() )
+ {
+ if ( !stringConnect.isEmpty() )
+ stringConnect += QChar( ';' );
+ stringConnect += "SOCKET=";
+ stringConnect += stringSOCKET;
+ }
+
+ if ( !stringSTMT.isNull() )
+ {
+ if ( !stringConnect.isEmpty() )
+ stringConnect += QChar( ';' );
+ stringConnect += "STMT=";
+ stringConnect += stringSTMT;
+ }
+
+ if ( !stringUSER.isNull() )
+ {
+ if ( !stringConnect.isEmpty() )
+ stringConnect += QChar( ';' );
+ stringConnect += "UID=";
+ stringConnect += stringUSER;
+ }
+
+ return stringConnect;
+}
+
+MYODBC_INS_DRIVERCONNECT_METHOD MYODBCInsDriverConnect::getConnectMethod()
+{
+ return nConnectMethod;
+}
+
+MYODBC_INS_DRIVERCONNECT_PROMPT MYODBCInsDriverConnect::getPrompt()
+{
+ return nPrompt;
+}
+
+
+
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsDumpDataSource.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsDumpDataSource.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsDumpDataSource.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,37 +0,0 @@
-/*!
- \internal
- \file MYODBCInsDumpDataSource.c
- \author Peter Harvey <pharvey@stripped>
- Copyright MySQL AB 2004-2005 Released under GPL.
- \version Connector/ODBC v5
- \date 2005
- \brief This code is used to support installer.
-*/
-
-#include "MYODBCInsInternal.h"
-
-void MYODBCInsDumpDataSource( MYODBC_INS_DATASOURCE_PTR pDataSource )
-{
- printf( "[%s][%d] MYODBC_INS_DATASOURCE (%p)\n", __FILE__, __LINE__, pDataSource );
- if ( pDataSource )
- {
- printf( "\tnConnect = %d\n", pDataSource->nConnect );
- printf( "\tnMode = %d\n", pDataSource->nMode );
- printf( "\tnPrompt = %d\n", pDataSource->nPrompt );
- printf( "\tpszDATABASE = %s\n", pDataSource->pszDATABASE );
- printf( "\tpszDESCRIPTION = %s\n", pDataSource->pszDESCRIPTION );
- printf( "\tpszDRIVER = %s\n", pDataSource->pszDRIVER );
- printf( "\tpszDriverFileName = %s\n", pDataSource->pszDriverFileName );
- printf( "\tpszDSN = %s\n", pDataSource->pszDSN );
- printf( "\tpszOPTION = %s\n", pDataSource->pszOPTION );
- printf( "\tpszPASSWORD = %s\n", pDataSource->pszPASSWORD );
- printf( "\tpszPORT = %s\n", pDataSource->pszPORT );
- printf( "\tpszSERVER = %s\n", pDataSource->pszSERVER );
- printf( "\tpszSOCKET = %s\n", pDataSource->pszSOCKET );
- printf( "\tpszSTMT = %s\n", pDataSource->pszSTMT );
- printf( "\tpszUSER = %s\n", pDataSource->pszUSER );
- }
-}
-
-
-
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsDumpDriver.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsDumpDriver.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsDumpDriver.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,25 +0,0 @@
-/*!
- \internal
- \file MYODBCInsDumpDriver.c
- \author Peter Harvey <pharvey@stripped>
- Copyright MySQL AB 2004-2005 Released under GPL.
- \version Connector/ODBC v5
- \date 2005
- \brief This code is used to support installer.
-*/
-
-#include "MYODBCInsInternal.h"
-
-void MYODBCInsDumpDriver( MYODBC_INS_DRIVER_PTR pDriver )
-{
- printf( "[%s][%d] MYODBC_INS_DRIVER (%p)\n", __FILE__, __LINE__, pDriver );
- if ( pDriver )
- {
- printf( "\tpszDRIVER = %s\n", pDriver->pszDRIVER );
- printf( "\tpszName = %s\n", pDriver->pszName );
- printf( "\tpszSETUP = %s\n", pDriver->pszSETUP );
- }
-}
-
-
-
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsExistsDataSource.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsExistsDataSource.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsExistsDataSource.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,81 +0,0 @@
-/* Copyright (C) 2000-2004 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-MYODBC_C_BOOL MYODBCInsDSNExists( char *pszDataSourceName )
-{
- char szSectionNames[SQL_MAX_DSN_LENGTH * MYODBC_INS_MAX_DSN_NAMES];
- char * pszSectionName;
-
- if ( !pszDataSourceName || !(*pszDataSourceName) )
- return MYODBC_C_FALSE;
-
- /*!
- Get all section names. It would seem to be safest to get all sections
- names and then scan the result for match rather than try to do this
- with a single call to SQLGetPrivateProfileString() in off-chance that
- the section name exists with no name/value pairs.
- */
-
-#if defined(WIN32)
- /*!
- \note WIN
-
- SQLGetPrivateProfileString does not work when NULL for first arg.
- so we provide first arg and hope that there is at least one
- attribute (its likley anyway).
- */
- if ( SQLGetPrivateProfileString( pszDataSourceName, NULL, "", szSectionNames, sizeof(
szSectionNames ) - 1, "ODBC.INI" ) > 0 )
- return MYODBC_C_TRUE;
- else
-#elif defined(__OSX__)
- /*!
- \note OSX
-
- SQLGetPrivateProfileString is the proper call and is available - but
- at this time it appears utterly broken. So we call an alternative
- instead.
- */
- if ( GetPrivateProfileString( NULL, NULL, NULL, szSectionNames, sizeof(
szSectionNames ) - 1, "ODBC.INI" ) < 1 )
-#else
- if ( SQLGetPrivateProfileString( NULL, NULL, "", szSectionNames, sizeof(
szSectionNames ) - 1, "ODBC.INI" ) < 1 )
-#endif
- {
- /*! oops - we take easy way out and just say we did not find it */
- return MYODBC_C_FALSE;
- }
-
- /*!
- Scan result and return MYODBC_C_TRUE if we find a match.
- */
- pszSectionName = szSectionNames;
- while( *pszSectionName )
- {
- if ( MYODBCCStrCaseCmp( pszDataSourceName, pszSectionName ) == 0 )
- return MYODBC_C_TRUE;
- pszSectionName += strlen( pszSectionName ) + 1;
- }
-
- return MYODBC_C_FALSE;
-}
-
-
-
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsFreeDataSource.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsFreeDataSource.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsFreeDataSource.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,35 +0,0 @@
-/* Copyright (C) 2000-2004 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-void MYODBCInsFreeDataSource( MYODBC_INS_DATASOURCE *pDataSource )
-{
- if ( !pDataSource )
- return;
-
- MYODBCInsClearDataSource( pDataSource );
- MYODBCCFree( pDataSource->pszDriverFileName );
- MYODBCCFree( pDataSource->pszDRIVER );
-
- MYODBCCFree( pDataSource );
-}
-
-
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsFreeDriver.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsFreeDriver.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsFreeDriver.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,33 +0,0 @@
-/* Copyright (C) 2000-2004 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-void MYODBCInsFreeDriver( MYODBC_INS_DRIVER *pDriver )
-{
- if ( !pDriver )
- return;
-
- MYODBCInsClearDriver( pDriver );
-
- MYODBCCFree( pDriver );
-}
-
-
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsGetDataSourceNames.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsGetDataSourceNames.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsGetDataSourceNames.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,89 +0,0 @@
-/* Copyright (C) 2000-2005 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-MYODBC_C_BOOL MYODBCInsGetDataSourceNames( char *pszBuffer, int nBuffer, UWORD nScope )
-{
- int nChars = 0;
-
- /*
- sanity check
- */
- if ( !pszBuffer || nBuffer < 1024 )
- {
- fprintf( stderr, "[%s][%d][ERROR] Insufficient buffer size. Please provide 1k or
better yet - 32k.\n", __FILE__, __LINE__ );
- return MYODBC_C_FALSE;
- }
-
- /* set scope */
- switch ( nScope )
- {
- case ODBC_BOTH_DSN:
- break;
- case ODBC_USER_DSN:
- case ODBC_SYSTEM_DSN:
- if ( !SQLSetConfigMode( nScope ) )
- return MYODBC_C_FALSE;
- break;
- default:
- return MYODBC_C_FALSE;
- }
-
-#if defined(__APPLE__)
- nChars = GetPrivateProfileString( NULL, NULL, "", pszBuffer, nBuffer - 1, "ODBC.INI"
);
-#elif defined(WIN32)
- /*
- This returns no data as does having a NULL for 1st arg!?
-
- nChars = SQLGetPrivateProfileString( "ODBC 32 bit Data Sources", NULL, NULL,
pszBuffer, nBuffer - 1, "ODBC.INI" );
- */
- /*
- This returns our data sources but includes "ODBC 32 bit Data Sources" as a data
sources
- and does not respect config mode. Probably best until we use registery (MS is
getting sloppy
- in supporting SQLGetPrivateProfileString).
- */
- nChars = GetPrivateProfileString( NULL, NULL, NULL, pszBuffer, nBuffer - 1,
"ODBC.INI" );
-#else
- nChars = SQLGetPrivateProfileString( NULL, NULL, "", pszBuffer, nBuffer - 1,
"ODBC.INI" );
-#endif
-
- /* unset scope */
- switch ( nScope )
- {
- case ODBC_BOTH_DSN:
- break;
- case ODBC_USER_DSN:
- case ODBC_SYSTEM_DSN:
- SQLSetConfigMode( ODBC_BOTH_DSN );
- break;
- }
-
- if ( nChars < 1 )
- {
- fprintf( stderr, "[%s][%d][INFO] Call returned no data. Could be an error or just
no data to return.\n", __FILE__, __LINE__ );
- return MYODBC_C_FALSE;
- }
-
- return MYODBC_C_TRUE;
-}
-
-
-
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsGetDriverNames.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsGetDriverNames.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsGetDriverNames.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,66 +0,0 @@
-/* Copyright (C) 2000-2005 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-/*!
- \internal
- \brief Put a list of installed drivers in pszBuffer.
-
- \note OSX
-
- SQLGetPrivateProfileString() is broken but fortunately
- the old GetPrivateProfileString() is available.
-
- \note XP
-
- SQLGetPrivateProfileString() with a NULL 1st arg does
- not return anything - ever. To return a list of drivers
- we can use SQLGetInstalledDrivers() instead.
-*/
-MYODBC_C_BOOL MYODBCInsGetDriverNames( char *pszBuffer, int nBuffer )
-{
- int nChars = 0;
-
- /*
- sanity check
- */
- if ( !pszBuffer || nBuffer < 1024 )
- {
- fprintf( stderr, "[%s][%d][ERROR] Insufficient buffer size. Please provide 1k or
better yet - 32k.\n", __FILE__, __LINE__ );
- return MYODBC_C_FALSE;
- }
-
-
-#if defined(__APPLE__)
- nChars = GetPrivateProfileString( NULL, NULL, "", pszBuffer, nBuffer - 1,
"ODBCINST.INI" );
-#elif defined(WIN32)
- nChars = ( SQLGetInstalledDrivers( pszBuffer, nBuffer - 1, NULL ) ? 1 : 0 );
-#else
- nChars = SQLGetPrivateProfileString( NULL, NULL, "", pszBuffer, nBuffer - 1,
"ODBCINST.INI" );
-#endif
- if ( nChars < 1 )
- {
- fprintf( stderr, "[%s][%d][INFO] Call returned no data. Could be an error or just
no data to return.\n", __FILE__, __LINE__ );
- return MYODBC_C_FALSE;
- }
-
- return MYODBC_C_TRUE;
-}
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsInsertStr.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsInsertStr.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsInsertStr.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,35 +0,0 @@
-/* Copyright (C) 2000-2004 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-MYODBC_C_BOOL MYODBCInsInsertStr( char *pszStr, LPCSTR pszStrIn, SQLSMALLINT nMaxLen, int
*pnIndex )
-{
- int nStrInLen = strlen( pszStrIn );
-
- if ( (*pnIndex + nStrInLen + 1) > nMaxLen )
- return MYODBC_C_FALSE;
-
- strcpy( &(pszStr[(*pnIndex)]), pszStrIn );
- *pnIndex += nStrInLen;
-
- return MYODBC_C_TRUE;
-}
-
Modified: MYODBCIns/MYODBCInsLib/MYODBCInsInternal.h
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsInternal.h 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsInternal.h 2005-12-26 20:17:46 UTC (rev 16)
@@ -27,74 +27,6 @@
} MYODBC_INS_ATTR_PARSE_STATE;
-#ifdef __cplusplus
-extern "C" {
#endif
-#ifdef __APPLE__
-int GetPrivateProfileString( LPCSTR lpszSection, LPCSTR lpszEntry, LPCSTR lpszDefault,
LPSTR lpszRetBuffer, int cbRetBuffer, LPCSTR lpszFilename );
-#endif
-/*!
- \internal
- \brief Dumps the contents to stdout.
-
- This is useful for debugging.
-
- \param pDataSource A pointer to a valid MYODBC_INS_DATASOURCE (may be null).
-*/
-void MYODBCInsDumpDataSource( MYODBC_INS_DATASOURCE_PTR pDataSource );
-
-/*!
- \internal
- \brief Dumps the contents to stdout.
-
- This is useful for debugging.
-
- \param pDriver A pointer to a valid MYODBC_INS_DRIVER (may be null).
-*/
-void MYODBCInsDumpDriver( MYODBC_INS_DRIVER_PTR pDriver );
-
-/*!
- \internal
- \brief Inserts pszStrIn into pszStr at pnIndex.
-
- This is used to build the outgoing connection string for
- SQLDriverConnect().
-
- \param pszStr Destination string.
- \param pszStrIn Source string.
- \param nMaxLen Max length to insert.
- \param pnIndex Starting position in source string.
-
- \return MYODBC_C_TRUE Upon success.
- MYODBC_C_FALSE Upon failure.
-*/
-MYODBC_C_BOOL MYODBCInsInsertStr( char *pszStr, LPCSTR pszStrIn, SQLSMALLINT nMaxLen, int
*pnIndex );
-
-/*!
- \internal
- \brief Formulates a connection string reflecting any user modifications.
-
- The string can be used to pass back to SQLDriverConnect.
-
- \param pDataSource A pointer to a viable
- \param nDelim
- \param pszStr
- \param nMaxLen
-
- \return MYODBC_C_TRUE Upon success.
- MYODBC_C_FALSE Upon failure.
-
- \sa MYODBCInsReadDataSourceStr
-*/
-MYODBC_C_BOOL MYODBCInsWriteDataSourceStr( MYODBC_INS_DATASOURCE *pDataSource,
MYODBC_INS_DELIM nDelim, char *pszStr, SQLSMALLINT nMaxLen );
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-
Modified: MYODBCIns/MYODBCInsLib/MYODBCInsLib.pro
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsLib.pro 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsLib.pro 2005-12-26 20:17:46 UTC (rev 16)
@@ -7,8 +7,11 @@
include( ../../common.pri )
include( ../../config.pri )
include( ../../defines.pri )
+include( ../../odbc.pri )
CONFIG += staticlib
+CONFIG += console
INCLUDEPATH += ../../MYODBCC/include
+INCLUDEPATH += ../include
# #########################################################
# UNIX
@@ -31,28 +34,13 @@
# #########################################################
HEADERS = \
../include/MYODBCIns.h \
+ ../include/MYODBCInsDriver.h \
+ ../include/MYODBCInsDataSource.h \
+ ../include/MYODBCInsDriverConnect.h \
MYODBCInsInternal.h
SOURCES = \
- MYODBCInsAllocDataSource.c \
- MYODBCInsAllocDriver.c \
- MYODBCInsClearDataSource.c \
- MYODBCInsClearDriver.c \
- MYODBCInsDefaultDataSource.c \
- MYODBCInsDumpDataSource.c \
- MYODBCInsDumpDriver.c \
- MYODBCInsExistsDataSource.c \
- MYODBCInsFreeDataSource.c \
- MYODBCInsFreeDriver.c \
- MYODBCInsGetDataSourceNames.c \
- MYODBCInsGetDriverNames.c \
- MYODBCInsInsertStr.c \
- MYODBCInsReadConnectStr.c \
- MYODBCInsReadDataSource.c \
- MYODBCInsReadDataSourceStr.c \
- MYODBCInsReadDriver.c \
- MYODBCInsWriteConnectStr.c \
- MYODBCInsWriteDataSource.c \
- MYODBCInsWriteDataSourceStr.c \
- MYODBCInsWriteDriver.c
+ MYODBCInsDriver.cpp \
+ MYODBCInsDataSource.cpp \
+ MYODBCInsDriverConnect.cpp
Modified: MYODBCIns/MYODBCInsLib/MYODBCInsLib.vpj
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsLib.vpj 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsLib.vpj 2005-12-26 20:17:46 UTC (rev 16)
@@ -184,27 +184,11 @@
<Folder
Name="Source Files"
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl">
- <F N="MYODBCInsAllocDataSource.c"/>
- <F N="MYODBCInsAllocDriver.c"/>
- <F N="MYODBCInsClearDataSource.c"/>
- <F N="MYODBCInsClearDriver.c"/>
- <F N="MYODBCInsDefaultDataSource.c"/>
- <F N="MYODBCInsDumpDataSource.c"/>
- <F N="MYODBCInsDumpDriver.c"/>
- <F N="MYODBCInsExistsDataSource.c"/>
- <F N="MYODBCInsFreeDataSource.c"/>
- <F N="MYODBCInsFreeDriver.c"/>
- <F N="MYODBCInsGetDataSourceNames.c"/>
- <F N="MYODBCInsGetDriverNames.c"/>
- <F N="MYODBCInsInsertStr.c"/>
- <F N="MYODBCInsReadConnectStr.c"/>
- <F N="MYODBCInsReadDataSource.c"/>
- <F N="MYODBCInsReadDataSourceStr.c"/>
- <F N="MYODBCInsReadDriver.c"/>
- <F N="MYODBCInsWriteConnectStr.c"/>
- <F N="MYODBCInsWriteDataSource.c"/>
- <F N="MYODBCInsWriteDataSourceStr.c"/>
- <F N="MYODBCInsWriteDriver.c"/>
+ <F N="backup.c"/>
+ <F N="MYODBCIns.cpp"/>
+ <F N="MYODBCInsDataSource.cpp"/>
+ <F N="MYODBCInsDriver.cpp"/>
+ <F N="MYODBCInsDriverConnect.cpp"/>
</Folder>
<Folder
Name="Header Files"
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsReadConnectStr.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsReadConnectStr.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsReadConnectStr.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,195 +0,0 @@
-/* Copyright (C) 2000-2004 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-MYODBC_C_BOOL MYODBCInsReadConnectStr( MYODBC_INS_DATASOURCE *pDataSource, LPCSTR pszStr
)
-{
- MYODBC_INS_ATTR_PARSE_STATE nState = MYODBC_INS_ATTR_PARSE_STATE_NAME_START;
- char * pAnchorChar = (char *)pszStr;
- char * pScanChar = (char *)pszStr;
- char * pszName = 0;
-
- /* short circuit if we have not been given stuff to parse */
- if ( !pszStr || !(*pszStr) )
- return MYODBC_C_FALSE;
-
- /* scan the input */
- while ( 1 )
- {
- switch ( nState )
- {
- case MYODBC_INS_ATTR_PARSE_STATE_NAME_START:
- {
- if ( isalpha( *pScanChar ) || *pScanChar == '{' )
- {
- pAnchorChar = pScanChar;
- nState = MYODBC_INS_ATTR_PARSE_STATE_NAME;
- }
- }
- break;
- case MYODBC_INS_ATTR_PARSE_STATE_NAME:
- {
- if ( (!isalpha( *pScanChar ) && !isdigit( *pScanChar )
&& *pScanChar != '}') || *pScanChar == '=' )
- {
- pszName = MYODBCCStrDup( pAnchorChar, pScanChar - pAnchorChar );
-
- if ( *pScanChar == '=' )
- nState = MYODBC_INS_ATTR_PARSE_STATE_VALUE_START;
- else
- nState = MYODBC_INS_ATTR_PARSE_STATE_EQUAL;
- }
- }
- break;
- case MYODBC_INS_ATTR_PARSE_STATE_EQUAL:
- {
- if ( *pScanChar == '=' )
- nState = MYODBC_INS_ATTR_PARSE_STATE_VALUE_START;
- }
- break;
- case MYODBC_INS_ATTR_PARSE_STATE_VALUE_START:
- {
- if ( !isspace( *pScanChar ) )
- {
- pAnchorChar = pScanChar;
- nState = MYODBC_INS_ATTR_PARSE_STATE_VALUE;
- }
- }
- break;
- case MYODBC_INS_ATTR_PARSE_STATE_VALUE:
- {
- /*
- \internal ODBC Rule
-
- If any keywords are repeated in the connection string, the driver
uses the value
- associated with the first occurrence of the keyword. If the DSN
and DRIVER keywords
- are included in the same connection string, the Driver Manager
and the driver use
- whichever keyword appears first.
- */
-
- /* ';' terminates name/value but we may not find one for last */
- if ( *pScanChar == ';' || *pScanChar == '\0' )
- {
- if ( MYODBCCStrCaseCmp( pszName, "DATABASE" ) == 0 ||
MYODBCCStrCaseCmp( pszName, "DB" ) == 0 )
- {
- if ( !pDataSource->pszDATABASE )
- pDataSource->pszDATABASE = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar ) ;
- }
- else if ( MYODBCCStrCaseCmp( pszName, "DESCRIPTION" ) == 0 ||
MYODBCCStrCaseCmp( pszName, "DESC" ) == 0 )
- {
- if ( !pDataSource->pszDESCRIPTION )
- pDataSource->pszDESCRIPTION = MYODBCCStrDup(
pAnchorChar, pScanChar - pAnchorChar );
- }
- else if ( MYODBCCStrCaseCmp( pszName, "DRIVER" ) == 0 )
- {
- if ( !pDataSource->pszDRIVER &&
!pDataSource->pszDSN ) /* we use one or other - whichever comes 1st */
- {
- pDataSource->pszDRIVER = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar ); /* friendly name such as; "MySQL ODBC 3.51 Driver" */
- pDataSource->nConnect =
MYODBC_INS_DATASOURCE_CONNECT_DRIVER;
- }
- }
- else if ( MYODBCCStrCaseCmp( pszName, "DSN" ) == 0 )
- {
- if ( !pDataSource->pszDSN &&
!pDataSource->pszDRIVER ) /* we use one or other - whichever comes 1st */
- {
- pDataSource->pszDSN = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar );
- pDataSource->nConnect =
MYODBC_INS_DATASOURCE_CONNECT_DSN;
- }
- }
- else if ( MYODBCCStrCaseCmp( pszName, "OPTION" ) == 0 )
- {
- if ( !pDataSource->pszOPTION )
- pDataSource->pszOPTION = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar );
- }
- /*
- \internal MYODBC Rule
-
- We will 'read' variants on the standard keywords (but only
write standard version).
- */
- else if ( MYODBCCStrCaseCmp( pszName, "PWD" ) == 0 ||
MYODBCCStrCaseCmp( pszName, "PASSWORD" ) == 0 )
- {
- if ( !pDataSource->pszPASSWORD )
- pDataSource->pszPASSWORD = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar );
- }
- else if ( MYODBCCStrCaseCmp( pszName, "PORT" ) == 0 )
- {
- if ( !pDataSource->pszPORT )
- pDataSource->pszPORT = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar );
- }
- else if ( MYODBCCStrCaseCmp( pszName, "SERVER" ) == 0 )
- {
- if ( !pDataSource->pszSERVER )
- pDataSource->pszSERVER = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar );
- }
- else if ( MYODBCCStrCaseCmp( pszName, "SOCKET" ) == 0 )
- {
- if ( !pDataSource->pszSOCKET )
- pDataSource->pszSOCKET = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar );
- }
- else if ( MYODBCCStrCaseCmp( pszName, "STMT" ) == 0 )
- {
- if ( !pDataSource->pszSTMT )
- pDataSource->pszSTMT = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar );
- }
- /*
- \internal MYODBC Rule
-
- We will 'read' variants on the standard keywords (but only
write standard version).
- */
- else if ( MYODBCCStrCaseCmp( pszName, "UID" ) == 0 ||
MYODBCCStrCaseCmp( pszName, "USER" ) == 0 )
- {
- if ( !pDataSource->pszUSER )
- pDataSource->pszUSER = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar );
- }
- else
- {
- /* What the ? */
- }
-
- if ( pszName )
- MYODBCCFree( pszName );
- pszName = 0;
- }
- }
- break;
- default:
- fprintf( stderr, "[%s][%d][ERROR] Unhandled state.\n", __FILE__, __LINE__
);
- return MYODBC_C_FALSE;
- }
-
- /* ';' is used to terminate a name/value pair */
- if ( *pScanChar == ';' )
- nState = MYODBC_INS_ATTR_PARSE_STATE_NAME_START;
-
- /* null terminates */
- if ( pScanChar[0] == '\0' )
- break;
-
- pScanChar++;
-
- } /* while scan */
-
- if ( pszName )
- MYODBCCFree( pszName );
-
- return MYODBC_C_TRUE;
-}
-
-
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsReadDataSource.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsReadDataSource.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsReadDataSource.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,249 +0,0 @@
-/* Copyright (C) 2000-2005 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-/*!
- \note - unixODBC does not have a header section in ini files.
- - On XP, the "32 bit" parts are secretly stripped away
- inside SQLGetPrivateProfileString() somewhere.
-*/
-#define MYODBC_INS_ODBCINI_HEADER_SECTION "ODBC Data Sources"
-
-MYODBC_C_BOOL MYODBCInsReadDataSource( MYODBC_INS_DATASOURCE *pDataSource, LPCSTR pszDSN
)
-{
- char szEntryNames[SQL_MAX_DSN_LENGTH * MYODBC_INS_MAX_DSN_NAMES];
- char * pszEntryName;
- char szValue[4096];
- int nChars = 0;
-#if defined(WIN32)
- UWORD nMode = ODBC_BOTH_DSN;
-
- if ( !SQLGetConfigMode( &nMode ) )
- {
- fprintf( stderr, "[%s][%d][ERROR] SQLGetConfigMode failed!\n", __FILE__, __LINE__
);
- return MYODBC_C_FALSE;
- }
-#endif
-
- if ( !pszDSN || !(*pszDSN) )
- return MYODBC_C_TRUE;
-
- *szEntryNames = '\0';
-
-#if defined(__APPLE__)
- /*!
- \note OSX
-
- SQLGetPrivateProfileString is the proper call and is available - but
- at this time it appears utterly broken. So we call an alternative
- instead.
- */
- if ( ( nChars = GetPrivateProfileString( pszDSN, NULL, NULL, szEntryNames, sizeof(
szEntryNames ) - 1, "odbc.ini" ) ) < 1 )
-#else
- if ( ( nChars = SQLGetPrivateProfileString( pszDSN, NULL, NULL, szEntryNames, sizeof(
szEntryNames ) - 1, "ODBC.INI" ) ) < 1 )
-#endif
- return MYODBC_C_FALSE;
-
-#if defined(WIN32)
- {
- int nLen = strlen( szEntryNames );
-
- /*!
- \note XP
-
- Bug in SQLGetPrivateProfileString when mode is ODBC_BOTH_DSN and we
are looking for a system
- DSN. In this case SQLGetPrivateProfileString will find the system dsn
but return a corrupt
- list of attributes.
-
- A corrupt list of attributes can be identified because the first
attribute (if any) will be
- followed by more than one '\0'.
-
- The solution is to detect this condition and set mode to
ODBC_SYSTEM_DSN and try again. We
- also ensure we reset the mode when done - regardless of outcome.
- */
- if ( nMode == ODBC_BOTH_DSN && nLen < nChars &&
szEntryNames[nLen + 1 ] == '\0' )
- {
- *szEntryNames = '\0';
- if ( !SQLSetConfigMode( ODBC_SYSTEM_DSN ) )
- fprintf( stderr, "[%s][%d][ERROR] SQLSetConfigMode failed!\n", __FILE__,
__LINE__ );
-
- if ( ( nChars = SQLGetPrivateProfileString( pszDSN, NULL, NULL, szEntryNames,
sizeof( szEntryNames ) - 1, "ODBC.INI" ) ) < 1 )
- return MYODBC_C_FALSE;
- }
- }
-#endif
-
- /*!
- Looks like things are going to work. Lets set DSN.
- */
- if ( !pDataSource->pszDSN )
- pDataSource->pszDSN = MYODBCCStrDup( (SQLCHAR*)pszDSN, SQL_NTS );
-
- /*!
- Scan result and return MYODBC_C_TRUE if we find a match.
- */
- pszEntryName = szEntryNames;
- while ( *pszEntryName )
- {
- *szValue = '\0';
-#if defined(__APPLE__)
- if ( GetPrivateProfileString( pszDSN, pszEntryName, NULL, szValue, sizeof(
szValue ) - 1, "odbc.ini" ) > 0 )
-#elif defined(WIN32)
- if ( SQLGetPrivateProfileString( pszDSN, pszEntryName, NULL, szValue, sizeof(
szValue ) - 1, "ODBC.INI" ) > 0 )
-#else
- if ( SQLGetPrivateProfileString( pszDSN, pszEntryName, "", szValue, sizeof(
szValue ) - 1, "ODBC.INI" ) > 0 )
-#endif
- {
- /*!
- \internal ODBC Rule
- (SQLDriverConnect)
-
- The driver uses any information it retrieves from the system information
- to augment the information passed to it in the connection string. If the
- information in the system information duplicates information in the
- connection string, the driver uses the information in the connection
- string.
- */
- if ( MYODBCCStrCaseCmp( pszEntryName, "DATABASE" ) == 0 || MYODBCCStrCaseCmp(
pszEntryName, "DB" ) == 0 )
- {
- if ( !pDataSource->pszDATABASE )
- {
- pDataSource->pszDATABASE = MYODBCCStrDup( szValue, SQL_NTS );
- }
- }
- else if ( MYODBCCStrCaseCmp( pszEntryName, "DESCRIPTION" ) == 0 ||
MYODBCCStrCaseCmp( pszEntryName, "DESC" ) == 0 )
- {
- if ( !pDataSource->pszDESCRIPTION )
- pDataSource->pszDESCRIPTION = MYODBCCStrDup( szValue, SQL_NTS );
- }
- else if ( MYODBCCStrCaseCmp( pszEntryName, "DRIVER" ) == 0 )
- {
-#if defined(WIN32)
- if ( !pDataSource->pszDriverFileName )
- pDataSource->pszDriverFileName = MYODBCCStrDup( szValue, SQL_NTS
);
-#else
- if ( *szValue == '/' )
- {
- if ( !pDataSource->pszDriverFileName )
- pDataSource->pszDriverFileName = MYODBCCStrDup( szValue,
SQL_NTS );
- }
- else
- {
- if ( !pDataSource->pszDRIVER )
- pDataSource->pszDRIVER = MYODBCCStrDup( szValue, SQL_NTS );
- }
-#endif
- }
- else if ( MYODBCCStrCaseCmp( pszEntryName, "OPTION" ) == 0 )
- {
- if ( !pDataSource->pszOPTION )
- pDataSource->pszOPTION = MYODBCCStrDup( szValue, SQL_NTS );
- }
- else if ( MYODBCCStrCaseCmp( pszEntryName, "PWD" ) == 0 || MYODBCCStrCaseCmp(
pszEntryName, "PASSWORD" ) == 0 )
- {
- if ( !pDataSource->pszPASSWORD )
- pDataSource->pszPASSWORD = MYODBCCStrDup( szValue, SQL_NTS );
- }
- else if ( MYODBCCStrCaseCmp( pszEntryName, "PORT" ) == 0 )
- {
- if ( !pDataSource->pszPORT )
- pDataSource->pszPORT = MYODBCCStrDup( szValue, SQL_NTS );
- }
- else if ( MYODBCCStrCaseCmp( pszEntryName, "SERVER" ) == 0 )
- {
- if ( !pDataSource->pszSERVER )
- pDataSource->pszSERVER = MYODBCCStrDup( szValue, SQL_NTS );
- }
- else if ( MYODBCCStrCaseCmp( pszEntryName, "SOCKET" ) == 0 )
- {
- if ( !pDataSource->pszSOCKET )
- pDataSource->pszSOCKET = MYODBCCStrDup( szValue, SQL_NTS );
- }
- else if ( MYODBCCStrCaseCmp( pszEntryName, "STMT" ) == 0 )
- {
- if ( !pDataSource->pszSTMT )
- pDataSource->pszSTMT = MYODBCCStrDup( szValue, SQL_NTS );
- }
- else if ( MYODBCCStrCaseCmp( pszEntryName, "UID" ) == 0 || MYODBCCStrCaseCmp(
pszEntryName, "USER" ) == 0 )
- {
- if ( !pDataSource->pszUSER )
- pDataSource->pszUSER = MYODBCCStrDup( szValue, SQL_NTS );
- }
- else
- {
- /* What the ? */
- fprintf( stderr, "[%s][%d][ERROR] Unknown attribute (%s).\n", __FILE__,
__LINE__, pszEntryName );
- }
- }
- else
- fprintf( stderr, "[%s][%d][WARNING] Failed to get value for attribute
(%s).\n", __FILE__, __LINE__, pszEntryName );
-
- pszEntryName += strlen( pszEntryName ) + 1;
- } /* while */
-
-
- /* try harder to get the friendly driver name */
- if ( !pDataSource->pszDRIVER )
- {
-#if defined(__APPLE__)
- if ( GetPrivateProfileString( MYODBC_INS_ODBCINI_HEADER_SECTION, NULL, NULL,
szEntryNames, sizeof( szEntryNames ) - 1, "odbc.ini" ) < 1 )
-#else
- if ( SQLGetPrivateProfileString( MYODBC_INS_ODBCINI_HEADER_SECTION, NULL, NULL,
szEntryNames, sizeof( szEntryNames ) - 1, "ODBC.INI" ) < 1 )
-#endif
- return MYODBC_C_FALSE;
-
- pszEntryName = szEntryNames;
- while ( *pszEntryName )
- {
- *szValue = '\0';
-#if defined(__APPLE__)
- if ( GetPrivateProfileString( MYODBC_INS_ODBCINI_HEADER_SECTION,
pszEntryName, NULL, szValue, sizeof( szValue ) - 1, "odbc.ini" ) > 0 )
-#else
- if ( SQLGetPrivateProfileString( MYODBC_INS_ODBCINI_HEADER_SECTION,
pszEntryName, NULL, szValue, sizeof( szValue ) - 1, "ODBC.INI" ) > 0 )
-#endif
- {
- if ( MYODBCCStrCaseCmp( pszEntryName, pszDSN ) == 0 )
- {
- pDataSource->pszDRIVER = MYODBCCStrDup( szValue, SQL_NTS );
- }
- }
- pszEntryName += strlen( pszEntryName ) + 1;
- }
- }
-
-#if defined(WIN32)
- /*!
- XP
-
- Some people have reported that the friendly driver name is never found so...
- */
- if ( !pDataSource->pszDRIVER )
- pDataSource->pszDRIVER = MYODBCINST_DRIVER_NAME;
-#endif
-
-#if defined(WIN32)
- /* ALWAYS restore mode */
- SQLSetConfigMode( nMode );
-#endif
-
- return MYODBC_C_TRUE;
-}
-
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsReadDataSourceStr.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsReadDataSourceStr.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsReadDataSourceStr.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,241 +0,0 @@
-/* Copyright (C) 2000-2005 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-/*! \todo hide this in libMYODBCC */
-#if defined(__APPLE__) || defined(WIN32) || defined(__SPARC__)
-char *strndup( const char *s, size_t n )
-{
- size_t nAvail;
- char *p;
-
- if ( !s )
- return 0;
-
- nAvail = min( strlen(s) + 1, n + 1 );
- p = malloc( nAvail );
- memcpy( p, s, nAvail );
- p[nAvail - 1] = '\0';
-
- return p;
-}
-#endif
-
-MYODBC_C_BOOL MYODBCInsReadDataSourceStrValTerm( MYODBC_INS_DELIM nDelim, char cChar )
-{
- switch ( nDelim )
- {
- case MYODBC_INS_DELIM_NULL:
- if ( cChar == '\0' )
- return MYODBC_C_TRUE;
- break;
- case MYODBC_INS_DELIM_SEMI:
- /* We check for '\0' to handle case where last value does not have a ';'.
*/
- /* In such a case the '\0' is the string terminator.
*/
- if ( cChar == ';' || cChar == '\0' )
- return MYODBC_C_TRUE;
- break;
- case MYODBC_INS_DELIM_BOTH:
- if ( cChar == '\0' || cChar == ';' )
- return MYODBC_C_TRUE;
- break;
- }
-
- return MYODBC_C_FALSE;
-}
-
-MYODBC_C_BOOL MYODBCInsReadDataSourceStrTerm( MYODBC_INS_DELIM nDelim, char *pcScanChar )
-{
- switch ( nDelim )
- {
- case MYODBC_INS_DELIM_NULL:
- if ( pcScanChar[0] == '\0' && pcScanChar[1] == '\0' )
- return MYODBC_C_TRUE;
- break;
- case MYODBC_INS_DELIM_SEMI:
- if ( pcScanChar[0] == '\0' )
- return MYODBC_C_TRUE;
- break;
- case MYODBC_INS_DELIM_BOTH:
- /* we can not really handle both - so handle as per MYODBC_INS_DELIM_NULL */
- if ( pcScanChar[0] == '\0' && pcScanChar[1] == '\0' )
- return MYODBC_C_TRUE;
- break;
- }
-
- return MYODBC_C_FALSE;
-}
-
-MYODBC_C_BOOL MYODBCInsReadDataSourceStr( MYODBC_INS_DATASOURCE *pDataSource,
MYODBC_INS_DELIM nDelim, LPCSTR pszStr )
-{
- MYODBC_INS_ATTR_PARSE_STATE nState = MYODBC_INS_ATTR_PARSE_STATE_NAME_START;
- char * pAnchorChar = (char *)pszStr;
- char * pScanChar = (char *)pszStr;
- char * pszName = 0;
-
- /* short circuit if we have not been given stuff to parse */
- if ( !pszStr || !(*pszStr) )
- return MYODBC_C_TRUE; /* done and no errors :) */
-
- /* scan the input */
- while ( 1 )
- {
- switch ( nState )
- {
- case MYODBC_INS_ATTR_PARSE_STATE_NAME_START:
- {
- if ( isalpha( *pScanChar ) )
- {
- pAnchorChar = pScanChar;
- nState = MYODBC_INS_ATTR_PARSE_STATE_NAME;
- }
- }
- break;
- case MYODBC_INS_ATTR_PARSE_STATE_NAME:
- {
- if ( (!isalpha( *pScanChar ) && !isdigit( *pScanChar )) ||
*pScanChar == '=' )
- {
- pszName = MYODBCCStrDup( pAnchorChar, pScanChar - pAnchorChar );
-
- if ( *pScanChar == '=' )
- nState = MYODBC_INS_ATTR_PARSE_STATE_VALUE_START;
- else
- nState = MYODBC_INS_ATTR_PARSE_STATE_EQUAL;
- }
- }
- break;
- case MYODBC_INS_ATTR_PARSE_STATE_EQUAL:
- {
- if ( *pScanChar == '=' )
- nState = MYODBC_INS_ATTR_PARSE_STATE_VALUE_START;
- }
- break;
- case MYODBC_INS_ATTR_PARSE_STATE_VALUE_START:
- {
- if ( !isspace( *pScanChar ) )
- {
- pAnchorChar = pScanChar;
- nState = MYODBC_INS_ATTR_PARSE_STATE_VALUE;
- }
- }
- break;
- case MYODBC_INS_ATTR_PARSE_STATE_VALUE:
- {
- if ( MYODBCInsReadDataSourceStrValTerm( nDelim, *pScanChar ) )
- {
- if ( MYODBCCStrCaseCmp( pszName, "DATABASE" ) == 0 ||
MYODBCCStrCaseCmp( pszName, "DB" ) == 0 )
- {
- if ( !pDataSource->pszDATABASE )
- pDataSource->pszDATABASE = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar ) ;
- }
- else if ( MYODBCCStrCaseCmp( pszName, "DESCRIPTION" ) == 0 ||
MYODBCCStrCaseCmp( pszName, "DESC" ) == 0 )
- {
- if ( !pDataSource->pszDESCRIPTION )
- pDataSource->pszDESCRIPTION = MYODBCCStrDup(
pAnchorChar, pScanChar - pAnchorChar );
- }
- else if ( MYODBCCStrCaseCmp( pszName, "DRIVER" ) == 0 )
- {
- if ( !pDataSource->pszDRIVER )
- pDataSource->pszDRIVER = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar );
- }
- else if ( MYODBCCStrCaseCmp( pszName, "DSN" ) == 0 )
- {
- if ( !pDataSource->pszDSN )
- pDataSource->pszDSN = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar );
- }
- else if ( MYODBCCStrCaseCmp( pszName, "OPTION" ) == 0 )
- {
- if ( !pDataSource->pszOPTION )
- pDataSource->pszOPTION = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar );
- }
- /*
- \internal MYODBC Rule
-
- We will 'read' variants on the standard keywords (but only
write standard version).
- */
- else if ( MYODBCCStrCaseCmp( pszName, "PWD" ) == 0 ||
MYODBCCStrCaseCmp( pszName, "PASSWORD" ) == 0 )
- {
- if ( !pDataSource->pszPASSWORD )
- pDataSource->pszPASSWORD = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar );
- }
- else if ( MYODBCCStrCaseCmp( pszName, "PORT" ) == 0 )
- {
- if ( !pDataSource->pszPORT )
- pDataSource->pszPORT = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar );
- }
- else if ( MYODBCCStrCaseCmp( pszName, "SERVER" ) == 0 )
- {
- if ( !pDataSource->pszSERVER )
- pDataSource->pszSERVER = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar );
- }
- else if ( MYODBCCStrCaseCmp( pszName, "SOCKET" ) == 0 )
- {
- if ( !pDataSource->pszSOCKET )
- pDataSource->pszSOCKET = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar );
- }
- else if ( MYODBCCStrCaseCmp( pszName, "STMT" ) == 0 )
- {
- if ( !pDataSource->pszSTMT )
- pDataSource->pszSTMT = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar );
- }
- /*
- \internal MYODBC Rule
-
- We will 'read' variants on the standard keywords (but only
write standard version).
- */
- else if ( MYODBCCStrCaseCmp( pszName, "UID" ) == 0 ||
MYODBCCStrCaseCmp( pszName, "USER" ) == 0 )
- {
- if ( !pDataSource->pszUSER )
- pDataSource->pszUSER = MYODBCCStrDup( pAnchorChar,
pScanChar - pAnchorChar );
- }
- else
- {
- fprintf( stderr, "[%s][%d][ERROR] Unhandled attribute
(%s).\n", __FILE__, __LINE__, pszName );
- }
-
- MYODBCCFree( pszName );
- pszName = 0;
- }
- }
- break;
- default:
- fprintf( stderr, "[%s][%d][ERROR] Unhandled state.\n", __FILE__, __LINE__
);
- return MYODBC_C_FALSE;
- } /* switch */
-
- /* is attribute value term ? */
- if ( MYODBCInsReadDataSourceStrValTerm( nDelim, *pScanChar ) )
- nState = MYODBC_INS_ATTR_PARSE_STATE_NAME_START;
-
- /* is attribute list term ? */
- if ( MYODBCInsReadDataSourceStrTerm( nDelim, pScanChar ) )
- break;
-
- pScanChar++;
-
- } /* while scan */
-
- MYODBCCFree( pszName );
-
- return MYODBC_C_TRUE;
-}
-
-
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsReadDriver.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsReadDriver.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsReadDriver.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,82 +0,0 @@
-/* Copyright (C) 2000-2004 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-MYODBC_C_BOOL MYODBCInsReadDriver( MYODBC_INS_DRIVER *pDriver, LPCSTR pszName )
-{
- char szEntryNames[SQL_MAX_DSN_LENGTH * MYODBC_INS_MAX_DSN_NAMES];
- char * pszEntryName;
- char szValue[4096];
-
- if ( !pszName || !(*pszName) )
- return MYODBC_C_FALSE;
-
- if ( !pDriver->pszName )
- pDriver->pszName = strdup( pszName ) ;
-
-#if defined(__APPLE__)
- /*!
- \note OSX
-
- SQLGetPrivateProfileString is the proper call and is available - but
- at this time it appears utterly broken. So we call an alternative
- instead.
- */
- if ( GetPrivateProfileString( pszName, NULL, NULL, szEntryNames, sizeof( szEntryNames
) - 1, "ODBCINST.INI" ) < 1 )
-#else
- if ( SQLGetPrivateProfileString( pszName, NULL, "", szEntryNames, sizeof(
szEntryNames ) - 1, "ODBCINST.INI" ) < 1 )
-#endif
- return MYODBC_C_FALSE;
-
- /*!
- Scan result and return MYODBC_C_TRUE if we find a match.
- */
- pszEntryName = szEntryNames;
- while ( *pszEntryName )
- {
- *szValue = '\0';
-#if defined(__APPLE__)
- if ( GetPrivateProfileString( pszName, pszEntryName, NULL, szValue, sizeof(
szValue ) - 1, "ODBCINST.INI" ) > 0 )
-#else
- if ( SQLGetPrivateProfileString( pszName, pszEntryName, "", szValue, sizeof(
szValue ) - 1, "ODBCINST.INI" ) > 0 )
-#endif
- {
- if ( MYODBCCStrCaseCmp( pszEntryName, "DRIVER" ) == 0 )
- {
- if ( !pDriver->pszDRIVER )
- pDriver->pszDRIVER = strdup( szValue ) ;
- }
- else if ( MYODBCCStrCaseCmp( pszEntryName, "SETUP" ) == 0 )
- {
- if ( !pDriver->pszSETUP )
- pDriver->pszSETUP = strdup( szValue );
- }
- else
- {
- /* What the ? */
- }
- }
- pszEntryName += strlen( pszEntryName ) + 1;
- } /* while */
-
- return MYODBC_C_TRUE;
-}
-
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsWriteConnectStr.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsWriteConnectStr.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsWriteConnectStr.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,140 +0,0 @@
-/* Copyright (C) 2000-2004 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-MYODBC_C_BOOL MYODBCInsWriteConnectStr( MYODBC_INS_DATASOURCE *pDataSource, char *pszStr,
SQLSMALLINT nMaxLen )
-{
- int nIndex = 0;
-
- *pszStr = '\0';
-
- if ( pDataSource->pszDATABASE )
- {
- if ( !MYODBCInsInsertStr( pszStr, "DATABASE=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszDATABASE, nMaxLen,
&nIndex ) )
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszDESCRIPTION )
- {
- if ( nIndex && !MYODBCInsInsertStr( pszStr, ";", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, "DESCRIPTION=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszDATABASE, nMaxLen,
&nIndex ) )
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszDRIVER )
- {
- if ( nIndex && !MYODBCInsInsertStr( pszStr, ";", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, "DRIVER=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszDRIVER, nMaxLen, &nIndex
) )
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszDSN )
- {
- if ( nIndex && !MYODBCInsInsertStr( pszStr, ";", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, "DSN=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszDSN, nMaxLen, &nIndex )
)
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszOPTION )
- {
- if ( nIndex && !MYODBCInsInsertStr( pszStr, ";", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, "OPTION=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszOPTION, nMaxLen, &nIndex
) )
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszPASSWORD )
- {
- if ( nIndex && !MYODBCInsInsertStr( pszStr, ";", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, "PWD=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszPASSWORD, nMaxLen,
&nIndex ) )
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszPORT )
- {
- if ( nIndex && !MYODBCInsInsertStr( pszStr, ";", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, "PORT=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszPORT, nMaxLen, &nIndex )
)
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszSERVER )
- {
- if ( nIndex && !MYODBCInsInsertStr( pszStr, ";", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, "SERVER=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszSERVER, nMaxLen, &nIndex
) )
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszSOCKET )
- {
- if ( nIndex && !MYODBCInsInsertStr( pszStr, ";", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, "SOCKET=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszSOCKET, nMaxLen, &nIndex
) )
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszSTMT )
- {
- if ( nIndex && !MYODBCInsInsertStr( pszStr, ";", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, "STMT=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszSTMT, nMaxLen, &nIndex )
)
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszUSER )
- {
- if ( nIndex && !MYODBCInsInsertStr( pszStr, ";", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, "UID=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszUSER, nMaxLen, &nIndex )
)
- return MYODBC_C_FALSE;
- }
-
- return MYODBC_C_TRUE;
-}
-
-
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsWriteDataSource.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsWriteDataSource.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsWriteDataSource.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,70 +0,0 @@
-/* Copyright (C) 2000-2004 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-MYODBC_C_BOOL MYODBCInsWriteDataSource( MYODBC_INS_DATASOURCE *pDataSource )
-{
- /*
- SQLWriteDSNToIni is *supposed* to replace any existing DSN
- with same name but fails (at least on unixODBC) to do so.
- So we ensure that any existing DSN with same name is removed
- with the following call.
- */
- if ( !SQLRemoveDSNFromIni( pDataSource->pszDSN ) )
- return MYODBC_C_FALSE;
-
- /* create/replace data source name */
- if ( !SQLWriteDSNToIni( pDataSource->pszDSN, pDataSource->pszDRIVER ) )
- return MYODBC_C_FALSE;
-
- /* add details */
- if ( pDataSource->pszDATABASE &&
- !SQLWritePrivateProfileString( pDataSource->pszDSN, "DATABASE",
pDataSource->pszDATABASE, "odbc.ini" ) )
- return MYODBC_C_FALSE;
- if ( pDataSource->pszDESCRIPTION &&
- !SQLWritePrivateProfileString( pDataSource->pszDSN, "DESCRIPTION",
pDataSource->pszDESCRIPTION, "odbc.ini" ) )
- return MYODBC_C_FALSE;
- if ( pDataSource->pszOPTION &&
- !SQLWritePrivateProfileString( pDataSource->pszDSN, "OPTION",
pDataSource->pszOPTION, "odbc.ini" ) )
- return MYODBC_C_FALSE;
- if ( pDataSource->pszPASSWORD &&
- !SQLWritePrivateProfileString( pDataSource->pszDSN, "PWD",
pDataSource->pszPASSWORD, "odbc.ini" ) )
- return MYODBC_C_FALSE;
- if ( pDataSource->pszPORT &&
- !SQLWritePrivateProfileString( pDataSource->pszDSN, "PORT",
pDataSource->pszPORT, "odbc.ini" ) )
- return MYODBC_C_FALSE;
- if ( pDataSource->pszSERVER &&
- !SQLWritePrivateProfileString( pDataSource->pszDSN, "SERVER",
pDataSource->pszSERVER, "odbc.ini" ) )
- return MYODBC_C_FALSE;
- if ( pDataSource->pszSOCKET &&
- !SQLWritePrivateProfileString( pDataSource->pszDSN, "SOCKET",
pDataSource->pszSOCKET, "odbc.ini" ) )
- return MYODBC_C_FALSE;
- if ( pDataSource->pszSTMT &&
- !SQLWritePrivateProfileString( pDataSource->pszDSN, "STMT",
pDataSource->pszSTMT, "odbc.ini" ) )
- return MYODBC_C_FALSE;
- if ( pDataSource->pszUSER &&
- !SQLWritePrivateProfileString( pDataSource->pszDSN, "UID",
pDataSource->pszUSER, "odbc.ini" ) )
- return MYODBC_C_FALSE;
-
- return MYODBC_C_TRUE;
-}
-
-
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsWriteDataSourceStr.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsWriteDataSourceStr.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsWriteDataSourceStr.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,168 +0,0 @@
-/* Copyright (C) 2000-2005 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-#define MYODBCINSWRITEDATASOURCESTR_DELIM \
- if ( nIndex ) \
- { \
- if ( nIndex >= nMaxLen ) \
- return MYODBC_C_FALSE; \
- pszStr[nIndex] = cDelim; \
- nIndex++; \
- }
-
-MYODBC_C_BOOL MYODBCInsWriteDataSourceStr( MYODBC_INS_DATASOURCE *pDataSource,
MYODBC_INS_DELIM nDelim, char *pszStr, SQLSMALLINT nMaxLen )
-{
- int nIndex = 0;
- char cDelim = ';';
-
- if ( nMaxLen < 2 )
- return MYODBC_C_FALSE;
-
- switch ( nDelim )
- {
- case MYODBC_INS_DELIM_NULL:
- cDelim = '\0';
- break;
- case MYODBC_INS_DELIM_SEMI:
- case MYODBC_INS_DELIM_BOTH:
- break;
- }
-
- pszStr[nIndex] = '\0';
-
- if ( pDataSource->pszDATABASE )
- {
- if ( !MYODBCInsInsertStr( pszStr, "DATABASE=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszDATABASE, nMaxLen,
&nIndex ) )
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszDESCRIPTION )
- {
- MYODBCINSWRITEDATASOURCESTR_DELIM;
-
- if ( !MYODBCInsInsertStr( pszStr, "DESCRIPTION=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszDATABASE, nMaxLen,
&nIndex ) )
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszDRIVER )
- {
- MYODBCINSWRITEDATASOURCESTR_DELIM;
-
- if ( !MYODBCInsInsertStr( pszStr, "DRIVER=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszDRIVER, nMaxLen, &nIndex
) )
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszDSN )
- {
- MYODBCINSWRITEDATASOURCESTR_DELIM;
-
- if ( !MYODBCInsInsertStr( pszStr, "DSN=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszDSN, nMaxLen, &nIndex )
)
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszOPTION )
- {
- MYODBCINSWRITEDATASOURCESTR_DELIM;
-
- if ( !MYODBCInsInsertStr( pszStr, "OPTION=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszOPTION, nMaxLen, &nIndex
) )
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszPASSWORD )
- {
- MYODBCINSWRITEDATASOURCESTR_DELIM;
-
- if ( !MYODBCInsInsertStr( pszStr, "PWD=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszPASSWORD, nMaxLen,
&nIndex ) )
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszPORT )
- {
- MYODBCINSWRITEDATASOURCESTR_DELIM;
-
- if ( !MYODBCInsInsertStr( pszStr, "PORT=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszPORT, nMaxLen, &nIndex )
)
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszSERVER )
- {
- MYODBCINSWRITEDATASOURCESTR_DELIM;
-
- if ( !MYODBCInsInsertStr( pszStr, "SERVER=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszSERVER, nMaxLen, &nIndex
) )
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszSOCKET )
- {
- MYODBCINSWRITEDATASOURCESTR_DELIM;
-
- if ( !MYODBCInsInsertStr( pszStr, "SOCKET=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszSOCKET, nMaxLen, &nIndex
) )
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszSTMT )
- {
- MYODBCINSWRITEDATASOURCESTR_DELIM;
-
- if ( !MYODBCInsInsertStr( pszStr, "STMT=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszSTMT, nMaxLen, &nIndex )
)
- return MYODBC_C_FALSE;
- }
-
- if ( pDataSource->pszUSER )
- {
- MYODBCINSWRITEDATASOURCESTR_DELIM;
-
- if ( !MYODBCInsInsertStr( pszStr, "UID=", nMaxLen, &nIndex ) )
- return MYODBC_C_FALSE;
- if ( !MYODBCInsInsertStr( pszStr, pDataSource->pszUSER, nMaxLen, &nIndex )
)
- return MYODBC_C_FALSE;
- }
-
- if ( nDelim == MYODBC_INS_DELIM_NULL )
- {
- MYODBCINSWRITEDATASOURCESTR_DELIM;
- }
-
- return MYODBC_C_TRUE;
-}
-
-
Deleted: MYODBCIns/MYODBCInsLib/MYODBCInsWriteDriver.c
===================================================================
--- MYODBCIns/MYODBCInsLib/MYODBCInsWriteDriver.c 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/MYODBCInsLib/MYODBCInsWriteDriver.c 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,38 +0,0 @@
-/* Copyright (C) 2000-2004 MySQL AB
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- There are special exceptions to the terms and conditions of the GPL as it
- is applied to this software. View the full text of the exception in file
- EXCEPTIONS in the directory of this software distribution.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
-
-#include "MYODBCInsInternal.h"
-
-MYODBC_C_BOOL MYODBCInsWriteDriver( MYODBC_INS_DRIVER *pDriver )
-{
- if ( pDriver->pszName &&
- !SQLWritePrivateProfileString( pDriver->pszName, NULL, NULL, "ODBCINST.INI" )
)
- return MYODBC_C_FALSE;
- if ( pDriver->pszDRIVER &&
- !SQLWritePrivateProfileString( pDriver->pszName, "DRIVER",
pDriver->pszDRIVER, "ODBCINST.INI" ) )
- return MYODBC_C_FALSE;
- if ( pDriver->pszSETUP &&
- !SQLWritePrivateProfileString( pDriver->pszName, "SETUP",
pDriver->pszSETUP, "ODBCINST.INI" ) )
- return MYODBC_C_FALSE;
-
- return MYODBC_C_TRUE;
-}
-
-
Modified: MYODBCIns/include/MYODBCIns.h
===================================================================
--- MYODBCIns/include/MYODBCIns.h 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/include/MYODBCIns.h 2005-12-26 20:17:46 UTC (rev 16)
@@ -1,466 +1,9 @@
#ifndef MYODBC_INS_H
#define MYODBC_INS_H
-#include <MYODBCC.h>
+#include <MYODBCInsDriver.h>
+#include <MYODBCInsDataSource.h>
+#include <MYODBCInsDriverConnect.h>
-/*!
- \brief Delimiter type used for an attribute string.
-
-*/
-typedef enum tMYODBC_INS_DELIM
-{
- MYODBC_INS_DELIM_NULL,
- MYODBC_INS_DELIM_SEMI,
- MYODBC_INS_DELIM_BOTH
-
-} MYODBC_INS_DELIM;
-
-/*!
- \brief Driver fields.
-
- This reflects what we can have in odbcinst.ini.
-*/
-typedef struct tMYODBC_INS_DRIVER
-{
- char *pszName; /* Friendly name for driver. (ie "MySQL
ODBC 3.51 Driver") */
- char *pszDRIVER; /* File name - typically complete abs path. (ie
"/usr/lib/libmyodbc3.so") */
- char *pszSETUP; /* File name - typically complete abs path. (ie
"/usr/lib/libmyodbc3S.so") */
-
-} MYODBC_INS_DRIVER;
-
-/*!
- \internal
- \brief Driver pointer.
-
- This is for convenience and code clarity.
-*/
-typedef MYODBC_INS_DRIVER *MYODBC_INS_DRIVER_PTR;
-
-/*!
- \brief Driver connect method.
-
- Used to indicate what is being used to do
- a SQLDriverConnect.
-*/
-typedef enum tMYODBC_INS_DATASOURCE_CONNECT
-{
- MYODBC_INS_DATASOURCE_CONNECT_DRIVER,
- MYODBC_INS_DATASOURCE_CONNECT_DSN
-
-} MYODBC_INS_DATASOURCE_CONNECT;
-
-/*!
- \brief Prompting used during SQLDriverConnect.
-
- Could be a SQLUSMALLINT and then standard
- ODBC values such as SQL_DRIVER_PROMPT but there
- are worthwhile advantages to creating this type
- internally such as compiler validation of a
- switch/case and stricter type on func args and
- more understandable code etc.
-*/
-typedef enum tMYODBC_INS_DATASOURCE_PROMPT
-{
- MYODBC_INS_DATASOURCE_PROMPT_PROMPT,
- MYODBC_INS_DATASOURCE_PROMPT_COMPLETE,
- MYODBC_INS_DATASOURCE_PROMPT_REQUIRED,
- MYODBC_INS_DATASOURCE_PROMPT_NOPROMPT
-
-} MYODBC_INS_DATASOURCE_PROMPT;
-
-
-/*!
- \brief DSN edit mode.
-
- Reason why we have created a MYODBC_INS_DATASOURCE.
-*/
-typedef enum tMYODBC_INS_DATASOURCE_MODE
-{
- MYODBC_INS_DATASOURCE_MODE_DSN_ADD, /* For ConfigDSN() - ODBC_ADD_DSN.
*/
- MYODBC_INS_DATASOURCE_MODE_DSN_EDIT, /* For ConfigDSN() - ODBC_CONFIG_DSN.
*/
- MYODBC_INS_DATASOURCE_MODE_DSN_VIEW, /* For command-line tools to list DSN
details. */
- MYODBC_INS_DATASOURCE_MODE_DRIVER_CONNECT /* For SQLDriverConnect().
*/
-
-} MYODBC_INS_DATASOURCE_MODE;
-
-
-/*!
- \brief DSN fields.
-
- This reflects what we can have in odbc.ini.
-*/
-typedef struct tMYODBC_INS_DATASOURCE
-{
- char *pszDriverFileName; /* As used in DSN; often the abs path to driver.
(ie "/usr/lib/libmyodbc3.so") */
- char *pszDSN; /* The name of our data source.
(ie "test") */
- char *pszDRIVER; /* Friendly driver name as used in DSN and connect str.
(ie "MySQL ODBC 3.51 Driver (32 bit)") */
- char *pszDESCRIPTION; /* General description or long name of DSN.
*/
- char *pszSERVER; /* The hostname of the MySQL server.
*/
- char *pszUSER; /* The username used to connect to MySQL.
*/
- char *pszPASSWORD; /* The password for the server user combination.
*/
- char *pszDATABASE; /* The default database.
*/
- char *pszPORT; /* The TCP/IP port to use if SERVER is not localhost.
*/
- char *pszSOCKET; /* Unix socket file or Windows named pipe to connect to.
*/
- char *pszSTMT; /* Statement that will be exec when connecting to MySQL.
*/
- char *pszOPTION; /* Options that specify how MyODBC should work.
*/
-
-
- MYODBC_INS_DATASOURCE_MODE nMode; /* ConfigDSN mode or SQLDriverConnect
mode. */
- MYODBC_INS_DATASOURCE_CONNECT nConnect; /* SQLDriverConnect() using a DSN or a
DRIVER to connect. */
- MYODBC_INS_DATASOURCE_PROMPT nPrompt; /* SQLDriverConnect() kind of prompting
(if any). */
-
-} MYODBC_INS_DATASOURCE;
-
-/*!
- \internal
- \brief Data Source pointer.
-
- This is for convenience and code clarity.
-*/
-typedef MYODBC_INS_DATASOURCE *MYODBC_INS_DATASOURCE_PTR;
-
-#ifdef __cplusplus
-extern "C" {
#endif
-#ifdef __APPLE__
-int GetPrivateProfileString( LPCSTR lpszSection, LPCSTR lpszEntry, LPCSTR lpszDefault,
LPSTR lpszRetBuffer, int cbRetBuffer, LPCSTR lpszFilename );
-#endif
-
-/*!
- \brief Allocate and return a MYODBC_INS_DATASOURCE.
-
- Allocates, initializes and returns a MYODBC_INS_DATASOURCE
- structure.
-
- \param nMode Reason why we want to create a MYODBC_INS_DATASOURCE. This
- will influence the behaviour of the setup code if passed
- to the setup code to view/edit.
-
- \return A pointer to a viable MYODBC_INS_DATASOURCE.
-
- \sa MYODBCInsFreeDataSource
-*/
-MYODBC_INS_DATASOURCE *MYODBCInsAllocDataSource( MYODBC_INS_DATASOURCE_MODE nMode );
-
-/*!
- \brief Allocate and return a MYODBC_INS_DRIVER.
-
- Allocates, initializes and returns a MYODBC_INS_DRIVER
- structure.
-
- \return A pointer to a viable MYODBC_INS_DRIVER.
-
- \sa MYODBCInsFreeDriver
-*/
-MYODBC_INS_DRIVER *MYODBCInsAllocDriver();
-
-/*!
- \brief Reinitializes MYODBC_INS_DATASOURCE.
-
- Frees most of the values allocated within and inits to
- same defaults as when created.
-
- \note Does NOT reinit pszDriverFileName and pszDRIVER.
-
- \param pDataSource A pointer to a viable MYODBC_INS_DATASOURCE.
-
- \return void
-
- \sa MYODBCInsAllocDataSource MYODBCInsFreeDataSource
-*/
-void MYODBCInsClearDataSource( MYODBC_INS_DATASOURCE *pDataSource );
-
-/*!
- \brief Reinitializes MYODBC_INS_DRIVER.
-
- Frees the values allocated within and inits to
- same defaults as when created.
-
- \param pDriver A pointer to a viable MYODBC_INS_DRIVER.
-
- \return void
-
- \sa MYODBCInsAllocDriver MYODBCInsFreeDriver
-*/
-void MYODBCInsClearDriver( MYODBC_INS_DRIVER *pDriver );
-
-/*!
- \brief Set NULL values to default value.
-
- The default values have been gleaned from pre-existing
- code in connect.c but there are some inconsistencies
- between SQLConnect and SQLDriverConnect so I assume that
- mysql_real_connect is smarter than it used to be.
-
- \todo This needs to be cleaned up such that it reflects what is
- really needed.
-
- \return MYODBC_C_BOOL
-
- \retval MYODBC_C_TRUE Success.
- \retval MYODBC_C_FALSE Failure.
-*/
-MYODBC_C_BOOL MYODBCInsDefaultDataSource( MYODBC_INS_DATASOURCE *pDataSource );
-
-/*!
- \brief Checks to see if a DSN exists in the ODBC system
- information.
-
- This function uses the current SQLSetConfigMode() to check
- if the given DSN exists.
-
- \param pszDataSourceName The DSN to look for.
-
- \return MYODBC_C_TRUE If found.
- MYODBC_C_FALSE If not found.
-*/
-MYODBC_C_BOOL MYODBCInsDSNExists( char *pszDataSourceName );
-
-/*!
- \brief Free memory used by MYODBC_INS_DATASOURCE.
-
- Frees all resources used by the given MYODBC_INS_DATASOURCE.
-
- \param pDataSource Pointer to a viable MYODBC_INS_DATASOURCE.
-
- \return void
-
- \sa MYODBCInsAllocDataSource
-*/
-void MYODBCInsFreeDataSource( MYODBC_INS_DATASOURCE *pDataSource );
-
-/*!
- \brief Free memory used by MYODBC_INS_DRIVER.
-
- Frees all resources used by the given MYODBC_INS_DRIVER.
-
- \param pDriver Pointer to a viable MYODBC_INS_DRIVER.
-
- \return void
-
- \sa MYODBCInsAllocDriver
-*/
-void MYODBCInsFreeDriver( MYODBC_INS_DRIVER *pDriver );
-
-/*!
- \brief Put a list of existing data source names in pszBuffer.
-
- Gets a list of data source names within the given scope
- while handling platform specific issues.
-
- \note OSX
-
- SQLGetPrivateProfileString() is broken but fortunately
- the old GetPrivateProfileString() is available and seems
- to work fine.
-
- \note XP
-
- SQLGetPrivateProfileString() with a NULL 1st arg does
- not return anything - ever. This is contrary to the
- specification :(
-
- Using SQLDataSources() is not a real option here as we
- would need to be calling into the DM for that and we
- are supposed to be below the DM in the depend hierarchy.
-
- So we use the deprecated precursor to
- SQLGetPrivateProfileString().
-
- GetPrivateProfileString() is not aware of changes to the way
- ODBC system information is stored so we get stuff like
- "ODBC 32 bit Data Sources" list as a datasource. It also
- appears to be unaware of User vs System DSN.
-
- \param pszBuffer A buffer to hold the results. The results will
- be a serious of null terminated string with
- last result terminated with an extra null.
- \param nBuffer Amount of space in pszBuffer.
- \param nScope ODBC_BOTH_DSN, ODBC_USER_DSN, or ODBC_SYSTEM_DSN.
-
-
- \return MYODBC_C_TRUE If success.
- MYODBC_C_FALSE If failed.
-
- \sa MYODBCInsGetDriverNames
-*/
-MYODBC_C_BOOL MYODBCInsGetDataSourceNames( char *pszBuffer, int nBuffer, UWORD nScope );
-
-/*!
- \brief Put a list of installed drivers in pszBuffer.
-
- Gets a list of registered drivers while handling
- platform specific issues.
-
- \note OSX
-
- SQLGetPrivateProfileString() is broken but fortunately
- the old GetPrivateProfileString() is available.
-
- \note XP
-
- SQLGetPrivateProfileString() with a NULL 1st arg does
- not return anything - ever. To return a list of drivers
- we can use SQLGetInstalledDrivers() instead.
-
- \param pszBuffer A buffer to hold the results. The results will
- be a serious of null terminated string with
- last result terminated with an extra null.
- \param nBuffer Amount of space in pszBuffer.
-
- \return MYODBC_C_TRUE If success.
- MYODBC_C_FALSE If failed.
-
- \sa MYODBCInsGetDataSourceNames
-*/
-MYODBC_C_BOOL MYODBCInsGetDriverNames( char *pszBuffer, int nBuffer );
-
-/*!
- \brief Parse a string of "name=value" pairs.
-
- SQLDriverConnect receives connection information
- as a list of attributes in the form of keyword-value pairs. Each
- pair is terminated with a ';', and the entire list is
- terminated with a '\0'.
-
- \note This will not replace existing values in pDataSource.
-
- \param pDataSource Destination - a viable MYODBC_INS_DATASOURCE.
- \param pszStr Source - name=value string.
-
- \return MYODBC_C_TRUE Upon success.
- MYODBC_C_FALSE Upon failure.
-
- \sa MYODBCInsWriteConnectStr
-*/
-MYODBC_C_BOOL MYODBCInsReadConnectStr( MYODBC_INS_DATASOURCE *pDataSource, LPCSTR pszStr
);
-
-/*!
- \brief Read data source from system information.
-
- \note This will not replace existing values in pDataSource.
-
- On XP we use hard-coded driver name and driver
- file name (if not given) as it seems MS is in the middle
- of changing odbc system info (probably to better support
- 64 bit).
-
- \param pDataSource Data Source struct.
- \param pszDSN The data source name to lookup.
-
- \return MYODBC_C_TRUE If success.
- MYODBC_C_FALSE If failed.
-
- \sa MYODBCInsWriteDataSource
-*/
-MYODBC_C_BOOL MYODBCInsReadDataSource( MYODBC_INS_DATASOURCE *pDataSource, LPCSTR pszDSN
);
-
-/*!
- \brief Parse a string of "name=value" pairs.
-
- ConfigDSN receives connection information from the installer DLL
- as a list of attributes in the form of keyword-value pairs.
-
- \note This will not replace existing values in pDataSource.
-
- \note Linux
-
- In some cases on unixODBC a semi-colon will be used
- to indicate the end of name/value pair. This is like
- in SQLDriverConnect(). This is incorrect but we try
- to simply ignore semi-colon and hope rest of format
- is ok.
-
- \param pDataSource Destination - a viable MYODBC_INS_DATASOURCE.
- \param nDelim Type of delimiter used between the name=value pairs.
- One of the following; MYODBC_INS_DELIM_NULL,
- MYODBC_INS_DELIM_SEMI, or MYODBC_INS_DELIM_BOTH.
- \param pszStr Source - name=value string.
-
- \return MYODBC_C_TRUE Upon success.
- MYODBC_C_FALSE Upon failure.
-
- \sa MYODBCInsWriteDataSourceStr
-*/
-MYODBC_C_BOOL MYODBCInsReadDataSourceStr( MYODBC_INS_DATASOURCE *pDataSource,
MYODBC_INS_DELIM nDelim, LPCSTR pszStr );
-
-/*!
- \brief Read driver from system information.
-
- Fetchs the driver details from the odbc system information.
-
- \note This will not replace existing values in pDriver.
-
- \param pDriver Pointer to a viable MYODBC_INS_DRIVER.
- \param pszName User friendly name of driver such as "MySQL ODBC 3.51 Driver (32
bit)"
-
- \return MYODBC_C_TRUE If success.
- MYODBC_C_FALSE If failed.
-
- \sa MYODBCInsWriteDriver
-*/
-MYODBC_C_BOOL MYODBCInsReadDriver( MYODBC_INS_DRIVER *pDriver, LPCSTR pszName );
-
-/*!
- \brief Formulates a connection string reflecting any user modifications.
-
- The string can be used to pass back to SQLDriverConnect.
-
- \param pDataSource Source - a pointer to a viable MYODBC_INS_DATASOURCE.
- \param pszStr Destination - a pointer to a buffer with nMaxLen.
- \param nMaxLen Max len we can put into pszStr.
-
- \return MYODBC_C_TRUE Upon success.
- MYODBC_C_FALSE Upon failure.
-
- \sa MYODBCInsReadConnectStr
-*/
-MYODBC_C_BOOL MYODBCInsWriteConnectStr( MYODBC_INS_DATASOURCE *pDataSource, char *pszStr,
SQLSMALLINT nMaxLen );
-
-/*!
- \brief Creates/replaces the given data source.
-
- The use of SQLWriteDSNToIni() means this function
- does not really update an existing DSN so much as
- replaces it.
-
- \param pDataSource A pointer to viable MYODBC_INS_DATASOURCE - the
- values of which will be written to the system
- ODBC information.
-
- \return MYODBC_C_TRUE If success.
- MYODBC_C_FALSE If failed.
-
- \sa MYODBCInsReadDataSource
-*/
-MYODBC_C_BOOL MYODBCInsWriteDataSource( MYODBC_INS_DATASOURCE *pDataSource );
-
-/*!
- \brief Creates/replaces the given driver registration.
-
- This should not be used for general register/deregister
- driver tasks - use SQLInstallDriverEx() and SQLRemoveDriver()
- for that.
-
- Use this when you want a more rudementary method to play with
- the driver registration.
-
- \note If section pDriver->pszName does not exist it will be created
- otherwise it is updated.
-
- \param pDriver A pointer to a viable MYODBC_INS_DRIVER.
-
- \return MYODBC_C_TRUE If success.
- MYODBC_C_FALSE If failed.
-
- \sa MYODBCInsReadDriver
-*/
-MYODBC_C_BOOL MYODBCInsWriteDriver( MYODBC_INS_DRIVER *pDriver );
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
Added: MYODBCIns/include/MYODBCInsDataSource.h
===================================================================
--- MYODBCIns/include/MYODBCInsDataSource.h 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/include/MYODBCInsDataSource.h 2005-12-26 20:17:46 UTC (rev 16)
@@ -0,0 +1,104 @@
+#ifndef MYODBC_INS_DATASOURCE_H
+#define MYODBC_INS_DATASOURCE_H
+
+#include <MYODBCC.h>
+
+#include <QString>
+#include <QStringList>
+#include <QTextStream>
+
+/*!
+ \brief DSN edit mode.
+
+ Reason why we have created a MYODBC_INS_DATASOURCE.
+*/
+typedef enum tMYODBC_INS_DATASOURCE_MODE
+{
+ MYODBC_INS_DATASOURCE_MODE_DSN_ADD, /* For ConfigDSN() - ODBC_ADD_DSN.
*/
+ MYODBC_INS_DATASOURCE_MODE_DSN_EDIT, /* For ConfigDSN() - ODBC_CONFIG_DSN.
*/
+ MYODBC_INS_DATASOURCE_MODE_DSN_VIEW, /* For command-line tools to list DSN
details. */
+ MYODBC_INS_DATASOURCE_MODE_CONNECT /* For SQLDriverConnect().
*/
+
+} MYODBC_INS_DATASOURCE_MODE;
+
+typedef enum tMYODBC_INS_DATASOURCE_SCOPE
+{
+ MYODBC_INS_DATASOURCE_SCOPE_BOTH = ODBC_BOTH_DSN,
+ MYODBC_INS_DATASOURCE_SCOPE_USER = ODBC_USER_DSN,
+ MYODBC_INS_DATASOURCE_SCOPE_SYSTEM = ODBC_SYSTEM_DSN
+
+} MYODBC_INS_DATASOURCE_SCOPE;
+
+class MYODBCInsDataSource
+{
+public:
+ MYODBCInsDataSource( MYODBC_INS_DATASOURCE_MODE nMode =
MYODBC_INS_DATASOURCE_MODE_CONNECT );
+
+ bool setDriverFileName( const QString &stringDriverFileName );
+ bool setDSN( const QString &stringDSN );
+ bool setDRIVER( const QString &stringDRIVER );
+ bool setDESCRIPTION( const QString &stringDESCRIPTION );
+ bool setSERVER( const QString &stringSERVER );
+ bool setUSER( const QString &stringUSER );
+ bool setPASSWORD( const QString &stringPASSWORD );
+ bool setDATABASE( const QString &stringDATABASE );
+ bool setPORT( const QString &stringPORT );
+ bool setSOCKET( const QString &stringSOCKET );
+ bool setSTMT( const QString &stringSTMT );
+ bool setOPTION( const QString &stringOPTION );
+ bool setMode( MYODBC_INS_DATASOURCE_MODE nMode );
+ bool setScope( MYODBC_INS_DATASOURCE_SCOPE nScope );
+
+ QString getDriverFileName();
+ QString getDSN();
+ QString getDRIVER();
+ QString getDESCRIPTION();
+ QString getSERVER();
+ QString getUSER();
+ QString getPASSWORD();
+ QString getDATABASE();
+ QString getPORT();
+ QString getSOCKET();
+ QString getSTMT();
+ QString getOPTION();
+ MYODBC_INS_DATASOURCE_MODE getMode();
+ MYODBC_INS_DATASOURCE_SCOPE getScope();
+ static QStringList getDataSourceNames( MYODBC_INS_DATASOURCE_SCOPE nScope );
+
+ static bool isExistsDataSourceName( const QString &stringDataSourceName,
MYODBC_INS_DATASOURCE_SCOPE nScope );
+
+ bool doRead( const QString &stringDataSourceName, MYODBC_INS_DATASOURCE_SCOPE
nScope );
+ bool doRead( const QString &stringDataSourceName );
+ bool doRead();
+ bool doWrite( MYODBC_INS_DATASOURCE_SCOPE nScope );
+ bool doWrite();
+ void doClear();
+
+ MYODBCInsDataSource operator=( MYODBCInsDataSource rval );
+ QTextStream &operator<<( MYODBCInsDataSource rval );
+
+protected:
+ /*!
+ \brief DSN fields.
+
+ This reflects what we can have in odbc.ini.
+ */
+ QString stringDriverFileName; /* As used in DSN; often the abs path to driver.
(ie "/usr/lib/libmyodbc3.so") */
+ QString stringDSN; /* The name of our data source.
(ie "test") */
+ QString stringDRIVER; /* Friendly driver name as used in DSN and connect
str. (ie "MySQL ODBC 3.51 Driver (32 bit)") */
+ QString stringDESCRIPTION; /* General description or long name of DSN.
*/
+ QString stringSERVER; /* The hostname of the MySQL server.
*/
+ QString stringUSER; /* The username used to connect to MySQL.
*/
+ QString stringPASSWORD; /* The password for the server user combination.
*/
+ QString stringDATABASE; /* The default database.
*/
+ QString stringPORT; /* The TCP/IP port to use if SERVER is not
localhost. */
+ QString stringSOCKET; /* Unix socket file or Windows named pipe to connect
to. */
+ QString stringSTMT; /* Statement that will be exec when connecting to
MySQL. */
+ QString stringOPTION; /* Options that specify how MyODBC should work.
*/
+
+ MYODBC_INS_DATASOURCE_MODE nMode;
+ MYODBC_INS_DATASOURCE_SCOPE nScope;
+};
+
+#endif
+
Added: MYODBCIns/include/MYODBCInsDriver.h
===================================================================
--- MYODBCIns/include/MYODBCInsDriver.h 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/include/MYODBCInsDriver.h 2005-12-26 20:17:46 UTC (rev 16)
@@ -0,0 +1,41 @@
+#ifndef MYODBC_INS_DRIVER_H
+#define MYODBC_INS_DRIVER_H
+
+#include <MYODBCC.h>
+#include <QString>
+#include <QStringList>
+#include <QTextStream>
+
+
+class MYODBCInsDriver
+{
+public:
+ bool setFriendlyName( const QString &stringFriendlyName );
+ bool setDRIVER( const QString &stringDriverFileName );
+ bool setSETUP( const QString &stringSetupFileName );
+
+ QString getFriendlyName();
+ QString getDRIVER();
+ QString getSETUP();
+ static QStringList getDriverNames();
+
+ bool doRead( const QString &stringFriendlyName );
+ bool doWrite();
+ void doClear();
+
+ MYODBCInsDriver operator=( MYODBCInsDriver rval );
+ QTextStream &operator<<( MYODBCInsDriver rval );
+
+protected:
+ /*!
+ \brief Driver fields.
+
+ This reflects what we can have in odbcinst.ini.
+ */
+ QString stringFriendlyName; /* Friendly name for driver. (ie
"MySQL ODBC 3.51 Driver") */
+ QString stringDRIVER; /* File name - typically complete abs path. (ie
"/usr/lib/libmyodbc3.so") */
+ QString stringSETUP; /* File name - typically complete abs path. (ie
"/usr/lib/libmyodbc3S.so") */
+};
+
+#endif
+
Added: MYODBCIns/include/MYODBCInsDriverConnect.h
===================================================================
--- MYODBCIns/include/MYODBCInsDriverConnect.h 2005-12-24 20:12:29 UTC (rev 15)
+++ MYODBCIns/include/MYODBCInsDriverConnect.h 2005-12-26 20:17:46 UTC (rev 16)
@@ -0,0 +1,82 @@
+#ifndef MYODBC_INS_DRIVERCONNECT_H
+#define MYODBC_INS_DRIVERCONNECT_H
+
+#include "MYODBCInsDataSource.h"
+
+/*!
+ \brief Delimiter type used for an attribute string.
+
+*/
+typedef enum tMYODBC_INS_DELIM
+{
+ MYODBC_INS_DELIM_NULL,
+ MYODBC_INS_DELIM_SEMI,
+ MYODBC_INS_DELIM_BOTH
+
+} MYODBC_INS_DELIM;
+
+/*!
+ \brief Driver connect method.
+
+ Used to indicate what is being used to do
+ a SQLDriverConnect.
+*/
+typedef enum tMYODBC_INS_DRIVERCONNECT_METHOD
+{
+ MYODBC_INS_DRIVERCONNECT_METHOD_DRIVER,
+ MYODBC_INS_DRIVERCONNECT_METHOD_DSN
+
+} MYODBC_INS_DRIVERCONNECT_METHOD;
+
+/*!
+ \brief Prompting used during SQLDriverConnect.
+
+ Could be a SQLUSMALLINT and then standard
+ ODBC values such as SQL_DRIVER_PROMPT but there
+ are worthwhile advantages to creating this type
+ internally such as compiler validation of a
+ switch/case and stricter type on func args and
+ more understandable code etc.
+*/
+typedef enum tMYODBC_INS_DRIVERCONNECT_PROMPT
+{
+ MYODBC_INS_DRIVERCONNECT_PROMPT_PROMPT,
+ MYODBC_INS_DRIVERCONNECT_PROMPT_COMPLETE,
+ MYODBC_INS_DRIVERCONNECT_PROMPT_REQUIRED,
+ MYODBC_INS_DRIVERCONNECT_PROMPT_NOPROMPT
+
+} MYODBC_INS_DRIVERCONNECT_PROMPT;
+
+
+class MYODBCInsDriverConnect : public MYODBCInsDataSource
+{
+public:
+ MYODBCInsDriverConnect( MYODBC_INS_DRIVERCONNECT_METHOD nConnectMethod =
MYODBC_INS_DRIVERCONNECT_METHOD_DRIVER,
+ MYODBC_INS_DRIVERCONNECT_PROMPT nPrompt =
MYODBC_INS_DRIVERCONNECT_PROMPT_NOPROMPT );
+
+ bool setConnectString( const QString &stringConnectString );
+ bool setConnectMethod( MYODBC_INS_DRIVERCONNECT_METHOD nConnectMethod );
+ bool setPrompt( MYODBC_INS_DRIVERCONNECT_PROMPT nPrompt );
+
+ QString getConnectString();
+ MYODBC_INS_DRIVERCONNECT_METHOD getConnectMethod();
+ MYODBC_INS_DRIVERCONNECT_PROMPT getPrompt();
+
+protected:
+ bool setMode( MYODBC_INS_DATASOURCE_MODE ) { return false; }
+ bool setScope( MYODBC_INS_DATASOURCE_SCOPE ) { return false; }
+
+ MYODBC_INS_DATASOURCE_MODE getMode() { return nMode; }
+ MYODBC_INS_DATASOURCE_SCOPE getScope() { return nScope; }
+
+ bool doWrite( MYODBC_INS_DATASOURCE_SCOPE ) { return false; }
+ bool doWrite() { return false; }
+ void doClear() {}
+
+ MYODBC_INS_DRIVERCONNECT_METHOD nConnectMethod; /* SQLDriverConnect() using a DSN or
a DRIVER to connect. */
+ MYODBC_INS_DRIVERCONNECT_PROMPT nPrompt; /* SQLDriverConnect() kind of
prompting (if any). */
+};
+
+
+#endif
+
Modified: root.pro
===================================================================
--- root.pro 2005-12-24 20:12:29 UTC (rev 15)
+++ root.pro 2005-12-26 20:17:46 UTC (rev 16)
@@ -57,3 +57,4 @@
# MYODBCInstaller \
# MYODBCShell
+
| Thread |
|---|
| • Connector/ODBC 5 commit: r16 - / MYODBCIns MYODBCIns/MYODBCInsLib MYODBCIns/include | pharvey | 26 Dec |