List:Commits« Previous MessageNext Message »
From:pharvey Date:February 28 2007 1:44pm
Subject:Connector/ODBC 5 commit: r806 - trunk/Driver/Setup/Library
View as plain text  
Added:
   trunk/Driver/Setup/Library/ConfigDSN.cpp
Log:
- unixODBC does not, yet, support ConfigDSNW so we need to implement
  ConfigDSN (as single-byte)
- started to implement this on linux and decided to toss the work thus
  far in favour of sorting this out on win32 first


Added: trunk/Driver/Setup/Library/ConfigDSN.cpp
===================================================================
--- trunk/Driver/Setup/Library/ConfigDSN.cpp	2007-02-21 19:53:56 UTC (rev 805)
+++ trunk/Driver/Setup/Library/ConfigDSN.cpp	2007-02-28 13:44:21 UTC (rev 806)
@@ -0,0 +1,159 @@
+/*! 
+    \file     ConfigDSN.cpp
+    \author   Peter Harvey <pharvey@stripped>
+              Copyright MySQL AB 2004-2007 Released under GPL.
+    \version  Connector/ODBC v5
+    \date       2007
+    \brief    Contains the ConfigDSN entry point.
+    \internal License  
+
+              Copyright (C) 2004-2007 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 "MYODBCSetup.h"
+
+/*!
+    \brief  Add, edit, or remove a Data Source Name (DSN).
+
+            This function should be called from the ODBC Administrator
+            program when our driver is being used during a request to
+            add, edit or remove a DSN. This allows us to do driver 
+            specific stuff such as use our dialogs to work with our
+            driver.
+
+            This function is also a viable entry point and a public API
+            for use by special function code such as an installer or an
+            application which has embedded the driver functionality.
+
+    \param  hWnd            Window handle to use as the parent window for any dialogs
this function may
+                            invoke to support the request.
+    \param  nRequest        The type of request; 
+                                - ODBC_ADD_DSN
+                                - ODBC_CONFIG_DSN
+                                - ODBC_REMOVE_DSN
+    \param  pszDriver       Friendly driver name such as "MySQL Connector/ODBC v5".
+    \param  pszAttributes   A list of key-value (KEY=VALUE) pairs where each key-value
pair is delimited by a 
+                            null (including the last one) and the entire list is
terminated by a null (so list
+                            ends with 2 nulls).
+
+    \return BOOL
+
+    \retval TRUE            Request succeeded.
+    \retval FALSE           Request failed for some reason - caller can use
SQLInstallerError() to get details.
+*/  
+BOOL INSTAPI ConfigDSN( HWND hWnd, WORD nRequest, LPCSTR pszDriver, LPCSTR pszzAttributes
)
+{
+    MYODBCDbgEnter();
+
+    BOOL bReturn = true;
+
+    /*!
+        \internal ODBC RULE
+
+        ConfigDSN receives connection information from the installer DLL as a list of 
+        attributes in the form of keyword-value pairs. Each pair is terminated with a 
+        null byte, and the entire list is terminated with a null byte.
+    */
+    QHash<QString,QString> hashKeywordValues;
+    if ( !MYODBCIns::getKeywordValues( &hashKeywordValues, pszzAttributes,
MYODBCIns::DELIM_NULL ) )
+    {
+        MYODBCIns::setError( "Data Source string seems invalid.",
ODBC_ERROR_INVALID_KEYWORD_VALUE );
+        MYODBCDbgReturn3( "%d", false );
+    }
+
+    /* get keyword-values into our datasource object */
+    MYODBCInsDataSource datasource;
+    if ( !datasource.setAttributes( hashKeywordValues, true, false ) )
+        MYODBCDbgReturn3( "%d", false );
+
+    datasource.setDRIVER( pszDriver );
+
+    /*!
+        \internal ODBC RULE
+
+        Driver description (usually the name of the associated DBMS) presented to users 
+        instead of the physical driver name.
+    */  
+    if ( datasource.getDRIVER().isEmpty() )
+    {
+        MYODBCIns::setError( "Need driver name (DRIVER)." );
+        MYODBCDbgReturn3( "%d", false );
+    }
+
+    /* process request */
+    switch ( nRequest )
+    {
+        case ODBC_ADD_DSN:
+            datasource.setMode( MYODBCInsDataSource::DATASOURCE_MODE_DSN_ADD );
+            if ( MYODBCSetupDataSourceConfig( hWnd, &datasource ) )
+            {
+                if ( !datasource.doWrite() )
+                    MYODBCDbgReturn3( "%d", false );
+            }
+            break;
+
+        case ODBC_CONFIG_DSN:
+            datasource.setMode( MYODBCInsDataSource::DATASOURCE_MODE_DSN_EDIT );
+
+            if ( !datasource.doRead() )
+                MYODBCDbgReturn3( "%d", false );
+
+            if ( MYODBCSetupDataSourceConfig( hWnd, &datasource ) )
+            {
+                if ( !datasource.doWrite() )
+                    MYODBCDbgReturn3( "%d", false );
+            }
+            break;
+
+        case ODBC_REMOVE_DSN:
+            /*!
+                \internal ODBC RULE
+
+                To delete a data source, a data source name must be passed to ConfigDSN
in lpszAttributes.
+            */
+            if ( datasource.getName().isEmpty() )
+            {
+                MYODBCIns::setError( "Need data source name (DSN)." );
+                MYODBCDbgReturn3( "%d", false );
+            }
+            /*!
+                \internal ODBC RULE
+
+                ConfigDSN checks that the data source name is in the Odbc.ini file (or
registry).
+            */
+            if ( !MYODBCIns::isExistsDataSourceName( datasource.getName(),
datasource.getScope() ) )
+            {
+                MYODBCIns::setError( "Failed to find data source name." );
+                MYODBCDbgReturn3( "%d", false );
+            }
+            /* delete it */
+            bReturn = MYODBCInsDataSource::doDelete( datasource.getName() );
+            break;
+
+        default:
+            MYODBCIns::setError( "Invalid request.", ODBC_ERROR_INVALID_REQUEST_TYPE );
+            MYODBCDbgReturn3( "%d", false );
+    }
+
+    MYODBCDbgReturn3( "%d", bReturn );
+}     
+
+
+

Thread
Connector/ODBC 5 commit: r806 - trunk/Driver/Setup/Librarypharvey28 Feb