Added:
trunk/Driver/Setup/Library/ConfigDSNW.c
trunk/SDK/Installer/Library/installer.c
trunk/SDK/Installer/include/installer.h
trunk/Tools/Installer/MYODBCInstaller.c
Removed:
trunk/Driver/Setup/Library/ConfigDSNW.cpp
trunk/Driver/Setup/Library/MYODBCSetupDriverConnect.cpp
trunk/SDK/Installer/Library/MYODBCIns.cpp
trunk/SDK/Installer/Library/MYODBCInsDataSource.cpp
trunk/SDK/Installer/Library/MYODBCInsDriver.cpp
trunk/SDK/Installer/Library/MYODBCInsDriverConnect.cpp
trunk/SDK/Installer/Library/MYODBCInsInternal.h
trunk/SDK/Installer/include/MYODBCIns.h
trunk/SDK/Installer/include/MYODBCInsDataSource.h
trunk/SDK/Installer/include/MYODBCInsDriver.h
trunk/SDK/Installer/include/MYODBCInsDriverConnect.h
trunk/Tools/Installer/MYODBCInstaller.cpp
trunk/Tools/Installer/MYODBCInstaller.h
trunk/Tools/Installer/main.cpp
Modified:
trunk/Driver/Driver/Library/MYODBCDriverInternal.h
trunk/Driver/Setup/Library/Library.pro
trunk/Driver/Setup/Library/MYODBCSetup.def
trunk/Driver/Setup/Library/MYODBCSetup.h
trunk/Driver/Setup/Library/MYODBCSetupDataSourceConfig.cpp
trunk/Driver/Setup/Library/MYODBCSetupDataSourceDialog.cpp
trunk/Driver/Setup/Library/MYODBCSetupDataSourceDialog.h
trunk/SDK/C/Library/MYODBCC.cpp
trunk/SDK/C/include/MYODBCC.h
trunk/SDK/Installer/Library/Library.pro
trunk/SDK/Installer/Tests/MYODBCInsTest.cpp
trunk/SDK/MYSQLPlus/Library/MConnection.cpp
trunk/SDK/MYSQLPlus/Library/MResultPlus.cpp
trunk/SDK/MYSQLPlus/Tests/MYSQLPlusTest.cpp
trunk/SDK/MYSQLPlus/include/M.h
trunk/SDK/MYSQLPlus/include/MConnection.h
trunk/Tools/Installer/Installer.pro
Log:
added QT_NODLL to fix inline+debug+dll link issue in Driver/Setup/Library/Library.pro
cleaned up MYODBCIns library
Modified: trunk/Driver/Driver/Library/MYODBCDriverInternal.h
===================================================================
--- trunk/Driver/Driver/Library/MYODBCDriverInternal.h 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/Driver/Driver/Library/MYODBCDriverInternal.h 2007-05-22 18:47:33 UTC (rev 925)
@@ -30,7 +30,6 @@
#define MYODBC_DRV_INTERNAL_H
#include <MYODBCC.h>
-#include <MYODBCIns.h>
#include <M.h>
#include "../include/MYODBCDriver.h"
Added: trunk/Driver/Setup/Library/ConfigDSNW.c
===================================================================
--- trunk/Driver/Setup/Library/ConfigDSNW.c 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/Driver/Setup/Library/ConfigDSNW.c 2007-05-22 18:47:33 UTC (rev 925)
@@ -0,0 +1,99 @@
+/*!
+ \file ConfigDSNW.cpp
+ \author Jess Balint <jbalint@stripped>
+ Copyright MySQL AB 2004-2007 Released under GPL.
+ \version Connector/ODBC v5
+ \date 2007
+ \brief Contains the ConfigDSNW 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"
+
+BOOL INSTAPI ConfigDSNW(HWND wnd, WORD req, LPCWSTR driver, LPCWSTR attrs)
+{
+ BOOL rc = TRUE;
+ DataSource *ds = ds_new();
+ int found = 0;
+ int mode = 0;
+
+ if(ds_from_kvpair(ds, attrs, 0))
+ {
+ SQLPostInstallerError(ODBC_ERROR_INVALID_KEYWORD_VALUE,
+ "Cannot parse attribute string");
+ goto end;
+ }
+
+ ds_set_strattr(&ds->driver, driver);
+
+ /* try to lookup a datasource */
+ if((found = ds_lookup(ds)) > 0)
+ {
+ /* any >0 error will be an installer API error */
+ rc = FALSE;
+ goto end;
+ }
+
+ /* 0 means found, invert it */
+ found = !found;
+
+ switch(req)
+ {
+ /* edit a DSN */
+ case ODBC_CONFIG_DSN:
+ if(!found)
+ {
+ rc = FALSE;
+ goto end;
+ }
+ /* pass down, to "add" which will replace current contents.
+ * reset 'found' so it won't prompt to replace. */
+ found = 0;
+
+ mode = CONFIG_EDIT;
+ /* TODO handle if they rename it? delete the old one.. */
+ case ODBC_ADD_DSN:
+ if(!wnd || !MYODBCSetupDataSourceConfig(wnd, ds, mode || CONFIG_ADD))
+ {
+ rc = FALSE;
+ goto end;
+ }
+
+ if(ds_add(ds))
+ {
+ rc = FALSE;
+ goto end;
+ }
+ break;
+ case ODBC_REMOVE_DSN:
+ rc = SQLRemoveDSNFromIni(ds->name);
+ break;
+ default:
+ SQLPostInstallerError(ODBC_ERROR_INVALID_REQUEST_TYPE,
+ "Invalid request type");
+ rc = FALSE;
+ }
+
+end:
+ return rc;
+}
+
Deleted: trunk/Driver/Setup/Library/ConfigDSNW.cpp
===================================================================
--- trunk/Driver/Setup/Library/ConfigDSNW.cpp 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/Driver/Setup/Library/ConfigDSNW.cpp 2007-05-22 18:47:33 UTC (rev 925)
@@ -1,171 +0,0 @@
-/*!
- \file ConfigDSNW.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 ConfigDSNW( HWND hWnd, WORD nRequest, LPCWSTR pszDriver, LPCWSTR
pszzAttributes )
-{
- DBUG_ENTER("ConfigDSNW");
-
- 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,
-
MYODBCCString::QString_fromWCharArray(pszzAttributes,
-
MYODBCCMap::getKeywordValuesLength(pszzAttributes) + 2),
- MYODBCIns::DELIM_NULL))
- {
- MYODBCIns::setError( "Data Source string seems invalid.",
ODBC_ERROR_INVALID_KEYWORD_VALUE );
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- /* get keyword-values into our datasource object */
- MYODBCInsDataSource datasource;
- if ( !datasource.setAttributes( hashKeywordValues, true, false ) )
- {
- bReturn = false;
- goto end;
- }
-
- datasource.setDRIVER(MYODBCCString::QString_fromWCharArray(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)." );
- bReturn = false;
- goto end;
- }
-
- /* process request */
- switch ( nRequest )
- {
- case ODBC_ADD_DSN:
- datasource.setMode( MYODBCInsDataSource::DATASOURCE_MODE_DSN_ADD );
- if ( MYODBCSetupDataSourceConfig( hWnd, &datasource ) )
- if ( !datasource.doWrite() )
- bReturn = false;
- break;
-
- case ODBC_CONFIG_DSN:
- datasource.setMode( MYODBCInsDataSource::DATASOURCE_MODE_DSN_EDIT );
-
- if ( !datasource.doRead() )
- {
- bReturn = false;
- break;
- }
-
- if ( MYODBCSetupDataSourceConfig( hWnd, &datasource ) )
- if ( !datasource.doWrite() )
- bReturn = 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)." );
- bReturn = false;
- break;
- }
- /*!
- \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." );
- bReturn = false;
- break;
- }
- /* delete it */
- bReturn = MYODBCInsDataSource::doDelete( datasource.getName() );
- break;
-
- default:
- MYODBCIns::setError( "Invalid request.", ODBC_ERROR_INVALID_REQUEST_TYPE );
- bReturn = false;
- break;
- }
-
-end:
- DBUG_PRINT("oreturn", ("%d", bReturn));
- DBUG_RETURN(bReturn);
-}
-
-
-
Modified: trunk/Driver/Setup/Library/Library.pro
===================================================================
--- trunk/Driver/Setup/Library/Library.pro 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/Driver/Setup/Library/Library.pro 2007-05-22 18:47:33 UTC (rev 925)
@@ -32,6 +32,7 @@
RC_FILE = MYODBCSetup.rc
libraries.path = /windows/system32
libraries.files = MYODBCSetup5.dll
+ DEFINES += QT_NODLL
}
win32-msvc2005 {
@@ -52,9 +53,8 @@
MYODBCSetupDataSourceTab1.h
SOURCES = \
ConfigDSN.cpp \
- ConfigDSNW.cpp \
+ ConfigDSNW.c \
MYODBCSetupDataSourceConfig.cpp \
- MYODBCSetupDriverConnect.cpp \
MYODBCSetupDataSourceDialog.cpp \
MYODBCSetupDataSourceTab1.cpp
Modified: trunk/Driver/Setup/Library/MYODBCSetup.def
===================================================================
--- trunk/Driver/Setup/Library/MYODBCSetup.def 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/Driver/Setup/Library/MYODBCSetup.def 2007-05-22 18:47:33 UTC (rev 925)
@@ -3,9 +3,3 @@
;
ConfigDSNW
MYODBCSetupDataSourceConfig
-MYODBCSetupDriverConnect
-
-
-
-
-
Modified: trunk/Driver/Setup/Library/MYODBCSetup.h
===================================================================
--- trunk/Driver/Setup/Library/MYODBCSetup.h 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/Driver/Setup/Library/MYODBCSetup.h 2007-05-22 18:47:33 UTC (rev 925)
@@ -29,35 +29,40 @@
#ifndef MYODBCSETUP_H
#define MYODBCSETUP_H
-#include <QApplication>
-#include <QColor>
-#include <QDialog>
-#include <QLayout>
-#include <QLabel>
-#include <QPushButton>
-#include <QSplitter>
-#include <QMessageBox>
-#include <QTextBrowser>
-#include <QTextEdit>
-#include <QTabWidget>
-#include <QProcess>
-#include <QToolTip>
-
-#include <MYODBCC.h>
-#include <MYODBCIns.h>
-#include <myodbc_dbug.h>
-
#ifdef __cplusplus
+# include <MYODBCC.h>
+# include <installer.h>
+# include <myodbc_dbug.h>
+# include <QApplication>
+# include <QColor>
+# include <QDialog>
+# include <QLayout>
+# include <QLabel>
+# include <QPushButton>
+# include <QSplitter>
+# include <QMessageBox>
+# include <QTextBrowser>
+# include <QTextEdit>
+# include <QTabWidget>
+# include <QProcess>
+# include <QToolTip>
extern "C" {
+#else /* just C */
+# include <installer.h>
+# include <myodbc_dbug.h>
#endif
-BOOL MYODBCSetupDataSourceConfig( HWND hWnd, MYODBCInsDataSource *pDataSource );
-BOOL MYODBCSetupDriverConnect( HWND hWnd, MYODBCInsDriverConnect *pDriverConnect );
+/* the different modes used when calling MYODBCSetupDataSourceConfig */
+#define CONFIG_ADD 1
+#define CONFIG_EDIT 2
+#define CONFIG_VIEW 3
+#define CONFIG_DRIVER_CONNECT 4
+BOOL MYODBCSetupDataSourceConfig( HWND hWnd, DataSource *pDataSource, int mode );
+
#ifdef __cplusplus
}
#endif
#endif
-
Modified: trunk/Driver/Setup/Library/MYODBCSetupDataSourceConfig.cpp
===================================================================
--- trunk/Driver/Setup/Library/MYODBCSetupDataSourceConfig.cpp 2007-05-22 18:30:28 UTC
(rev 924)
+++ trunk/Driver/Setup/Library/MYODBCSetupDataSourceConfig.cpp 2007-05-22 18:47:33 UTC
(rev 925)
@@ -30,7 +30,7 @@
char *pszAppName = "MYODBCSetup5";
-BOOL MYODBCSetupDataSourceConfig( HWND hWnd, MYODBCInsDataSource *pDataSource )
+BOOL MYODBCSetupDataSourceConfig( HWND hWnd, DataSource *pDataSource, int mode )
{
BOOL bReturn = FALSE;
@@ -39,6 +39,12 @@
No window handle - no gui - regardless of the fact that we may not use the window
handle anyway :)
We must return true to support ODBC_ADD_DSN - which allows add even when no GUI.
+
+ We will provide a GUI for any non-zero value but on XP the _DM_ tries
+ to be too smart for us - and complains about an invalid window handle.
+ This prevents this trick from working on XP which in turn prevents console
+ applications from invoking GUI (unless they can come up with a viable
+ window handle).
*/
if ( !hWnd )
return true;
@@ -64,6 +70,19 @@
*/
if ( !QApplication::instance() )
{
+// METHOD 1
+// int argc = 1;
+// char * argv[] = { pszAppName, NULL };
+// static QApplication app( argc, argv );
+//
+// MYODBCSetupDataSourceDialog dialogDataSource( NULL, hDBC, pDataSource );
+//
+// app.connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
+// dialogDataSource.show();
+// if ( app.exec() == QDialog::Accepted )
+// bReturn = TRUE;
+
+// METHOD 2 (tested to work on XP)
int argc = 1;
char * argv[] = { pszAppName, NULL };
QApplication app( argc, argv );
@@ -73,7 +92,8 @@
// if ( pdialogDataSource->exec() == QDialog::Accepted )
// bReturn = TRUE;
- MYODBCSetupDataSourceDialog dialogDataSource( NULL, pDataSource );
+ // We are most likely to come in this route as caller is unlikely to have a
QApplication
+ MYODBCSetupDataSourceDialog dialogDataSource( NULL, pDataSource, mode );
if ( dialogDataSource.exec() == QDialog::Accepted )
bReturn = TRUE;
@@ -84,9 +104,16 @@
}
else
{
- // We get here when ODBCConfig calls setup and gets this dialog because
ODBCConfig has a qApp. */
- MYODBCSetupDataSourceDialog dialogDataSource( NULL, pDataSource );
+// METHOD 1
+// MYODBCSetupDataSourceDialog *pdialogDataSource = new
MYODBCSetupDataSourceDialog( NULL, hDBC, pDataSource );
+// if ( pdialogDataSource->exec() == QDialog::Accepted )
+// bReturn = TRUE;
+//
+// METHOD 2 (tested to work on XP)
+ // We get here when ODBCConfig calls setup and gets this dialog because
ODBCConfig has a QApplication
+ MYODBCSetupDataSourceDialog dialogDataSource( NULL, pDataSource, mode );
+
if ( dialogDataSource.exec() == QDialog::Accepted )
bReturn = TRUE;
}
@@ -94,5 +121,3 @@
return bReturn;
}
-
-
Modified: trunk/Driver/Setup/Library/MYODBCSetupDataSourceDialog.cpp
===================================================================
--- trunk/Driver/Setup/Library/MYODBCSetupDataSourceDialog.cpp 2007-05-22 18:30:28 UTC
(rev 924)
+++ trunk/Driver/Setup/Library/MYODBCSetupDataSourceDialog.cpp 2007-05-22 18:47:33 UTC
(rev 925)
@@ -31,22 +31,14 @@
#include "MySQL-16.xpm"
#include "TopImage.xpm"
-MYODBCSetupDataSourceDialog::MYODBCSetupDataSourceDialog( QWidget *pwidgetParent,
MYODBCInsDataSource *pDataSource )
- : QDialog( pwidgetParent )
+MYODBCSetupDataSourceDialog::MYODBCSetupDataSourceDialog(QWidget *pwidgetParent,
+ DataSource *pDataSource, int configmode)
+ : QDialog( pwidgetParent ), mode(configmode)
{
this->pDataSource = pDataSource;
- this->pDriverConnect = NULL;
doInit();
}
-MYODBCSetupDataSourceDialog::MYODBCSetupDataSourceDialog( QWidget *pwidgetParent,
MYODBCInsDriverConnect *pDriverConnect )
- : QDialog( pwidgetParent )
-{
- this->pDataSource = NULL;
- this->pDriverConnect = pDriverConnect;
- doInit();
-}
-
MYODBCSetupDataSourceDialog::~MYODBCSetupDataSourceDialog()
{
// Are we getting deleted - is our destructor getting executed?
@@ -55,30 +47,32 @@
void MYODBCSetupDataSourceDialog::slotOk()
{
- if ( pDataSource )
- doOk( pDataSource );
- else if ( pDriverConnect )
- doOk( pDriverConnect );
+ doOk( pDataSource );
}
-void MYODBCSetupDataSourceDialog::doOk( MYODBCInsDataSource *pDataSource )
+void MYODBCSetupDataSourceDialog::doOk( DataSource *ds )
{
- switch ( pDataSource->getMode() )
+ if(mode != CONFIG_DRIVER_CONNECT &&
+ ptab1->getDataSourceName().isEmpty())
{
- case MYODBCInsDataSource::DATASOURCE_MODE_DSN_ADD:
- if ( ptab1->getDataSourceName().isEmpty() )
- {
// ptab1->plineeditDataSourceName->setFocus();
- QMessageBox::warning( this, "MyODBC", tr("Missing Data Source Name"),
tr("&Ok"), QString::null, QString::null, 0, 1 );
- return;
- }
- if ( ptab1->getUser().isEmpty() )
- {
-// ptab1->plineeditUser->setFocus();
- QMessageBox::warning( this, "MyODBC", tr("Missing User ID"),
tr("&Ok"), QString::null, QString::null, 0, 1 );
- return;
- }
+ QMessageBox::warning( this, "MyODBC", tr("Missing Data Source Name"),
tr("&Ok"), QString::null, QString::null, 0, 1 );
+ return;
+ }
+ else if(mode == CONFIG_DRIVER_CONNECT && ptab1->getUser().isEmpty())
+ {
+ /*!
+ \internal MYODBC RULE
+ A UID is really the only thing we MUST have for a driver connect.
+ */
+ ptabwidget->setCurrentWidget( 0 );
+// ptab1->plineeditUser->setFocus();
+ QMessageBox::warning( this, "MyODBC", tr("Missing User ID"), tr("&Ok"),
QString::null, QString::null, 0, 1 );
+ return;
+ }
+ else if(mode == CONFIG_ADD && ds_exists(ds->name))
+ {
/*!
\internal ODBC RULE
@@ -86,72 +80,23 @@
ConfigDSN overwrites the existing name. If it matches an existing name
and hwndParent
is not null, ConfigDSN prompts the user to overwrite the existing name.
*/
- if ( MYODBCIns::isExistsDataSourceName( ptab1->getDataSourceName(),
pDataSource->getScope() ) )
- {
- int n = QMessageBox::warning( this, "MyODBC", tr("Data Source Name (%1)
exists. It will be replaced?") .arg( ptab1->getDataSourceName() ), tr("&Ok"),
tr("&Cancel"), QString::null, 0, 1 );
- if ( n )
- return;
- }
- break;
-
- case MYODBCInsDataSource::DATASOURCE_MODE_DSN_EDIT:
- if ( ptab1->getDataSourceName().isEmpty() )
- {
- ptabwidget->setCurrentWidget( 0 );
-// ptab1->plineeditDataSourceName->setFocus();
- QMessageBox::warning( this, "MyODBC", tr("Missing Data Source Name"),
tr("&Ok"), QString::null, QString::null, 0, 1 );
+ int n = QMessageBox::warning( this, "MyODBC", tr("Data Source Name (%1)
exists. Overwrite it?") .arg( ptab1->getDataSourceName() ), tr("&Ok"),
tr("&Cancel"), QString::null, 0, 1 );
+ if ( n )
return;
- }
- break;
-
- case MYODBCInsDataSource::DATASOURCE_MODE_DSN_VIEW:
- break;
-
- default:
- break;
}
- if ( pDataSource->getMode() != MYODBCInsDataSource::DATASOURCE_MODE_DSN_VIEW )
- {
- pDataSource->setName( ptab1->getDataSourceName() );
- pDataSource->setDESCRIPTION( ptab1->getDescription() );
- pDataSource->setSERVER( ptab1->getServer() );
- pDataSource->setUID( ptab1->getUser() );
- pDataSource->setPWD( ptab1->getPassword() );
- pDataSource->setDATABASE( ptab1->getDatabase() );
- pDataSource->setPORT( ptab1->getPort() );
- }
+ ds_set_strattr(&ds->name,
ptab1->getDataSourceName().toStdWString().c_str());
+ ds_set_strattr(&ds->description,
ptab1->getDescription().toStdWString().c_str());
+ ds_set_strattr(&ds->server, ptab1->getServer().toStdWString().c_str());
+ ds_set_strattr(&ds->uid, ptab1->getUser().toStdWString().c_str());
+ ds_set_strattr(&ds->pwd, ptab1->getPassword().toStdWString().c_str());
+ ds_set_strattr(&ds->database, ptab1->getDatabase().toStdWString().c_str());
+ ds->port = ptab1->getPort().toInt();
// exit
done( QDialog::Accepted );
}
-void MYODBCSetupDataSourceDialog::doOk( MYODBCInsDriverConnect *pDriverConnect )
-{
- /*!
- \internal MYODBC RULE
-
- A UID is really the only thing we MUST have for a driver connect.
- */
- if ( ptab1->getUser().isEmpty() )
- {
- ptabwidget->setCurrentWidget( 0 );
-// ptab1->plineeditUser->setFocus();
- QMessageBox::warning( this, "MyODBC", tr("Missing User ID"), tr("&Ok"),
QString::null, QString::null, 0, 1 );
- return;
- }
-
- pDriverConnect->setDESCRIPTION( ptab1->getDescription() );
- pDriverConnect->setSERVER( ptab1->getServer() );
- pDriverConnect->setUID( ptab1->getUser() );
- pDriverConnect->setPWD( ptab1->getPassword() );
- pDriverConnect->setDATABASE( ptab1->getDatabase() );
- pDriverConnect->setPORT( ptab1->getPort() );
-
- // exit
- done( QDialog::Accepted );
-}
-
void MYODBCSetupDataSourceDialog::doInit()
{
setWindowTitle( "MySQL Connector/ODBC - Unknown Mode" );
@@ -216,55 +161,39 @@
ppushbuttonCancel = new QPushButton( "&Cancel", this );
playoutButtons->addWidget( ppushbuttonCancel );
- if ( pDataSource )
- doInit( pDataSource );
- else if ( pDriverConnect )
- doInit( pDriverConnect );
+ doInit( pDataSource );
connect( ppushbuttonOk, SIGNAL(clicked()), this, SLOT(slotOk()) );
connect( ppushbuttonCancel, SIGNAL(clicked()), this, SLOT(reject()) );
}
-void MYODBCSetupDataSourceDialog::doInit( MYODBCInsDataSource *pDataSource )
+void MYODBCSetupDataSourceDialog::doInit( DataSource *pDataSource )
{
- switch ( pDataSource->getMode() )
+ switch ( mode )
{
- case MYODBCInsDataSource::DATASOURCE_MODE_DSN_EDIT:
+ case CONFIG_EDIT:
setWindowTitle( "MySQL Connector/ODBC " MYODBC_VERSION " - Configure Data
Source Name" );
break;
- case MYODBCInsDataSource::DATASOURCE_MODE_DSN_ADD:
+ case CONFIG_ADD:
setWindowTitle( "MySQL Connector/ODBC " MYODBC_VERSION " - Add Data Source
Name" );
break;
- case MYODBCInsDataSource::DATASOURCE_MODE_DSN_VIEW:
+ case CONFIG_VIEW:
setWindowTitle( "MySQL Connector/ODBC " MYODBC_VERSION " - View Data Source
Name" );
break;
+ case CONFIG_DRIVER_CONNECT:
+ setWindowTitle( "MySQL Connector/ODBC " MYODBC_VERSION " - Driver Connect" );
+ ptab1->plineeditDataSourceName->setDisabled( true );
+ break;
default:
Q_ASSERT( 0 );
}
- ptab1->setDataSourceName( pDataSource->getName() );
- ptab1->setDescription( pDataSource->getDESCRIPTION() );
- ptab1->setServer( pDataSource->getSERVER() );
- ptab1->setUser( pDataSource->getUID() );
- ptab1->setPassword( pDataSource->getPWD() );
- ptab1->setDatabase( pDataSource->getDATABASE() );
- ptab1->setPort( pDataSource->getPORT() );
+ ptab1->setDataSourceName(QString::fromWCharArray(pDataSource->name));
+ ptab1->setDescription(QString::fromWCharArray(pDataSource->description));
+ ptab1->setServer(QString::fromWCharArray(pDataSource->server));
+ ptab1->setUser(QString::fromWCharArray(pDataSource->uid));
+ ptab1->setPassword(QString::fromWCharArray(pDataSource->pwd));
+ ptab1->setDatabase(QString::fromWCharArray(pDataSource->database));
+ ptab1->setPort(QString("%1").arg(pDataSource->port));
}
-void MYODBCSetupDataSourceDialog::doInit( MYODBCInsDriverConnect *pDriverConnect )
-{
- setWindowTitle( "MySQL Connector/ODBC " MYODBC_VERSION " - Driver Connect" );
-
- ptab1->plineeditDataSourceName->setDisabled( true );
-
- ptab1->setDataSourceName( pDriverConnect->getDSN() );
- ptab1->setDescription( pDriverConnect->getDESCRIPTION() );
- ptab1->setServer( pDriverConnect->getSERVER() );
- ptab1->setUser( pDriverConnect->getUID() );
- ptab1->setPassword( pDriverConnect->getPWD() );
- ptab1->setDatabase( pDriverConnect->getDATABASE() );
- ptab1->setPort( pDriverConnect->getPORT() );
-}
-
-
-
Modified: trunk/Driver/Setup/Library/MYODBCSetupDataSourceDialog.h
===================================================================
--- trunk/Driver/Setup/Library/MYODBCSetupDataSourceDialog.h 2007-05-22 18:30:28 UTC (rev
924)
+++ trunk/Driver/Setup/Library/MYODBCSetupDataSourceDialog.h 2007-05-22 18:47:33 UTC (rev
925)
@@ -36,16 +36,15 @@
{
Q_OBJECT
public:
- MYODBCSetupDataSourceDialog( QWidget *pwidgetParent, MYODBCInsDataSource *pDataSource
);
- MYODBCSetupDataSourceDialog( QWidget *pwidgetParent, MYODBCInsDriverConnect
*pDriverConnect );
+ MYODBCSetupDataSourceDialog( QWidget *pwidgetParent, DataSource *pDataSource, int
configmode );
~MYODBCSetupDataSourceDialog();
public slots:
void slotOk();
protected:
- MYODBCInsDataSource * pDataSource;
- MYODBCInsDriverConnect * pDriverConnect;
+ int mode;
+ DataSource *pDataSource;
// starts here
QVBoxLayout * playoutTop;
@@ -68,11 +67,9 @@
QPushButton * ppushbuttonOk;
QPushButton * ppushbuttonCancel;
- void doOk( MYODBCInsDataSource *pDataSource );
- void doOk( MYODBCInsDriverConnect *pDriverConnect );
+ void doOk( DataSource *pDataSource );
void doInit();
- void doInit( MYODBCInsDataSource *pDataSource );
- void doInit( MYODBCInsDriverConnect *pDriverConnect );
+ void doInit( DataSource *pDataSource );
};
#endif
Deleted: trunk/Driver/Setup/Library/MYODBCSetupDriverConnect.cpp
===================================================================
--- trunk/Driver/Setup/Library/MYODBCSetupDriverConnect.cpp 2007-05-22 18:30:28 UTC (rev
924)
+++ trunk/Driver/Setup/Library/MYODBCSetupDriverConnect.cpp 2007-05-22 18:47:33 UTC (rev
925)
@@ -1,96 +0,0 @@
-/*!
- \file MYODBCSetupDriverConnect.cpp
- \author Peter Harvey <pharvey@stripped>
- Copyright (C) MySQL AB 2004-2007, Released under GPL.
- \version Connector/ODBC v5
- \date 2007
-
- \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 "MYODBCSetupDataSourceDialog.h"
-
-static char *pszAppName = "MYODBCSetup5";
-
-BOOL MYODBCSetupDriverConnect( HWND hWnd, MYODBCInsDriverConnect *pDriverConnect )
-{
- BOOL bReturn = FALSE;
-
- /*!
- MYODBC RULE
-
- No window handle - no gui - regardless of the fact that we may not
- use the window handle anyway :)
-
- We will provide a GUI for any non-zero value but on XP the _DM_ tries
- to be too smart for us - and complains about an invalid window handle.
- This prevents this trick from working on XP which in turn prevents console
- applications from invoking GUI (unless they can come up with a viable
- window handle).
- */
- if ( !hWnd )
- return FALSE;
-
- if ( !qApp )
- {
-// METHOD 1
-// int argc = 1;
-// char * argv[] = { pszAppName, NULL };
-// static QApplication app( argc, argv );
-//
-// MYODBCSetupDataSourceDialog dialogDataSource( NULL, hDBC, pDataSource );
-//
-// app.connect( &app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()) );
-// dialogDataSource.show();
-// if ( app.exec() == QDialog::Accepted )
-// bReturn = TRUE;
-
-// METHOD 2 (tested to work on XP)
- int argc = 1;
- char * argv[] = { pszAppName, NULL };
- QApplication app( argc, argv );
-
- // We are most likely to come in this route as caller is unlikely to have a qApp
*/
- MYODBCSetupDataSourceDialog dialogDataSource( NULL, pDriverConnect );
-
- if ( dialogDataSource.exec() == QDialog::Accepted )
- bReturn = TRUE;
- }
- else
- {
-// METHOD 1
-// MYODBCSetupDataSourceDialog *pdialogDataSource = new
MYODBCSetupDataSourceDialog( NULL, hDBC, pDataSource );
-// if ( pdialogDataSource->exec() == QDialog::Accepted )
-// bReturn = TRUE;
-//
-
-// METHOD 2 (tested to work on XP)
- MYODBCSetupDataSourceDialog dialogDataSource( NULL, pDriverConnect );
-
- if ( dialogDataSource.exec() == QDialog::Accepted )
- bReturn = TRUE;
- }
-
- return bReturn;
-}
-
-
-
Modified: trunk/SDK/C/Library/MYODBCC.cpp
===================================================================
--- trunk/SDK/C/Library/MYODBCC.cpp 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/C/Library/MYODBCC.cpp 2007-05-22 18:47:33 UTC (rev 925)
@@ -2699,7 +2699,7 @@
}
/* -1 means all, otherwise it's correctly resized, so 0 means no copy */
if(nLenChars != 0)
- memcpy(array, st.c_str(), (st.length()+1) * sizeof(wchar_t));
+ memcpy(array, st.c_str(), (st.length()+1) * sizeof(wchar_t));
return r;
}
@@ -2772,3 +2772,11 @@
return final;
}
+char *MYODBCCString::wcstoutf8(const SQLWCHAR *str, const char *dfltres)
+{
+ if(!str)
+ return strdup(dfltres);
+ else
+ return strdup(QString::fromWCharArray(str).toUtf8().data());
+}
+
Modified: trunk/SDK/C/include/MYODBCC.h
===================================================================
--- trunk/SDK/C/include/MYODBCC.h 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/C/include/MYODBCC.h 2007-05-22 18:47:33 UTC (rev 925)
@@ -495,6 +495,8 @@
\param str 16 byte buffer holding packed int
*/
static int num_unpack(const char *str);
+
+ static char *wcstoutf8(const SQLWCHAR *str, const char *dfltres);
};
Modified: trunk/SDK/Installer/Library/Library.pro
===================================================================
--- trunk/SDK/Installer/Library/Library.pro 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/Installer/Library/Library.pro 2007-05-22 18:47:33 UTC (rev 925)
@@ -11,11 +11,7 @@
include( ../../../mysql.pri )
CONFIG += staticlib
CONFIG += console
-INCLUDEPATH += ../../C/include
-INCLUDEPATH += ../../Dbg/include
INCLUDEPATH += ../include
-LIBS += -L../../lib
-LIBS += -lMYODBCC
# #########################################################
# UNIX
@@ -36,16 +32,7 @@
# #########################################################
# FILES
# #########################################################
-HEADERS = \
- ../include/MYODBCIns.h \
- ../include/MYODBCInsDriver.h \
- ../include/MYODBCInsDataSource.h \
- ../include/MYODBCInsDriverConnect.h \
- MYODBCInsInternal.h
+HEADERS = ../include/installer.h
-SOURCES = \
- MYODBCIns.cpp \
- MYODBCInsDriver.cpp \
- MYODBCInsDataSource.cpp \
- MYODBCInsDriverConnect.cpp
+SOURCES = installer.c
Deleted: trunk/SDK/Installer/Library/MYODBCIns.cpp
===================================================================
--- trunk/SDK/Installer/Library/MYODBCIns.cpp 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/Installer/Library/MYODBCIns.cpp 2007-05-22 18:47:33 UTC (rev 925)
@@ -1,702 +0,0 @@
-/*!
- \file MYODBCIns.cpp
- \author Peter Harvey <pharvey@stripped>
- Copyright (C) MySQL AB 2004-2007, Released under GPL.
- \version Connector/ODBC v5
- \date 2007
- \brief Code to provide abstraction and portability for I/O of ODBC system
information information.
-
- \license GPL
-
- 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 MYODBCIns::setError( const QString &stringError, DWORD nError )
-{
- std::wstring msg;
-
- DBUG_ENTER("MYODBCIns::setError");
-
- if ( stringError.isNull() )
- {
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- MYODBCCString::QString_toWString( stringError, &msg );
- if ( !SQL_SUCCEEDED( SQLPostInstallerError( (DWORD)nError, const_cast<wchar_t
*>( msg.c_str() ) ) ) )
- {
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- DBUG_PRINT("oreturn", ( "%d", true ));
- DBUG_RETURN( true );
-}
-
-
-/*!
- \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 MYODBCIns::getDriverNames()
-{
- DBUG_ENTER("MYODBCIns::getDriverNames");
-
- SQLWCHAR szBuffer[50000];
- WORD nChars = 0;
- int nChar = 0;
- QStringList stringlistFriendlyNames;
- QString stringFriendlyName = QString::null;
-
- if ( !SQLGetInstalledDrivers( szBuffer, sizeof(szBuffer) / sizeof(SQLWCHAR),
&nChars ) )
- {
- DBUG_PRINT("oreturn", ("%p", &( stringlistFriendlyNames )));
- DBUG_RETURN( stringlistFriendlyNames );
- }
-
- if ( nChars < 1 )
- {
- {
- QString tmp_msg = ( "Call returned no data. Could be an error or just no data
to return." );
- DBUG_PRINT("oinfo", ("%s", (const char *)(tmp_msg.toUtf8())));
- }
- DBUG_PRINT("oreturn", ("%p", &( stringlistFriendlyNames )));
- DBUG_RETURN( stringlistFriendlyNames );
- }
-
- 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;
- }
- }
-
- DBUG_PRINT("oreturn", ("%p", &( stringlistFriendlyNames )));
- DBUG_RETURN( stringlistFriendlyNames );
-}
-
-QStringList MYODBCIns::getDataSourceNames( MYODBCInsDataSource::DATASOURCE_SCOPE nScope )
-{
- DBUG_ENTER("MYODBCIns::getDataSourceNames");
-
- SQLHENV hEnvironment;
- SQLWCHAR sDataSourceName[500];
- SQLWCHAR sDescription[500];
- SQLSMALLINT nDataSourceNameLength;
- SQLSMALLINT nDescriptionLength;
- SQLRETURN nReturn;
- SQLUSMALLINT nDirection;
- QStringList stringlistDataSourceNames;
-
- nReturn = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnvironment );
- nReturn = SQLSetEnvAttr( hEnvironment, SQL_ATTR_ODBC_VERSION, (void *)SQL_OV_ODBC3, 0
);
-
- switch ( nScope )
- {
- case MYODBCInsDataSource::DATASOURCE_SCOPE_BOTH:
- nDirection = SQL_FETCH_FIRST;
- break;
- case MYODBCInsDataSource::DATASOURCE_SCOPE_SYSTEM:
- nDirection = SQL_FETCH_FIRST_SYSTEM;
- break;
- case MYODBCInsDataSource::DATASOURCE_SCOPE_USER:
- nDirection = SQL_FETCH_FIRST_USER;
- break;
- }
-
- nReturn = SQLDataSources( hEnvironment, nDirection, sDataSourceName,
- sizeof(sDataSourceName) / sizeof(SQLWCHAR),
- &nDataSourceNameLength, sDescription,
- sizeof(sDescription) / sizeof(SQLWCHAR),
&nDescriptionLength );
-
- while ( SQL_SUCCEEDED( nReturn ) )
- {
- stringlistDataSourceNames += MYODBCCString::QString_fromWCharArray(
sDataSourceName );
-
- nReturn = SQLDataSources( hEnvironment, SQL_FETCH_NEXT, sDataSourceName,
- sizeof(sDataSourceName) / sizeof(SQLWCHAR),
- &nDataSourceNameLength, sDescription,
- sizeof(sDescription) / sizeof(SQLWCHAR),
&nDescriptionLength );
- }
-
- nReturn = SQLFreeHandle( SQL_HANDLE_ENV, hEnvironment );
-
- DBUG_PRINT("oreturn", ("%p", &( stringlistDataSourceNames )));
- DBUG_RETURN( stringlistDataSourceNames );
-}
-
-QString MYODBCIns::getDefaultInstallLocation()
-{
- DBUG_ENTER("MYODBCIns::getDefaultInstallLocation");
-
- QString stringDefaultInstallLocation;
- SQLWCHAR szPathOut[1024];
- WORD nPathOutLength = 0;
- DWORD nUsageCount = 0;
- SQLWCHAR * pszAttributes = MYODBCInsDriver::getAttributesNullDelim( "bogusname",
"bogusdriver", "bogussetup" );
- BOOL bRetCode = SQLInstallDriverEx( pszAttributes, NULL, szPathOut,
sizeof(szPathOut) / sizeof(SQLWCHAR), &nPathOutLength, ODBC_INSTALL_INQUIRY,
&nUsageCount );
-
- free(pszAttributes);
-
- if ( bRetCode )
- stringDefaultInstallLocation = MYODBCCString::QString_fromWCharArray( szPathOut
);
-
- DBUG_PRINT("oreturn", ("%s", ( (const char *)stringDefaultInstallLocation.toUtf8()
)));
- DBUG_RETURN( stringDefaultInstallLocation );
-}
-
-BOOL MYODBCIns::getKeywordValues( QHash<QString,QString> *phashKeywordValues, const
QString &stringKeywordValues, DELIM nDelim )
-{
- DBUG_ENTER("MYODBCIns::getKeywordValues");
-
- PARSE_STATE nState = PARSE_STATE_NAME_START;
- int nAnchorChar = 0;
- int nScanChar = 0;
- QString stringKeyword;
- QString stringValue;
- QChar cEqual( '=' );
- QChar cBraceOpen( '{' );
- QChar cBraceClose( '}' );
-
- /* short circuit if we have not been given stuff to parse */
- if ( stringKeywordValues.isEmpty() )
- {
- DBUG_PRINT("oreturn", ( "%d", true ));
- DBUG_RETURN( true );
- }
-
- /* scan the input (we can not use QString::split() due to possible use of {} to
embrace values and type of delim) */
- while ( 1 )
- {
- switch ( nState )
- {
- case PARSE_STATE_NAME_START:
- /* start of keyword? */
- {
- if ( stringKeywordValues[nScanChar].isLetter() )
- {
- nAnchorChar = nScanChar;
- nState = PARSE_STATE_NAME;
- }
- }
- break;
- case PARSE_STATE_NAME:
- /* end of keyword? */
- {
- if ( stringKeywordValues[nScanChar] == cEqual )
- {
- stringKeyword = stringKeywordValues.mid( nAnchorChar, nScanChar -
nAnchorChar );
- nState = PARSE_STATE_VALUE_START;
- }
- }
- break;
- case PARSE_STATE_VALUE_START:
- /* start of value? (ODBC says no spaces here but silently eat'm anyway)
*/
- {
- if ( !stringKeywordValues[nScanChar].isSpace() )
- {
- if ( stringKeywordValues[nScanChar] == cBraceOpen )
- {
- nAnchorChar = nScanChar + 1;
- nState = PARSE_STATE_VALUE_BRACED;
- }
- else
- {
- nAnchorChar = nScanChar;
- nState = PARSE_STATE_VALUE;
- }
- }
- }
- break;
- case PARSE_STATE_VALUE:
- case PARSE_STATE_VALUE_BRACED:
- /* end of value? */
- if ( nState == PARSE_STATE_VALUE )
- {
- /* more chars if it's not the last char or delimiter */
- if ( nScanChar + 1 < stringKeywordValues.length() &&
- !isDelim( stringKeywordValues, nScanChar, &nDelim ) )
- break;
-
- /*
- increment nScanChar if this is the last char and not a delimiter
- so mid() is given the right length
- */
- if( nScanChar + 1 == stringKeywordValues.length() &&
- !isDelim( stringKeywordValues, nScanChar, &nDelim ) )
- nScanChar++;
-
- stringValue = stringKeywordValues.mid( nAnchorChar, nScanChar -
nAnchorChar );
- }
- else if ( nState == PARSE_STATE_VALUE_BRACED )
- {
- if ( isDelim( stringKeywordValues, nScanChar, &nDelim ) )
- {
- setError( QString( "[%1][%2][ERROR] Missing closing brace for %3
value." )
- .arg( __FILE__ ).arg( __LINE__ ).arg( stringKeyword ) );
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- if ( stringKeywordValues[nScanChar] != cBraceClose )
- break;
-
- stringValue = stringKeywordValues.mid( nAnchorChar, nScanChar -
nAnchorChar );
-
- /* Skip the brace, unless it's the last char */
- if ( nScanChar < stringKeywordValues.length() )
- nScanChar++;
- }
-
- /* we now have a keyword/value pair */
-
- /*
- \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 ( phashKeywordValues->contains( stringKeyword ) )
- break;
-
- phashKeywordValues->insert( stringKeyword.toUpper(), stringValue );
- stringKeyword = QString::null;
- break;
- default:
- {
- QString tmp_msg;
- tmp_msg.sprintf( "Unhandled state %d", nState );
- DBUG_PRINT("oerror", ("%s", (const char *)(tmp_msg.toUtf8())));
- }
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- /* have we advanced to end of string */
- if ( nScanChar + 1 >= stringKeywordValues.length() ||
- isDelimKeywordValues( stringKeywordValues, nScanChar, nDelim ) )
- break;
-
- /* terminated a name/value pair */
- if ( isDelimKeywordValue( stringKeywordValues[nScanChar], &nDelim ) )
- nState = PARSE_STATE_NAME_START;
-
- nScanChar++;
-
- } /* while scan */
-
- DBUG_PRINT("oreturn", ( "%d", true ));
- DBUG_RETURN( true );
-}
-
-RETCODE MYODBCIns::getError( WORD nError, DWORD *pnErrorCode, QString &stringMessage
)
-{
- DBUG_ENTER("MYODBCIns::getError");
-
- SQLWCHAR szMessage[32000];
- WORD nMessageLen;
-
- RETCODE nRetCode = SQLInstallerError( nError, pnErrorCode, szMessage,
sizeof(szMessage) / sizeof(SQLWCHAR), &nMessageLen );
-
- if ( SQL_SUCCEEDED(nRetCode) )
- stringMessage = MYODBCCString::QString_fromWCharArray( szMessage );
-
- DBUG_RETURN( nRetCode );
-}
-
-QString MYODBCIns::getError( WORD nError )
-{
- DBUG_ENTER("MYODBCIns::getError");
-
- DWORD nErrorCode = 0;
- QString stringMessage;
- QString stringMessageEnhanced;
- RETCODE nRetCode = getError( nError, &nErrorCode, stringMessage );
-
- if ( SQL_SUCCEEDED(nRetCode) )
- {
- stringMessageEnhanced = QString( "[%1][%2] %3" )
- .arg( MYODBCCMap::getInstallerErrorString( nErrorCode ) )
- .arg( nErrorCode )
- .arg( stringMessage );
- }
-
- DBUG_PRINT("oreturn", ("%s", ( (const char *) stringMessageEnhanced.toUtf8() )));
- DBUG_RETURN( stringMessageEnhanced );
-}
-
-QStringList MYODBCIns::getErrors()
-{
- DBUG_ENTER("MYODBCIns::getErrors");
-
- QStringList stringlistErrors;
-
- /* 8 because this is max according to MS ver of ODBC spec */
- for ( WORD nError = 1; nError <= 8; nError++ )
- {
- QString stringError = getError( nError );
- if ( stringError.isEmpty() )
- break;
- stringlistErrors += stringError;
- }
-
- DBUG_PRINT("oreturn", ("%p", &( stringlistErrors )));
- DBUG_RETURN( stringlistErrors );
-}
-
-BOOL MYODBCIns::doRegisterDriver( const QString &stringName, const QString
&stringAttributes, DWORD *pnUsageCount )
-{
- DBUG_ENTER("MYODBCIns::doRegisterDriver");
-
- if ( stringName.isNull() )
- {
- setError( QString( "[%1][%2][ERROR] Driver name NULL." ).arg( __FILE__ ).arg(
__LINE__ ) );
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- if ( stringAttributes.isNull() )
- {
- setError( QString( "[%1][%2][ERROR] Driver attributes NULL." ).arg( __FILE__
).arg( __LINE__ ) );
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- QString stringNameAttributes = stringName + ";" + stringAttributes + " "; //
extra space at end needed for extra null term
- QChar * pData = stringNameAttributes.data();
- QChar * pChar;
- SQLWCHAR sLocation[FILENAME_MAX];
- WORD nLocationLength;
- DWORD nUsageCount = 0;
- QChar cNull( '\0' );
- QChar cSemi( ';' );
- std::wstring msg;
- BOOL ret;
-
- if ( !pnUsageCount )
- pnUsageCount = &nUsageCount;
-
- // Replace ';' with '\0' and ensure extra '\0' is at end.
- for ( pChar = pData; *pChar != cNull; pChar++ )
- {
- if ( *pChar == cSemi || pChar[1] == cNull )
- *pChar = cNull;
- }
-
- MYODBCCString::QString_toWString( stringNameAttributes, &msg );
- ret = SQLInstallDriverEx(msg.c_str(), 0, sLocation, FILENAME_MAX,
- &nLocationLength, ODBC_INSTALL_COMPLETE,
- pnUsageCount);
-
- DBUG_PRINT("oreturn", ( "%d", ret ));
- DBUG_RETURN( true );
-}
-
-BOOL MYODBCIns::doDeregisterDriver( const QString &stringName, BOOL bRemoveDSNs,
DWORD *pnUsageCount )
-{
- DBUG_ENTER("MYODBCIns::doDeregisterDriver");
-
- DWORD nUsageCount = -1;
- std::wstring msg;
- BOOL ret;
-
- if ( stringName.isNull() )
- {
- setError( QString( "[%1][%2][ERROR] Driver name NULL." ).arg( __FILE__ ).arg(
__LINE__ ) );
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- if ( !pnUsageCount )
- pnUsageCount = &nUsageCount;
-
- MYODBCCString::QString_toWString( stringName, &msg );
- ret = SQLRemoveDriver( msg.c_str(), bRemoveDSNs, pnUsageCount );
-
- DBUG_PRINT("oreturn", ( "%d", ret ));
- DBUG_RETURN( true );
-}
-
-BOOL MYODBCIns::doInsertDataSource( const QString &stringName, const QString
&stringAttributes, MYODBCInsDataSource::DATASOURCE_SCOPE nScope )
-{
- DBUG_ENTER("MYODBCIns::doInsertDataSource");
- BOOL ret;
-
- if ( stringName.isNull() )
- {
- setError( QString( "[%1][%2][ERROR] Data source name NULL." ).arg( __FILE__
).arg( __LINE__ ) );
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- if ( stringAttributes.isNull() )
- {
- setError( QString( "[%1][%2][ERROR] Data source attributes NULL." ).arg( __FILE__
).arg( __LINE__ ) );
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- if ( isExistsDataSourceName( stringName, nScope ) )
- {
- setError( QString( "[%1][%2][ERROR] Data source name exists." ).arg( __FILE__
).arg( __LINE__ ) );
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- //
- MYODBCInsDataSource datasource;
- datasource.setMode( MYODBCInsDataSource::DATASOURCE_MODE_DSN_VIEW );
-
- /*! \todo */
-
- ret = datasource.doWrite( nScope );
-
- DBUG_PRINT("oreturn", ( "%d", ret ));
- DBUG_RETURN( true );
-}
-
-BOOL MYODBCIns::doUpdateDataSource( const QString &stringName, const QString
&stringAttributes, MYODBCInsDataSource::DATASOURCE_SCOPE nScope )
-{
- DBUG_ENTER("MYODBCIns::doUpdateDataSource");
-
- /*! \todo */
-
- DBUG_PRINT("oreturn", ( "%d", true ));
- DBUG_RETURN( true );
-}
-
-BOOL MYODBCIns::doDeleteDataSource( const QString &stringName,
MYODBCInsDataSource::DATASOURCE_SCOPE nScope )
-{
- DBUG_ENTER("MYODBCIns::doDeleteDataSource");
-
- /*!
- \internal
- \todo
-
- Implement Scope.
- */
- BOOL b = MYODBCInsDataSource::doDelete( stringName );
-
- DBUG_PRINT("oreturn", ( "%d", b ));
- DBUG_RETURN( b );
-}
-
-BOOL MYODBCIns::isError()
-{
- DBUG_ENTER("MYODBCIns::isError");
-
- BOOL bReturn = SQL_SUCCEEDED( SQLInstallerError( 0, NULL, NULL, 0, NULL ) );
-
- DBUG_PRINT("oreturn", ( "%d", bReturn ));
- DBUG_RETURN( bReturn );
-}
-
-BOOL MYODBCIns::isExistsDataSourceName( const QString &stringName,
MYODBCInsDataSource::DATASOURCE_SCOPE nScope )
-{
- DBUG_ENTER("MYODBCIns::isExistsDataSourceName");
-
- SQLWCHAR szSectionNames[SQL_MAX_DSN_LENGTH * MYODBC_INS_MAX_DSN_NAMES];
- SQLWCHAR * pszSectionName;
- BOOL bReturn = false;
- UWORD nScopeToRestore = ODBC_BOTH_DSN;
- std::wstring msg;
-
- if ( !SQLGetConfigMode( &nScopeToRestore ) )
- {
- DBUG_PRINT("oreturn", ( "%d", bReturn ));
- DBUG_RETURN( bReturn );
- }
-
- if ( stringName.isEmpty() )
- {
- DBUG_PRINT("oreturn", ( "%d", bReturn ));
- DBUG_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 likely anyway).
- */
- MYODBCCString::QString_toWString( stringName, &msg );
- /* Hmmm ? */
- if ( SQLGetPrivateProfileString( msg.c_str(), NULL, L"", szSectionNames,
sizeof(szSectionNames) / sizeof(SQLWCHAR), L"ODBC.INI" ) > 0 )
- {
- bReturn = true;
- goto isExistsDataSourceNameExit1;
- }
- else
- goto isExistsDataSourceNameExit1;
-#else
- if ( SQLGetPrivateProfileString( NULL, NULL, L"", szSectionNames, sizeof(
szSectionNames ) / sizeof(SQLWCHAR), L"ODBC.INI" ) < 1 )
- goto isExistsDataSourceNameExit1;
-#endif
- /*!
- Scan result and return MYODBC_C_TRUE if we find a match.
- */
- pszSectionName = szSectionNames;
- while( *pszSectionName )
- {
- QString stringSectionName( MYODBCCString::QString_fromWCharArray( pszSectionName
) );
-
- if ( QString::localeAwareCompare( stringSectionName.toUpper(),
stringName.toUpper() ) == 0 )
- {
- bReturn = true;
- goto isExistsDataSourceNameExit1;
- }
- pszSectionName += MYODBCCString::getStrLen( pszSectionName, SQL_MAX_DSN_LENGTH *
MYODBC_INS_MAX_DSN_NAMES ) + 1;
- }
-
-isExistsDataSourceNameExit1:
- SQLSetConfigMode( nScopeToRestore );
-
- DBUG_PRINT("oreturn", ( "%d", bReturn ));
- DBUG_RETURN( bReturn );
-}
-
-
-BOOL MYODBCIns::isDelim( const QString &stringKeywordValues, int nScanChar, DELIM
*pnDelim )
-{
- BOOL b = false;
- DBUG_ENTER("MYODBCIns::isDelim");
-
- if (isDelimKeywordValue( stringKeywordValues[nScanChar], pnDelim ) ||
- isDelimKeywordValues( stringKeywordValues, nScanChar, *pnDelim ))
- {
- b = true;
- }
-
- DBUG_PRINT("oreturn", ( "%d", b ));
- DBUG_RETURN( b );
-}
-
-BOOL MYODBCIns::isDelimKeywordValue( const QChar &charChar, DELIM *pnDelim )
-{
- BOOL ret = false;
- DBUG_ENTER("MYODBCIns::isDelimKeywordValue");
-
- switch ( *pnDelim )
- {
- case DELIM_BOTH:
- if ( charChar == QChar( ';' ) )
- {
- *pnDelim = DELIM_SEMI;
- ret = true;
- }
- /*!
- \note This is not fool proof - only works if last key/value is delim or
if we
- have already determined that we are DELIM_SEMI. Unfortunately; it
is
- popular to delim with ';' even when the spec calls for '\0'. So
in
- this case we come in with DELIM_BOTH and try to guess what delim
is
- being used.
-
- So we can over-run the buffer if...
-
- 1. we are called with DELIM_BOTH
- 2. we are given a string without any key/value delim
- 3. string is delim with a single '\0'
-
- For example;
-
- "DSN=test"
-
- The solution in this case is either call here with DELIM_SEMI or
to
- have a ';' after the key/value pair. Better yet - avoid
DELIM_BOTH
- as much as possible.
- */
- else if ( charChar == QChar( '\0' ) )
- {
- *pnDelim = DELIM_NULL;
- ret = true;
- }
- break;
- case DELIM_NULL:
- if ( charChar == QChar( '\0' ) )
- ret = true;
- break;
- case DELIM_SEMI:
- if ( charChar == QChar( ';' ) )
- ret = true;
- break;
- }
-
- DBUG_PRINT("oreturn", ( "%d", ret ));
- DBUG_RETURN( ret );
-}
-
-BOOL MYODBCIns::isDelimKeywordValues( const QString &stringKeywordValues, int
nScanChar, DELIM nDelim )
-{
- BOOL ret = false;
- DBUG_ENTER("MYODBCIns::isDelimKeywordValues");
-
- switch ( nDelim )
- {
- case DELIM_BOTH:
- if ( stringKeywordValues[nScanChar] == QChar( '\0' ) )
- ret = true;
- break;
- case DELIM_NULL:
- if ( nScanChar > 0 && stringKeywordValues[nScanChar - 1] == QChar(
'\0' ) &&
- stringKeywordValues[nScanChar] == QChar( '\0' ))
- {
- ret = true;
- }
- break;
- case DELIM_SEMI:
- if ( stringKeywordValues[nScanChar] == QChar( '\0' ) )
- ret = true;
- break;
- }
-
- DBUG_PRINT("oreturn", ( "%d", ret ));
- DBUG_RETURN( ret );
-}
-
Deleted: trunk/SDK/Installer/Library/MYODBCInsDataSource.cpp
===================================================================
--- trunk/SDK/Installer/Library/MYODBCInsDataSource.cpp 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/Installer/Library/MYODBCInsDataSource.cpp 2007-05-22 18:47:33 UTC (rev 925)
@@ -1,528 +0,0 @@
-/*!
- \file MYODBCInsDataSource.cpp
- \author Peter Harvey <pharvey@stripped>
- Copyright (C) MySQL AB 2004-2007, Released under GPL.
- \version Connector/ODBC v5
- \date 2007
- \brief Code to provide abstraction and portability for I/O of ODBC installer
information.
-
- \license GPL
-
- 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"
-
-MYODBCInsDataSource::MYODBCInsDataSource()
-{
- DBUG_ENTER("MYODBCInsDataSource::MYODBCInsDataSource");
-
- doClear();
-
- // set desired mode
- nMode = DATASOURCE_MODE_DSN_VIEW;
-
- // get current scope
- UWORD n = DATASOURCE_SCOPE_BOTH;
-
- nScope = DATASOURCE_SCOPE_BOTH;
- SQLGetConfigMode( &n );
- nScope = (DATASOURCE_SCOPE)n;
-
- DBUG_VOID_RETURN;
-}
-
-BOOL MYODBCInsDataSource::setAttributes( const QHash<QString,QString>
&hashAttributes, BOOL bReplace, BOOL bStrict )
-{
- DBUG_ENTER("MYODBCInsDataSource::setAttributes");
-
- if ( !isValidAttributes( hashAttributes, bStrict ) )
- {
- MYODBCIns::setError( QString( "[%1][%2][ERROR] Data source attributes empty."
).arg( __FILE__ ).arg( __LINE__ ) );
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- QHash<QString, QString>::const_iterator i = hashAttributes.constBegin();
- while ( i != hashAttributes.constEnd() )
- {
- if ( i.key() == "DSN" )
- setName( i.value() );
- else if ( this->hashAttributes[i.key()].isNull() || bReplace )
- this->hashAttributes[i.key()] = i.value();
- ++i;
- }
-
- DBUG_PRINT("oreturn", ( "%d", true ));
- DBUG_RETURN( true );
-}
-
-BOOL MYODBCInsDataSource::setName( const QString &stringName )
-{
- this->stringName = stringName;
- return true;
-}
-
-BOOL MYODBCInsDataSource::setDRIVER( const QString &stringDRIVER )
-{
- hashAttributes["DRIVER"] = stringDRIVER;
- return true;
-}
-
-BOOL MYODBCInsDataSource::setDESCRIPTION( const QString &stringDESCRIPTION )
-{
- hashAttributes["DESCRIPTION"] = stringDESCRIPTION;
- return true;
-}
-
-BOOL MYODBCInsDataSource::setSERVER( const QString &stringSERVER )
-{
- hashAttributes["SERVER"] = stringSERVER;
- return true;
-}
-
-BOOL MYODBCInsDataSource::setUID( const QString &stringUID )
-{
- hashAttributes["UID"] = stringUID;
- return true;
-}
-
-BOOL MYODBCInsDataSource::setPWD( const QString &stringPWD )
-{
- hashAttributes["PWD"] = stringPWD;
- return true;
-}
-
-BOOL MYODBCInsDataSource::setDATABASE( const QString &stringDATABASE )
-{
- hashAttributes["DATABASE"] = stringDATABASE;
- return true;
-}
-
-BOOL MYODBCInsDataSource::setPORT( const QString &stringPORT )
-{
- hashAttributes["PORT"] = stringPORT;
- return true;
-}
-
-BOOL MYODBCInsDataSource::setSOCKET( const QString &stringSOCKET )
-{
- hashAttributes["SOCKET"] = stringSOCKET;
- return true;
-}
-
-BOOL MYODBCInsDataSource::setSTMT( const QString &stringSTMT )
-{
- hashAttributes["STMT"] = stringSTMT;
- return true;
-}
-
-BOOL MYODBCInsDataSource::setOPTION( const QString &stringOPTION )
-{
- hashAttributes["OPTION"] = stringOPTION;
- return true;
-}
-
-BOOL MYODBCInsDataSource::setMode( DATASOURCE_MODE nMode )
-{
- this->nMode = nMode;
- return true;
-}
-
-BOOL MYODBCInsDataSource::setScope( DATASOURCE_SCOPE nScope )
-{
- this->nScope = nScope;
- return true;
-}
-
-/*
-QString MYODBCInsDataSource::getDriverFileName()
-{
- DBUG_ENTER("MYODBCInsDataSource::getName");
-
- return stringDriverFileName;
-}
-*/
-
-QString MYODBCInsDataSource::getName()
-{
- return stringName;
-}
-
-QString MYODBCInsDataSource::getDRIVER()
-{
- return hashAttributes["DRIVER"];
-}
-
-QString MYODBCInsDataSource::getDESCRIPTION()
-{
- return hashAttributes["DESCRIPTION"];
-}
-
-QString MYODBCInsDataSource::getSERVER()
-{
- return hashAttributes["SERVER"];
-}
-
-QString MYODBCInsDataSource::getUID()
-{
- return hashAttributes["UID"];
-}
-
-QString MYODBCInsDataSource::getPWD()
-{
- return hashAttributes["PWD"];
-}
-
-QString MYODBCInsDataSource::getDATABASE()
-{
- return hashAttributes["DATABASE"];
-}
-
-QString MYODBCInsDataSource::getPORT()
-{
- return hashAttributes["PORT"];
-}
-
-QString MYODBCInsDataSource::getSOCKET()
-{
- return hashAttributes["SOCKET"];
-}
-
-QString MYODBCInsDataSource::getSTMT()
-{
- return hashAttributes["STMT"];
-}
-
-QString MYODBCInsDataSource::getOPTION()
-{
- return hashAttributes["OPTION"];
-}
-
-MYODBCInsDataSource::DATASOURCE_MODE MYODBCInsDataSource::getMode()
-{
- return nMode;
-}
-
-MYODBCInsDataSource::DATASOURCE_SCOPE MYODBCInsDataSource::getScope()
-{
- return nScope;
-}
-
-BOOL MYODBCInsDataSource::doRead( const QString &stringDataSourceName,
DATASOURCE_SCOPE nScope )
-{
- DBUG_ENTER("MYODBCInsDataSource::doRead");
-
- SQLWCHAR sEntryNames[SQL_MAX_DSN_LENGTH * MYODBC_INS_MAX_DSN_NAMES];
- SQLWCHAR * psEntryName;
- SQLWCHAR sValue[4096];
- int nChars = 0;
- UWORD nScopeToRestore = ODBC_BOTH_DSN;
- BOOL bReturn = false;
- std::wstring msg;
-
- if ( stringDataSourceName.isEmpty() )
- {
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- if ( !SQLGetConfigMode( &nScopeToRestore ) )
- {
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- SQLSetConfigMode( (UWORD)nScope );
-
- *sEntryNames = '\0';
- MYODBCCString::QString_toWString( stringDataSourceName, &msg );
- if ( ( nChars = SQLGetPrivateProfileString( msg.c_str(), NULL, L"", sEntryNames,
sizeof(sEntryNames) / sizeof(SQLWCHAR), L"ODBC.INI" ) ) < 1 )
- goto doReadExit1;
-
-#if defined(WIN32)
- {
- int nLen = MYODBCCString::getStrLen( sEntryNames, SQL_MAX_DSN_LENGTH *
MYODBC_INS_MAX_DSN_NAMES );
-
- /*!
- \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 == DATASOURCE_SCOPE_BOTH && nLen < nChars &&
sEntryNames[nLen + 1 ] == '\0' )
- {
- *sEntryNames = '\0';
- SQLSetConfigMode( ODBC_SYSTEM_DSN );
-
- MYODBCCString::QString_toWString( stringDataSourceName, &msg );
- if ( ( nChars = SQLGetPrivateProfileString( msg.c_str(), NULL, NULL,
sEntryNames, sizeof(sEntryNames) / sizeof(SQLWCHAR), L"ODBC.INI" ) ) < 1 )
- goto doReadExit1;
- }
- }
-#endif
-
- /* Looks like things are going to work. Lets set DSN */
- stringName = stringDataSourceName;
-
- /* Scan result and return MYODBC_C_TRUE if we find a match */
- psEntryName = sEntryNames;
- while ( *psEntryName )
- {
- *sValue = '\0';
- MYODBCCString::QString_toWString( stringDataSourceName, &msg );
- if ( SQLGetPrivateProfileString( msg.c_str(), psEntryName, L"", sValue, sizeof(
sValue ) / sizeof(SQLWCHAR), L"ODBC.INI" ) > 0 )
- {
- QString stringEntryName( MYODBCCString::QString_fromWCharArray( psEntryName )
);
- QString stringEntryNameUpper = stringEntryName.toUpper();
- QString stringValue( MYODBCCString::QString_fromWCharArray( sValue ) );
-
- /*!
- \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 ( hashAttributes.contains( stringEntryNameUpper ) )
- hashAttributes[stringEntryNameUpper] = stringValue.trimmed();
- else
- {
- QString tmp_msg;
- tmp_msg.sprintf( "Unknown attribute (%ls).", psEntryName );
- DBUG_PRINT("oerror", ("%s", (const char *)(tmp_msg.toUtf8())));
- }
- }
- else
- {
- QString tmp_msg;
- tmp_msg.sprintf( "Failed to get value for attribute (%ls).", psEntryName );
- DBUG_PRINT("owarn", ("%s", (const char *)(tmp_msg.toUtf8())));
- }
-
- psEntryName += MYODBCCString::getStrLen( psEntryName, SQL_MAX_DSN_LENGTH *
MYODBC_INS_MAX_DSN_NAMES ) + 1;
- } /* while */
-
- bReturn = true;
-
-doReadExit1:
- /* lets not loose the error message while we restore our scope */
- {
- QString stringError;
- DWORD nError = 0;
-
- if ( !bReturn )
- MYODBCIns::getError( 1, &nError, stringError );
-
- SQLSetConfigMode( nScopeToRestore );
-
- if ( !bReturn && !stringError.isEmpty() )
- MYODBCIns::setError( stringError, nError );
- }
-
- DBUG_PRINT("oreturn", ( "%d", bReturn ));
- DBUG_RETURN( bReturn );
-}
-
-BOOL MYODBCInsDataSource::doRead( const QString &stringDataSourceName )
-{
- return doRead( stringDataSourceName, nScope );
-}
-
-BOOL MYODBCInsDataSource::doRead()
-{
- return doRead( stringName, nScope );
-}
-
-BOOL MYODBCInsDataSource::doWrite( DATASOURCE_SCOPE nScope )
-{
- DBUG_ENTER("MYODBCInsDataSource::doWrite");
-
- BOOL bReturn = false;
- UWORD nScopeToRestore = ODBC_BOTH_DSN;
- std::wstring msg1, msg2, msg3;
-
- if ( !SQLGetConfigMode( &nScopeToRestore ) )
- {
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- if ( !SQLSetConfigMode( (UWORD)nScope ) )
- {
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- /*!
- \internal ODBC RULE
-
- SQLWriteDSNToIni is *supposed* to replace any existing DSN with same name but
fails to
- do so. So we ensure that any existing DSN with same name is removed with the
following call.
- This is particularly important when saving attributes which have an empty value
but used
- to have a non-empty value as empty value attributes are ignored during save.
- */
- MYODBCCString::QString_toWString( stringName, &msg1 );
- if ( !SQLRemoveDSNFromIni( msg1.c_str() ) )
- goto doWriteExit1;
-
- /* create/replace data source name */
- MYODBCCString::QString_toWString( hashAttributes["DRIVER"], &msg2 );
- if ( !SQLWriteDSNToIni( msg1.c_str(), msg2.c_str() ) )
- goto doWriteExit1;
-
- /* add attributes */
- {
- QHash<QString, QString>::const_iterator i = hashAttributes.constBegin();
- while ( i != hashAttributes.constEnd() )
- {
- if ( !i.value().isEmpty() )
- {
- MYODBCCString::QString_toWString( i.key(), &msg2 );
- MYODBCCString::QString_toWString( i.value(), &msg3 );
- if ( !SQLWritePrivateProfileString( msg1.c_str(), msg2.c_str(),
msg3.c_str(), L"odbc.ini" ) )
- goto doWriteExit1;
- }
- ++i;
- }
- }
-
- bReturn = true;
-
-doWriteExit1:
- /* lets not loose the error message while we restore our scope */
- {
- QString stringError;
- DWORD nError = 0;
-
- if ( !bReturn )
- MYODBCIns::getError( 1, &nError, stringError );
-
- SQLSetConfigMode( nScopeToRestore );
-
- if ( !bReturn && !stringError.isEmpty() )
- MYODBCIns::setError( stringError, nError );
- }
-
- DBUG_PRINT("oreturn", ( "%d", bReturn ));
- DBUG_RETURN( bReturn );
-}
-
-BOOL MYODBCInsDataSource::doWrite()
-{
- return doWrite( nScope );
-}
-
-void MYODBCInsDataSource::doClear()
-{
- DBUG_ENTER("MYODBCInsDataSource::doClear");
-
- /* do not change the nMode nor nScope */
- /*!
- \brief DSN fields.
-
- This reflects what we can have in odbc.ini.
- */
- hashAttributes["DRIVER"] = QString::null; /*!< As used in DSN; often the
abs path to driver. (ie "/usr/lib/libmyodbc3.so") */
- hashAttributes["DESCRIPTION"] = QString::null; /*!< General description or
long name of DSN. */
- hashAttributes["SERVER"] = QString::null; /*!< The hostname of the MySQL
server. */
- hashAttributes["UID"] = QString::null; /*!< The username used to
connect to MySQL. */
- hashAttributes["PWD"] = QString::null; /*!< The password for the
server user combination. */
- hashAttributes["DATABASE"] = QString::null; /*!< The default database.
*/
- hashAttributes["PORT"] = QString::null; /*!< The TCP/IP port to use if
SERVER is not localhost. */
- hashAttributes["SOCKET"] = QString::null; /*!< Unix socket file or
Windows named pipe to connect to. */
- hashAttributes["STMT"] = QString::null; /*!< Statement that will be
exec when connecting to MySQL. */
- hashAttributes["OPTION"] = QString::null; /*!< Options that specify how
MyODBC should work. */
-
- DBUG_VOID_RETURN;
-}
-
-BOOL MYODBCInsDataSource::doDelete( const QString &stringDataSourceName )
-{
- DBUG_ENTER("MYODBCInsDataSource::doDelete");
-
- std::wstring msg;
- MYODBCCString::QString_toWString( stringDataSourceName, &msg );
- BOOL bReturn = SQLRemoveDSNFromIni( msg.c_str() );
-
- DBUG_PRINT("oreturn", ( "%d", bReturn ));
- DBUG_RETURN( bReturn );
-}
-
-BOOL MYODBCInsDataSource::isValidAttributes( const QHash<QString,QString>
&hashAttributes, BOOL bStrict )
-{
- DBUG_ENTER("MYODBCInsDataSource::isValidAttributes");
-
- /* validate keywords */
- QHash<QString, QString>::const_iterator i = hashAttributes.constBegin();
- while ( i != hashAttributes.constEnd() )
- {
- if ( !this->hashAttributes.contains( i.key() ) )
- {
- if ( i.key() != "DSN" || bStrict ) // exception for DSN as we can handle that
by mapping to Name
- {
- MYODBCIns::setError( QString( "[%1][%2][ERROR] %3 is an unsupported
attribute." ).
- arg( __FILE__ ).arg( __LINE__ ).arg( i.key() ) );
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
- }
- ++i;
- }
-
- DBUG_PRINT("oreturn", ( "%d", true ));
- DBUG_RETURN( true );
-}
-
-MYODBCInsDataSource MYODBCInsDataSource::operator=( MYODBCInsDataSource rval )
-{
- DBUG_ENTER("MYODBCInsDataSource::operator=");
- hashAttributes = rval.hashAttributes;
-
- stringName = rval.stringName;
- nScope = rval.nScope;
-
- DBUG_RETURN(*this);
-}
-
-QTextStream &operator<<( QTextStream &stream, const MYODBCInsDataSource
&rval )
-{
- DBUG_ENTER("MYODBCInsDataSource::operator<<");
- stream << "Name : " << rval.stringName << endl;
-
- QHash<QString, QString>::const_iterator i = rval.hashAttributes.constBegin();
- while ( i != rval.hashAttributes.constEnd() )
- {
- stream << i.key() << " : " << i.value() << endl;
- ++i;
- }
-
- DBUG_RETURN(stream);
-}
-
-
Deleted: trunk/SDK/Installer/Library/MYODBCInsDriver.cpp
===================================================================
--- trunk/SDK/Installer/Library/MYODBCInsDriver.cpp 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/Installer/Library/MYODBCInsDriver.cpp 2007-05-22 18:47:33 UTC (rev 925)
@@ -1,244 +0,0 @@
-/*!
- \file MYODBCInsDriver.cpp
- \author Peter Harvey <pharvey@stripped>
- Copyright (C) MySQL AB 2004-2007, Released under GPL.
- \version Connector/ODBC v5
- \date 2007
- \brief Code to provide abstraction and portability for I/O of ODBC installer
information.
-
- \license GPL
-
- 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()
-{
- DBUG_ENTER("MYODBCInsDriver::getFriendlyName");
-
- DBUG_PRINT("oreturn", ("%s", ( (const char *)stringFriendlyName.toUtf8() )));
- DBUG_RETURN( stringFriendlyName );
-}
-
-QString MYODBCInsDriver::getDRIVER()
-{
- DBUG_ENTER("MYODBCInsDriver::getDRIVER");
-
- DBUG_PRINT("oreturn", ("%s", ( (const char *)stringDRIVER.toUtf8() )));
- DBUG_RETURN( stringDRIVER );
-}
-
-QString MYODBCInsDriver::getSETUP()
-{
- DBUG_ENTER("MYODBCInsDriver::getSETUP");
-
- DBUG_PRINT("oreturn", ("%s", ( (const char *)stringSETUP.toUtf8() )));
- DBUG_RETURN( stringSETUP );
-}
-
-SQLWCHAR *MYODBCInsDriver::getAttributesNullDelim( const QString &stringFriendlyName,
const QString &stringDRIVER, const QString &stringSETUP )
-{
- DBUG_ENTER("MYODBCInsDriver::getAttributesNullDelim");
-
- /* the 25 is for the attribute names, equal signs, and nulls */
- int nBuffer = (stringFriendlyName.length() +
- stringDRIVER.length() +
- stringSETUP.length() +
- 25) * sizeof(SQLWCHAR);
- SQLWCHAR * pszBuffer = (SQLWCHAR*) malloc( nBuffer );
- SQLWCHAR * pcInsertPos = pszBuffer;
- std::wstring msg;
-
- /* friendly name */
- MYODBCCString::QString_toWCharArray( stringFriendlyName, pcInsertPos,
stringFriendlyName.length() + 1 );
- pcInsertPos += stringFriendlyName.length() + 1;
-
- /* DRIVER */
- memcpy(pcInsertPos, L"DRIVER=", 7 * sizeof(SQLWCHAR));
- pcInsertPos += 7;
-
- MYODBCCString::QString_toWCharArray( stringDRIVER, pcInsertPos, stringDRIVER.length()
+ 1 );
- pcInsertPos += stringDRIVER.length() + 1;
-
- /* SETUP */
- memcpy(pcInsertPos, L"SETUP=", 6 * sizeof(SQLWCHAR));
- pcInsertPos += 6;
-
- MYODBCCString::QString_toWCharArray( stringSETUP, pcInsertPos, stringSETUP.length() +
1 );
- pcInsertPos += stringSETUP.length();
-
- /* we have terminated keyword/value pairs with null now extra null to terminate the
whole thing */
- pcInsertPos[0] = '\0';
- pcInsertPos[1] = '\0';
-
- DBUG_DUMP("return", (char*) pszBuffer, nBuffer);
- DBUG_RETURN( pszBuffer );
-}
-
-BOOL MYODBCInsDriver::doRead( const QString &stringFriendlyName )
-{
- DBUG_ENTER("MYODBCInsDriver::doRead");
-
- SQLWCHAR szEntryNames[SQL_MAX_DSN_LENGTH * MYODBC_INS_MAX_DSN_NAMES];
- SQLWCHAR * psEntryName;
- SQLWCHAR szValue[4096];
- std::wstring msg;
-
- if ( stringFriendlyName.isEmpty() )
- {
- MYODBCIns::setError( "invalid data source name" );
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- *szEntryNames = '\0';
- MYODBCCString::QString_toWString( stringFriendlyName, &msg );
- int nChars = SQLGetPrivateProfileString( msg.c_str(), NULL, L"", szEntryNames,
sizeof(szEntryNames) / sizeof(SQLWCHAR), L"ODBCINST.INI" );
- if ( nChars < 1 )
- {
- MYODBCIns::setError( "data source name not found" );
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- /* we avoid 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.
- */
- psEntryName = szEntryNames;
- while ( *psEntryName )
- {
- *szValue = '\0';
- MYODBCCString::QString_toWString( stringFriendlyName, &msg );
- if ( SQLGetPrivateProfileString( msg.c_str(), psEntryName, L"", szValue,
sizeof(szValue) / sizeof(SQLWCHAR), L"ODBCINST.INI" ) > 0 )
- {
- QString stringEntryName = MYODBCCString::QString_fromWCharArray( psEntryName
);
-
- if ( QString::localeAwareCompare( stringEntryName.toUpper(), "DRIVER" ) == 0
)
- {
- if ( stringDRIVER.isEmpty() )
- stringDRIVER = MYODBCCString::QString_fromWCharArray( szValue );
- }
- else if ( QString::localeAwareCompare( stringEntryName.toUpper(), "SETUP" )
== 0 )
- {
- if ( stringSETUP.isEmpty() )
- stringSETUP = MYODBCCString::QString_fromWCharArray( szValue );
- }
- else
- {
- /* What the ? */
- }
- }
- psEntryName += MYODBCCString::getStrLen( psEntryName, SQL_MAX_DSN_LENGTH *
MYODBC_INS_MAX_DSN_NAMES ) + 1;
- } /* while */
-
- DBUG_RETURN( true );
-}
-
-BOOL MYODBCInsDriver::doWrite()
-{
- DBUG_ENTER("MYODBCInsDriver::doWrite");
-
- SQLWCHAR szPathOut[1024];
- WORD nPathOutLength = 0;
- DWORD nUsageCount = 0;
- SQLWCHAR * pszAttributes = getAttributesNullDelim(stringFriendlyName,
stringDRIVER, stringSETUP);
- BOOL bRetCode = SQLInstallDriverEx( pszAttributes, NULL, szPathOut,
sizeof(szPathOut) / sizeof(SQLWCHAR), &nPathOutLength, ODBC_INSTALL_COMPLETE,
&nUsageCount );
-
- free( pszAttributes);
-
- DBUG_PRINT("oreturn", ( "%d", bRetCode ));
- DBUG_RETURN( bRetCode );
-}
-
-void MYODBCInsDriver::doClear()
-{
- DBUG_ENTER("MYODBCInsDriver::doClear");
-
- stringFriendlyName = QString::null;
- stringDRIVER = QString::null;
- stringSETUP = QString::null;
-
- DBUG_VOID_RETURN;
-}
-
-BOOL MYODBCInsDriver::doDelete( const QString &stringDriverName, BOOL
bRemoveDataSourceNames, LPDWORD pnUsageCount )
-{
- DBUG_ENTER("MYODBCInsDriver::doDelete");
-
- std::wstring msg;
- BOOL b;
-
- MYODBCCString::QString_toWString( stringDriverName, &msg );
- b = SQLRemoveDriver( msg.c_str(), bRemoveDataSourceNames, pnUsageCount );
-
- DBUG_PRINT("oreturn", ( "%d", b ));
- DBUG_RETURN( b );
-}
-
-MYODBCInsDriver MYODBCInsDriver::operator=( MYODBCInsDriver rval )
-{
- DBUG_ENTER("MYODBCInsDriver::operator=");
- stringFriendlyName = rval.stringFriendlyName;
- stringDRIVER = rval.stringDRIVER;
- stringSETUP = rval.stringSETUP;
-
- DBUG_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, const MYODBCInsDriver
&rval )
-{
- DBUG_ENTER("MYODBCInsDriver::operator<<");
- stream << "FriendlyName: " << rval.stringFriendlyName << endl;
- stream << "DRIVER : " << rval.stringDRIVER << endl;
- stream << "SETUP : " << rval.stringSETUP << endl;
-
- DBUG_RETURN(stream);
-}
-
Deleted: trunk/SDK/Installer/Library/MYODBCInsDriverConnect.cpp
===================================================================
--- trunk/SDK/Installer/Library/MYODBCInsDriverConnect.cpp 2007-05-22 18:30:28 UTC (rev
924)
+++ trunk/SDK/Installer/Library/MYODBCInsDriverConnect.cpp 2007-05-22 18:47:33 UTC (rev
925)
@@ -1,478 +0,0 @@
-/*!
- \file MYODBCInsDriverConnect.cpp
- \author Peter Harvey <pharvey@stripped>
- Copyright (C) MySQL AB 2004-2007, Released under GPL.
- \version Connector/ODBC v5
- \date 2007
- \brief Code to provide abstraction and portability for I/O of ODBC installer
information.
-
- \license GPL
-
- 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( DRIVERCONNECT_PROMPT nPrompt )
-{
- DBUG_ENTER("MYODBCInsDriverConnect::MYODBCInsDriverConnect");
-
- this->nPrompt = nPrompt;
-
- /*
- These are the attributes we expect to find in a connection string.
-
- 1. All DSN attributes are valid here but not all connection string attributes are
valid for DSN.
- 2. The DSN and DRIVER attributes are mutually exclusive (1st is valid other is
filtered out).
- 3. Duplicates should not exist (1st is valid rest filtered out).
- */
- vectorAttributesValid.append( "DSN" ); /*!< Data Source Name.
*/
- vectorAttributesValid.append( "DRIVER" ); /*!< Friendly driver name.
*/
- vectorAttributesValid.append( "DESCRIPTION" ); /*!< General description or long
name of DSN. */
- vectorAttributesValid.append( "SERVER" ); /*!< The hostname of the MySQL
server. */
- vectorAttributesValid.append( "UID" ); /*!< The username used to connect
to MySQL. */
- vectorAttributesValid.append( "PWD" ); /*!< The password for the server
user combination. */
- vectorAttributesValid.append( "DATABASE" ); /*!< The default database.
*/
- vectorAttributesValid.append( "PORT" ); /*!< The TCP/IP port to use if
SERVER is not localhost. */
- vectorAttributesValid.append( "SOCKET" ); /*!< Unix socket file or Windows
named pipe to connect to. */
- vectorAttributesValid.append( "STMT" ); /*!< Statement that will be exec
when connecting to MySQL. */
- vectorAttributesValid.append( "OPTION" ); /*!< Options that specify how
MyODBC should work. */
- vectorAttributesValid.append( "FILEDSN" ); /*!< This is to support case where
app is linked directly to driver. */
- vectorAttributesValid.append( "SAVEFILE" ); /*!< This is to support case where
app is linked directly to driver. */
-
- doClear();
-
- DBUG_VOID_RETURN;
-}
-
-BOOL MYODBCInsDriverConnect::setAttributes( const QString &stringAttributes )
-{
- DBUG_ENTER("MYODBCInsDriverConnect::setAttributes");
-
- /*!
- \internal MYODBC RULE
-
- Null values mean that we have not been given the attribute. An empty value means
- that we were given attribute but just keyword - no value.
- */
- /* set all fields to null */
- doClear();
-
- /* parse attributes string */
- if ( !MYODBCIns::getKeywordValues( &hashAttributes, stringAttributes,
MYODBCIns::DELIM_SEMI ) )
- {
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- /* DSN or DRIVER based? */
- if ( !getDRIVER().isNull() )
- setMethod( DRIVERCONNECT_METHOD_DRIVER );
- else if ( !getDSN().isNull() )
- setMethod( DRIVERCONNECT_METHOD_DSN );
- else
- {
- /* this is done by DM but app may be linked to us directly so... */
- setDSN( "DEFAULT" );
- setMethod( DRIVERCONNECT_METHOD_DSN );
- }
-
- /*!
- \internal ODBC RULE
-
- If the connection string contains the DSN keyword, the driver
- retrieves the information for the specified data source (and
- merges it into given connection info with given connection info
- having precedence).
- */
- if ( getMethod() == DRIVERCONNECT_METHOD_DSN )
- {
- if ( !MYODBCIns::isExistsDataSourceName( getDSN(),
MYODBCInsDataSource::DATASOURCE_SCOPE_BOTH ) )
- {
- if ( getDSN() == "DEFAULT" )
- {
- MYODBCIns::setError( QString( "[%1][%2][ERROR] Could not find 'DEFAULT'
DSN in system information." ).arg( __FILE__ ).arg( __LINE__ ) );
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
- }
- else if ( !doRead() )
- {
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
- }
-
- /* at this point we should have DRIVER attribute (if not we try to carry on)... */
- if ( getDRIVER().isEmpty() )
- MYODBCIns::setError( QString( "[%1][%2][WARNING] DRIVER attribute missing."
).arg( __FILE__ ).arg( __LINE__ ) );
-
- /* we *must* have SETUP if we are going to do any prompting... */
- setSETUP( getSETUP( getDRIVER() ) );
- if ( getSETUP().isEmpty() )
- MYODBCIns::setError( QString( "[%1][%2][WARNING] Could not determine SETUP
attribute." ).arg( __FILE__ ).arg( __LINE__ ) );
-
- DBUG_PRINT("oreturn", ( "%d", true ));
- DBUG_RETURN( true );
-}
-
-BOOL MYODBCInsDriverConnect::setDSN( const QString &stringDSN )
-{
- hashAttributes["DSN"] = stringDSN;
- return true;
-}
-
-BOOL MYODBCInsDriverConnect::setDRIVER( const QString &stringDRIVER )
-{
- hashAttributes["DRIVER"] = stringDRIVER;
- return true;
-}
-
-BOOL MYODBCInsDriverConnect::setDESCRIPTION( const QString &stringDESCRIPTION )
-{
- hashAttributes["DESCRIPTION"] = stringDESCRIPTION;
- return true;
-}
-
-BOOL MYODBCInsDriverConnect::setSERVER( const QString &stringSERVER )
-{
- hashAttributes["SERVER"] = stringSERVER;
- return true;
-}
-
-BOOL MYODBCInsDriverConnect::setUID( const QString &stringUID )
-{
- hashAttributes["UID"] = stringUID;
- return true;
-}
-
-BOOL MYODBCInsDriverConnect::setPWD( const QString &stringPWD )
-{
- hashAttributes["PWD"] = stringPWD;
- return true;
-}
-
-BOOL MYODBCInsDriverConnect::setDATABASE( const QString &stringDATABASE )
-{
- hashAttributes["DATABASE"] = stringDATABASE;
- return true;
-}
-
-BOOL MYODBCInsDriverConnect::setPORT( const QString &stringPORT )
-{
- hashAttributes["PORT"] = stringPORT;
- return true;
-}
-
-BOOL MYODBCInsDriverConnect::setSOCKET( const QString &stringSOCKET )
-{
- hashAttributes["SOCKET"] = stringSOCKET;
- return true;
-}
-
-BOOL MYODBCInsDriverConnect::setSTMT( const QString &stringSTMT )
-{
- hashAttributes["STMT"] = stringSTMT;
- return true;
-}
-
-BOOL MYODBCInsDriverConnect::setOPTION( const QString &stringOPTION )
-{
- hashAttributes["OPTION"] = stringOPTION;
- return true;
-}
-
-BOOL MYODBCInsDriverConnect::setSETUP( const QString &stringSETUP )
-{
- this->stringSETUP = stringSETUP;
- return true;
-}
-
-BOOL MYODBCInsDriverConnect::setMethod( DRIVERCONNECT_METHOD nMethod )
-{
- this->nMethod = nMethod;
- return true;
-}
-
-BOOL MYODBCInsDriverConnect::setPrompt( DRIVERCONNECT_PROMPT nPrompt )
-{
- this->nPrompt = nPrompt;
- return true;
-}
-
-BOOL MYODBCInsDriverConnect::setFILEDSN( const QString &stringFILEDSN )
-{
- hashAttributes["FILEDSN"] = stringFILEDSN;
- return true;
-}
-
-BOOL MYODBCInsDriverConnect::setSAVEFILE( const QString &stringSAVEFILE )
-{
- hashAttributes["SAVEFILE"] = stringSAVEFILE;
- return true;
-}
-
-QString MYODBCInsDriverConnect::getAttributes()
-{
- DBUG_ENTER("MYODBCInsDriverConnect::getAttributes");
-
- QString stringConnect;
-
- QHash<QString, QString>::const_iterator i = hashAttributes.constBegin();
- while ( i != hashAttributes.constEnd() )
- {
- if ( !i.value().isNull() ) // empty is ok but skip null
- {
- if ( !stringConnect.isEmpty() )
- stringConnect += QChar( ';' );
- stringConnect += i.key();
- stringConnect += QChar( '=' );
- stringConnect += i.value();
- }
- ++i;
- }
-
- DBUG_PRINT("oreturn", ("%s", ( (const char *) stringConnect.toUtf8() )));
- DBUG_RETURN( stringConnect );
-}
-
-QString MYODBCInsDriverConnect::getDSN()
-{
- return hashAttributes["DSN"];
-}
-
-QString MYODBCInsDriverConnect::getDRIVER()
-{
- return hashAttributes["DRIVER"];
-}
-
-QString MYODBCInsDriverConnect::getDESCRIPTION()
-{
- return hashAttributes["DESCRIPTION"];
-}
-
-QString MYODBCInsDriverConnect::getSERVER()
-{
- return hashAttributes["SERVER"];
-}
-
-QString MYODBCInsDriverConnect::getUID()
-{
- return hashAttributes["UID"];
-}
-
-QString MYODBCInsDriverConnect::getPWD()
-{
- return hashAttributes["PWD"];
-}
-
-QString MYODBCInsDriverConnect::getDATABASE()
-{
- return hashAttributes["DATABASE"];
-}
-
-QString MYODBCInsDriverConnect::getPORT()
-{
- return hashAttributes["PORT"];
-}
-
-QString MYODBCInsDriverConnect::getSOCKET()
-{
- return hashAttributes["SOCKET"];
-}
-
-QString MYODBCInsDriverConnect::getSTMT()
-{
- return hashAttributes["STMT"];
-}
-
-QString MYODBCInsDriverConnect::getOPTION()
-{
- return hashAttributes["OPTION"];
-}
-
-QString MYODBCInsDriverConnect::getSETUP()
-{
- return stringSETUP;
-}
-
-MYODBCInsDriverConnect::DRIVERCONNECT_METHOD MYODBCInsDriverConnect::getMethod()
-{
- DBUG_ENTER("MYODBCInsDriverConnect::getMethod");
-
- DBUG_PRINT("oreturn", ( "%d", nMethod ));
- DBUG_RETURN( nMethod );
-}
-
-MYODBCInsDriverConnect::DRIVERCONNECT_PROMPT MYODBCInsDriverConnect::getPrompt()
-{
- DBUG_ENTER("MYODBCInsDriverConnect::getPrompt");
-
- DBUG_PRINT("oreturn", ( "%d", nPrompt ));
- DBUG_RETURN( nPrompt );
-}
-
-QString MYODBCInsDriverConnect::getFILEDSN()
-{
- return hashAttributes["FILEDSN"];
-}
-
-QString MYODBCInsDriverConnect::getSAVEFILE()
-{
- return hashAttributes["SAVEFILE"];
-}
-
-QString MYODBCInsDriverConnect::getSETUP( const QString &stringDRIVER )
-{
- DBUG_ENTER("MYODBCInsDriverConnect::getSETUP");
-
- /*!
- \internal ODBC RULE
-
- Because the DRIVER keyword does not use information from the system information,
- the driver must define enough keywords so that a driver can connect to a data
- source using only the information in the connection string.
-
- If the connection string contains the DRIVER keyword, the driver cannot
- retrieve information about the data source from the system information.
-
- \note
-
- Problem; we are going to use DRIVER attribute and prompting - but we
- can not go after the system information to get the path/file of the
- setup library.
-
- 1. We can ignore this ODBC RULE and get the path/file from the system
- information.
-
- 2. We can include GUI bits for prompting in the driver itself but that would
- increase the dependencies of the driver greatly and not allow the prompt
- to be plugable.
-
- 3. We can hardcode the path/file but that would greatly reduce the flexability
- during installation.
-
- 4. We can extend the list of viable attributes to include SETUP which can be
- path/file to the setup library - but generic apps would not know to use
- this.
-
- 5. We can get the path/file from an environment variable (MYODBC_SETUP).
-
- Solution; we will get the setup path/file using several of the above in the
- following order.
-
- a. SETUP connection string attribute. If SETUP attribute is defined, when we go
- to prompt, but is empty or invalid we will return an error.
- b. MYODBC_SETUP environment variable. If MYODBC_SETUP is defined, when we go
- to prompt, but is empty or invalid we will return an error.
- c. Ignore the ODBC RULE. In this case we will try to get path/file from ODBC
- system information.
-
- We assume we are only being called because (a) did not result in a SETUP value.
- */
- QString stringSETUP;
-
- if ( getenv( "MYODBC_SETUP" ) )
- {
- stringSETUP = getenv( "MYODBC_LOG" );
- }
- else
- {
- MYODBCInsDriver driver;
- if ( driver.doRead( stringDRIVER.isEmpty() ? "MySQL Connector/ODBC v5" :
stringDRIVER ) )
- stringSETUP = driver.getSETUP();
- }
-
- DBUG_PRINT("oreturn", ("%s", ( (const char *) stringSETUP.toUtf8() )));
- DBUG_RETURN( stringSETUP );
-}
-
-void MYODBCInsDriverConnect::doClear()
-{
- DBUG_ENTER("MYODBCInsDriverConnect::doClear");
-
- /* DO NOT clear nPrompt here */
- nMethod = DRIVERCONNECT_METHOD_UNKNOWN;
- hashAttributes.clear();
- stringSETUP.clear();
-
- DBUG_VOID_RETURN;
-}
-
-/*!
- \brief Merge DSN in system information (if any) into existing attributes.
-
- This is only relevant when we are DRIVERCONNECT_METHOD_DSN and have a
- DSN attribute and the DSN exists in system information - in all other
- cases this call does nothing.
-
- By 'merge' we mean that the system information will be used to try to
- add missing/unset attributes - attributes we already have are NOT
- replaced.
-*/
-BOOL MYODBCInsDriverConnect::doRead()
-{
- DBUG_ENTER("MYODBCInsDriverConnect::doRead");
-
- /* some sanity checks... */
- if ( getMethod() != DRIVERCONNECT_METHOD_DSN )
- {
- MYODBCIns::setError( QString( "[%1][%2][ERROR] doRead only relevant for
DRIVERCONNECT_METHOD_DSN." ).arg( __FILE__ ).arg( __LINE__ ) );
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- if ( getDSN().isEmpty() )
- {
- MYODBCIns::setError( QString( "[%1][%2][ERROR] doRead only relevant when we have
a DSN." ).arg( __FILE__ ).arg( __LINE__ ) );
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- if ( !MYODBCIns::isExistsDataSourceName( getDSN(),
MYODBCInsDataSource::DATASOURCE_SCOPE_BOTH ) )
- {
- MYODBCIns::setError( QString( "[%1][%2][ERROR] DSN %3 does not exist." ).arg(
__FILE__ ).arg( __LINE__ ).arg( getDSN() ) );
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- /* read data source... */
- MYODBCInsDataSource datasource;
-
- datasource.setMode( MYODBCInsDataSource::DATASOURCE_MODE_DSN_VIEW );
- datasource.setScope( MYODBCInsDataSource::DATASOURCE_SCOPE_BOTH );
- if ( !datasource.doRead( getDSN() ) )
- {
- DBUG_PRINT("oreturn", ( "%d", false ));
- DBUG_RETURN( false );
- }
-
- /* merge... */
- QHash<QString, QString>::const_iterator i =
datasource.hashAttributes.constBegin();
- while ( i != datasource.hashAttributes.constEnd() )
- {
- if ( !hashAttributes.contains( i.key() ) )
- hashAttributes[i.key()] = i.value();
- ++i;
- }
-
- DBUG_PRINT("oreturn", ( "%d", true ));
- DBUG_RETURN( true );
-}
-
-
Deleted: trunk/SDK/Installer/Library/MYODBCInsInternal.h
===================================================================
--- trunk/SDK/Installer/Library/MYODBCInsInternal.h 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/Installer/Library/MYODBCInsInternal.h 2007-05-22 18:47:33 UTC (rev 925)
@@ -1,43 +0,0 @@
-/*!
- \file MYODBCInsInternal.h
- \author Peter Harvey <pharvey@stripped>
- Copyright (C) MySQL AB 2004-2007, Released under GPL.
- \version Connector/ODBC v5
- \date 2007
-
- \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
-*/
-
-#ifndef MYODBC_INS_INTERNAL_H
-#define MYODBC_INS_INTERNAL_H
-
-#include "../include/MYODBCIns.h"
-
-/* max dsn's we can have in odbc sys info - need to get rid of this limit */
-#define MYODBC_INS_MAX_DSN_NAMES 50
-
-#define MYODBC_INS_ODBCINI_HEADER_SECTION L"ODBC Data Sources"
-
-#include <myodbc_dbug.h>
-
-#endif
-
-
Added: trunk/SDK/Installer/Library/installer.c
===================================================================
--- trunk/SDK/Installer/Library/installer.c 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/Installer/Library/installer.c 2007-05-22 18:47:33 UTC (rev 925)
@@ -0,0 +1,524 @@
+/*!
+ \file installer.c
+ \author Jess Balint <jbalint@stripped>
+ Copyright (C) MySQL AB 2004-2007, Released under GPL.
+ \version Connector/ODBC v5
+ \date 2007
+ \brief Wrapper for some installer API functionality and structs
+ for drivers and data sources.
+
+ \license GPL
+
+ 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
+*/
+/*
+ * Installer wrapper implementations.
+ */
+#include "installer.h"
+
+/* ODBC Installer Config Wrapper */
+
+/*
+ * Convenience function to get the current config mode.
+ */
+UWORD config_get()
+{
+ UWORD mode;
+ SQLGetConfigMode(&mode);
+ return mode;
+}
+
+/*
+ * Convenience function to set the current config mode. Returns the
+ * mode in use when the function was called.
+ */
+UWORD config_set(UWORD mode)
+{
+ UWORD current = config_get();
+ SQLSetConfigMode(mode);
+ return current;
+}
+
+/* ODBC Installer Driver Wrapper */
+
+/*
+ * Create a new driver object. All string data is pre-allocated.
+ */
+Driver *driver_new()
+{
+ Driver *driver = malloc(sizeof(Driver));
+ if(!driver)
+ return NULL;
+ driver->name = malloc(ODBCDRIVER_STRLEN * sizeof(SQLWCHAR));
+ if(!driver->name)
+ {
+ free(driver);
+ return NULL;
+ }
+ driver->lib = malloc(ODBCDRIVER_STRLEN * sizeof(SQLWCHAR));
+ if(!driver->lib)
+ {
+ free(driver);
+ free(driver->name);
+ return NULL;
+ }
+ driver->setup_lib = malloc(ODBCDRIVER_STRLEN * sizeof(SQLWCHAR));
+ if(!driver->setup_lib)
+ {
+ free(driver);
+ free(driver->name);
+ free(driver->lib);
+ return NULL;
+ }
+ /* init to empty strings */
+ driver->name[0] = 0;
+ driver->lib[0] = 0;
+ driver->setup_lib[0] = 0;
+ return driver;
+}
+
+/*
+ * Delete an existing driver object.
+ */
+void driver_delete(Driver *driver)
+{
+ free(driver->name);
+ free(driver->lib);
+ free(driver->setup_lib);
+ free(driver);
+}
+
+/*
+ * Lookup a driver in the system. The driver name is read from the given
+ * object. If greater-than zero is returned, additional information
+ * can be obtained from SQLInstallerError(). A less-than zero return code
+ * indicates that the driver could not be found.
+ */
+int driver_lookup(Driver *driver)
+{
+ SQLWCHAR buf[4096];
+ SQLWCHAR *entries = buf;
+ SQLWCHAR *dest;
+
+ /* get entries and make sure the driver exists */
+ if(SQLGetPrivateProfileString(
+ driver->name, NULL, L"", buf, 4096, L"ODBCINST.INI") < 1)
+ return -1;
+
+ /* read the needed driver attributes */
+ while(*entries)
+ {
+ dest = NULL;
+ if(!wcscasecmp(L"DRIVER", entries))
+ dest = driver->lib;
+ else if(!wcscasecmp(L"SETUP", entries))
+ dest = driver->setup_lib;
+ else
+ { /* unknown/unused entry */ }
+
+ /* get the value if it's one we're looking for */
+ if(dest && SQLGetPrivateProfileString(driver->name, entries, L"",
+ dest, ODBCDRIVER_STRLEN, L"ODBCINST.INI") < 1)
+ return 1;
+
+ entries += wcslen(entries) + 1;
+ }
+
+ return 0;
+}
+
+/*
+ * Read the semi-colon delimited key-value pairs the attributes
+ * necessary to popular the driver object.
+ */
+int driver_from_kvpair_semicolon(Driver *driver, const SQLWCHAR *attrs)
+{
+ const SQLWCHAR *split;
+ const SQLWCHAR *end;
+ SQLWCHAR attribute[100];
+ SQLWCHAR *dest;
+
+ while(*attrs)
+ {
+ dest = NULL;
+
+ /* invalid key-value pair if no equals */
+ if((split = wcschr(attrs, L'=')) == NULL)
+ return 1;
+
+ /* get end of key-value pair */
+ if((end = wcschr(attrs, L';')) == NULL)
+ end = attrs + wcslen(attrs);
+
+ /* pull out the attribute name */
+ memcpy(attribute, attrs, (split - attrs) * sizeof(SQLWCHAR));
+ attribute[split - attrs] = 0; /* add null term */
+ split++;
+
+ /* if its one we want, copy it over */
+ if(!wcscasecmp(L"DRIVER", attribute))
+ dest = driver->lib;
+ else if(!wcscasecmp(L"SETUP", attribute))
+ dest = driver->setup_lib;
+ else
+ { /* unknown/unused attribute */ }
+
+ if(dest)
+ {
+ memcpy(dest, split, (end - split) * sizeof(SQLWCHAR));
+ dest[end - split] = 0; /* add null term */
+ }
+
+ /* advanced to next attribute */
+ attrs = end;
+ if(*end)
+ attrs++;
+ }
+
+ return 0;
+}
+
+/*
+ * Write the attributes of the driver object into key-value pairs
+ * separated by single NULL chars.
+ */
+int driver_to_kvpair_null(Driver *driver, SQLWCHAR *attrs, size_t attrslen)
+{
+ int x = swprintf(attrs, attrslen, L"%ws", driver->name);
+ attrslen -= x; attrs += x + 1;
+ x = swprintf(attrs, attrslen, L"Driver=%ws", driver->lib);
+ attrslen -= x; attrs += x + 1;
+ if(*driver->setup_lib)
+ {
+ swprintf(attrs, attrslen, L"Setup=%ws", driver->setup_lib);
+ attrslen -= x; attrs += x + 1;
+ }
+ *attrs = 0;
+ return 0;
+}
+
+/* ODBC Installer Data Source Wrapper */
+
+/*
+ * Create a new data source object.
+ */
+DataSource *ds_new()
+{
+ DataSource *ds = malloc(sizeof(DataSource));
+ if(!ds)
+ return NULL;
+
+ ds->name = NULL;
+ ds->driver = NULL;
+ ds->description = NULL;
+ ds->server = NULL;
+ ds->uid = NULL;
+ ds->pwd = NULL;
+ ds->database = NULL;
+ ds->port = 3306;
+ ds->socket = NULL;
+ ds->initstmt = NULL;
+
+ return ds;
+}
+
+/*
+ * Delete an existing data source object.
+ */
+void ds_delete(DataSource *ds)
+{
+ if(ds->name ) free(ds->name );
+ if(ds->driver ) free(ds->driver );
+ if(ds->description) free(ds->description);
+ if(ds->server ) free(ds->server );
+ if(ds->uid ) free(ds->uid );
+ if(ds->pwd ) free(ds->pwd );
+ if(ds->database ) free(ds->database );
+ if(ds->socket ) free(ds->socket );
+ if(ds->initstmt ) free(ds->initstmt );
+
+ free(ds);
+}
+
+/*
+ * Set a string attribute of a given data source object. THe string
+ * will be copied into the object.
+ */
+int ds_set_strattr(SQLWCHAR **attr, const SQLWCHAR *val)
+{
+ if(*attr)
+ free(*attr);
+ if(val)
+ *attr = wcsdup(val);
+ else
+ *attr = NULL;
+ return *attr || 0;
+}
+
+/*
+ * Same as ds_set_strattr, but allows truncating the given string. If
+ * charcount is zero, it will act the same as ds_set_strattr.
+ */
+int ds_set_strnattr(SQLWCHAR **attr, const SQLWCHAR *val, size_t charcount)
+{
+ if(*attr)
+ free(*attr);
+
+ if(charcount == 0)
+ charcount = wcslen(val);
+
+ if(val)
+ {
+ *attr = malloc((charcount + 1) * sizeof(SQLWCHAR));
+ memcpy(*attr, val, charcount * sizeof(SQLWCHAR));
+ (*attr)[charcount] = 0;
+ }
+ else
+ *attr = NULL;
+ return *attr || 0;
+}
+
+/*
+ * Internal function to map a parameter name of the data source object
+ * to the pointer needed to set the parameter. Only one of strdest or
+ * intdest will be set. strdest and intdest will be set for populating
+ * string (SQLWCHAR *) or int parameters.
+ */
+void ds_map_param(DataSource *ds, SQLWCHAR *param,
+ SQLWCHAR ***strdest, int **intdest)
+{
+ if(!wcscasecmp(L"DSN", param))
+ *strdest = &ds->name;
+ else if(!wcscasecmp(L"DRIVER", param))
+ *strdest = &ds->driver;
+ else if(!wcscasecmp(L"DESCRIPTION", param))
+ *strdest = &ds->description;
+ else if(!wcscasecmp(L"SERVER", param))
+ *strdest = &ds->server;
+ else if(!wcscasecmp(L"UID", param))
+ *strdest = &ds->uid;
+ else if(!wcscasecmp(L"PWD", param))
+ *strdest = &ds->pwd;
+ else if(!wcscasecmp(L"DATABASE", param))
+ *strdest = &ds->database;
+ else if(!wcscasecmp(L"SOCKET", param))
+ *strdest = &ds->socket;
+ else if(!wcscasecmp(L"INITSTMT", param))
+ *strdest = &ds->initstmt;
+ else if(!wcscasecmp(L"PORT", param))
+ *intdest = &ds->port;
+}
+
+/*
+ * Lookup a data source in the system. The name will be read from
+ * the object and the rest of the details will be populated.
+ */
+int ds_lookup(DataSource *ds)
+{
+ SQLWCHAR buf[8192];
+ SQLWCHAR *entries = buf;
+ SQLWCHAR **dest;
+ SQLWCHAR val[256];
+ int size;
+ int rc = 0;
+ UWORD config_mode = config_get();
+ int *intdest;
+
+ /* get entries and check if data source exists */
+ if((size = SQLGetPrivateProfileString(
+ ds->name, NULL, L"", buf, 8192, L"ODBC.INI")) < 1)
+ return -1;
+
+ /* Debug code to print the entries returned, char by char */
+ /*
+ {
+ int i;
+ for(i = 0; i < size; ++i)
+ printf("%wc - 0x%x\n", entries[i], entries[i]);
+ }
+ */
+
+#ifdef _WIN32
+ /*
+ * In Windows XP, there is a 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.
+ *
+ * See debug code above to print the exact data returned.
+ */
+ if(config_mode == ODBC_BOTH_DSN &&
+ /* two null chars or a null and some bogus character */
+ *(entries + wcslen(entries)) == 0 &&
+ (*(entries + wcslen(entries) + 1) > 0x7f ||
+ *(entries + wcslen(entries) + 1) == 0))
+ {
+ /* revert to system mode and try again */
+ config_set(ODBC_SYSTEM_DSN);
+ SQLGetPrivateProfileString(
+ ds->name, NULL, L"", buf, 8192, L"ODBC.INI");
+ }
+#endif
+
+ while(*entries)
+ {
+ dest = NULL;
+ intdest = NULL;
+
+ ds_map_param(ds, entries, &dest, &intdest);
+
+ if((dest || intdest) &&
+ SQLGetPrivateProfileString(ds->name, entries, L"",
+ val, ODBCDATASOURCE_STRLEN, L"ODBC.INI") < 1)
+ {
+ rc = 1;
+ goto end;
+ }
+ else if(dest)
+ ds_set_strattr(dest, val);
+ else if(intdest)
+ *intdest = wcstol(val, NULL, 10);
+
+ entries += wcslen(entries) + 1;
+ }
+
+end:
+ config_set(config_mode);
+ return rc;
+}
+
+int ds_from_kvpair(DataSource *ds, const SQLWCHAR *attrs, SQLWCHAR delim)
+{
+ const SQLWCHAR *split;
+ const SQLWCHAR *end;
+ SQLWCHAR **dest;
+ SQLWCHAR attribute[100];
+ int *intdest;
+
+ while(*attrs)
+ {
+ dest = NULL;
+ intdest = NULL;
+
+ if((split = wcschr(attrs, L'=')) == NULL)
+ return 1;
+
+ if((end = wcschr(attrs, delim)) == NULL)
+ end = attrs + wcslen(attrs);
+
+ memcpy(attribute, attrs, (split - attrs) * sizeof(SQLWCHAR));
+ attribute[split - attrs] = 0;
+ split++;
+
+ ds_map_param(ds, attribute, &dest, &intdest);
+
+ if(dest)
+ ds_set_strnattr(dest, split, end - split);
+ else if(intdest)
+ /* we know we have a ; or NULL at the end so we just let it go */
+ *intdest = wcstol(split, NULL, 10);
+
+ attrs = end;
+ if(*end)
+ attrs++;
+ }
+
+ return 0;
+}
+
+/*
+ * Utility method for ds_add() to add a single string
+ * property via the installer api.
+ */
+int ds_add_strprop(const SQLWCHAR *name,
+ const SQLWCHAR *propname, const SQLWCHAR *propval)
+{
+ /* don't write if its null or empty string */
+ if(propval && *propval)
+ return !SQLWritePrivateProfileString(
+ name, propname, propval, L"ODBC.INI");
+ return 0;
+}
+
+/*
+ * Utility method for ds_add() to add a single integer
+ * property via the installer api.
+ */
+int ds_add_intprop(const SQLWCHAR *name,
+ const SQLWCHAR *propname, int propval)
+{
+ SQLWCHAR buf[21];
+ if(!propval)
+ return 0;
+ swprintf(buf, 20, L"%d\n", propval);
+ return ds_add_strprop(name, propname, buf);
+}
+
+/*
+ * Add the given datasource to system. Call SQLInstallerError() to get
+ * further error details if non-zero is returned.
+ */
+int ds_add(DataSource *ds)
+{
+ /* Validate data source name */
+ if(!SQLValidDSN(ds->name))
+ return 1;
+
+ /* remove if exists, FYI SQLRemoveDSNFromIni returns true
+ * even if the dsn isnt found, false only if there is a failure */
+ if(!SQLRemoveDSNFromIni(ds->name))
+ return 1;
+
+ /* "Create" section for data source */
+ if(!SQLWriteDSNToIni(ds->name, ds->driver))
+ return 1;
+
+ /* write all fields (util method takes care of skipping blank fields) */
+ if(ds_add_strprop(ds->name, L"DRIVER" , ds->driver )) goto error;
+ if(ds_add_strprop(ds->name, L"DESCRIPTION", ds->description)) goto error;
+ if(ds_add_strprop(ds->name, L"SERVER" , ds->server )) goto error;
+ if(ds_add_strprop(ds->name, L"UID" , ds->uid )) goto error;
+ if(ds_add_strprop(ds->name, L"PWD" , ds->pwd )) goto error;
+ if(ds_add_strprop(ds->name, L"DATABASE" , ds->database )) goto error;
+ if(ds_add_strprop(ds->name, L"SOCKET" , ds->socket )) goto error;
+ if(ds_add_strprop(ds->name, L"INITSTMT" , ds->initstmt )) goto error;
+
+ if(ds_add_intprop(ds->name, L"PORT" , ds->port )) goto error;
+
+ return 0;
+
+error:
+ return 1;
+}
+
+/*
+ * Convenience method to check if data source exists. Set the dsn
+ * scope before calling this to narrow the check.
+ */
+int ds_exists(SQLWCHAR *name)
+{
+ SQLWCHAR buf[100];
+
+ /* get entries and check if data source exists */
+ if(SQLGetPrivateProfileString(name, NULL, L"", buf, 100, L"ODBC.INI"))
+ return 0;
+
+ return 1;
+}
+
Modified: trunk/SDK/Installer/Tests/MYODBCInsTest.cpp
===================================================================
--- trunk/SDK/Installer/Tests/MYODBCInsTest.cpp 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/Installer/Tests/MYODBCInsTest.cpp 2007-05-22 18:47:33 UTC (rev 925)
@@ -1,7 +1,7 @@
#include <QtTest/QtTest>
#include <QString>
#include <QFile>
-#include <MYODBCIns.h>
+#include <installer.h>
#include <myodbc_dbug.h>
// #define FILE_SEP "\\"
@@ -32,6 +32,7 @@
~MYODBCInsTest();
private slots:
+#if 0
void slotAttributeParsing();
void slotDataSource();
void slotDriverConnect();
@@ -43,6 +44,7 @@
void slotVerifyDeleteDataSourceName();
void slotDeregisterDriver();
void slotVerifyDeregisterDriver();
+#endif
};
MYODBCInsTest::MYODBCInsTest()
@@ -55,6 +57,7 @@
DBUG_POP();
}
+#if 0
/*
Test the MYODBCIns::getKeywordValues parsing of connect strings.
*/
@@ -455,6 +458,7 @@
QFAIL( "Failed to verify deregister driver." );
}
}
+#endif
QTEST_MAIN( MYODBCInsTest )
Deleted: trunk/SDK/Installer/include/MYODBCIns.h
===================================================================
--- trunk/SDK/Installer/include/MYODBCIns.h 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/Installer/include/MYODBCIns.h 2007-05-22 18:47:33 UTC (rev 925)
@@ -1,241 +0,0 @@
-/*!
- \file MYODBCIns.h
- \author Peter Harvey <pharvey@stripped>
- Copyright (C) MySQL AB 2004-2007, Released under GPL.
- \version Connector/ODBC v5
- \date 2007
- \brief Code to provide abstraction and portability for I/O of ODBC system
information information.
-
- \license GPL
-
- 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
-*/
-#ifndef MYODBC_INS_H
-#define MYODBC_INS_H
-
-#include <MYODBCInsDriver.h>
-#include <MYODBCInsDataSource.h>
-#include <MYODBCInsDriverConnect.h>
-
-/*!
- \brief Installer.
-
- This is basically a namespace to hold a variety of installer
- utilities. Any of the installer code which does not belong in
- the other classes gets placed in here - and typically as a
- 'static' to avoid having to really instantiate the class.
-
- \sa MYODBCInsDriver
- MYODBCInsDataSource
- MYODBCInsDriverConnect
-*/
-class MYODBCIns
-{
-public:
-
- /*!
- \brief Delimiter type used for an attribute string.
- \note See internal doc for pit-falls of using DELIM_BOTH
-
- */
- typedef enum tDELIM
- {
- DELIM_NULL,
- DELIM_SEMI,
- DELIM_BOTH
-
- } DELIM;
-
- /*!
- \brief Parse state.
-
- These are the different states we can be in while parsing
- an attributes string.
- */
- typedef enum tPARSE_STATE
- {
- PARSE_STATE_NAME_START, /*!< looking for start of name
*/
- PARSE_STATE_NAME, /*!< looking for end of name
*/
- PARSE_STATE_VALUE_START, /*!< looking for start of value (could be a
'{') */
- PARSE_STATE_VALUE, /*!< looking for end of value
*/
- PARSE_STATE_VALUE_BRACED /*!< looking for end of braced value (a '}')
*/
-
- } PARSE_STATE;
-
- /*!
- \brief Posts an installer error.
-
- Posts an installer error such that it can be returned later, along with
- any other errors posted, using getError().
-
- This uses SQLPostInstallerError().
- */
- static BOOL setError( const QString &stringMessage, DWORD nErrorCode =
ODBC_ERROR_GENERAL_ERR );
-
- /*!
- \brief Gets a list of registered drivers.
-
- The 'friendly' driver names are returned.
-
- This uses SQLGetInstalledDrivers().
- */
- static QStringList getDriverNames();
-
- /*!
- \brief Gets a list of data source names (DSN's).
-
- The results can be restricted in scope using nScope.
-
- This uses SQLDataSources().
- */
- static QStringList getDataSourceNames( MYODBCInsDataSource::DATASOURCE_SCOPE nScope
);
-
- /*!
- \brief Gets the default location for driver and setup libraries.
-
- This uses SQLInstallDriverEx() with ODBC_INSTALL_INQUIRY.
- */
- static QString getDefaultInstallLocation();
-
- /*!
- \brief Parses a keyword/value string - placing results in phashKeywordValues.
-
- Keyword/value strings are used in several places in ODBC and each use
- has its own special rules. Most notably; some use a ';' to delimit
- each key/value pair while others use '\0'.
-
- This method will parse the keyword/value string using the specified
- nDelim and does only the validation that is common to all uses.
-
- This method is mostly for use by other MYODBCIns classes.
-
- \param phashKeywordValues This is where the results will go. It is assumed to
- be empty at start and will have 0 or more entries if the parse succeeds.
- \param stringKeywordValues This is the keyword/value string.
- \param nDelim This is the delimiter used in stringKeywordValues. Using
DELIM_BOTH
- has limitations and should be avoided where ever possible.
- \return bool
- \retval true The parse succeeded
- \retval false The parse failed. The reason can be found using getError().
- */
- static BOOL getKeywordValues( QHash<QString,QString> *phashKeywordValues, const
QString &stringKeywordValues, DELIM nDelim = DELIM_BOTH );
-
- /*!
- \brief Get the error stored at location nError.
-
- This uses SQLInstallerError().
- */
- static RETCODE getError( WORD nError, DWORD *pnErrorCode, QString &stringMessage
);
-
- /*!
- \brief Get the error stored at location nError.
- */
- static QString getError( WORD nError );
-
- /*!
- \brief Get all/any installer errors.
- */
- static QStringList getErrors();
-
- /*!
- \brief Registers a driver.
-
- This registers a driver in the ODBC system information such that it
- can be used but - it does not copy any files. The files should be
- copied to the default location (\sa getDefaultInstallLocation())
- before the driver is registered.
-
- The usage count is incremented during this process.
-
- This uses SQLInstallDriverEx().
- */
- static BOOL doRegisterDriver( const QString &stringName, const QString
&stringAttributes, DWORD *pnUsageCount = NULL );
-
- /*!
- \brief Deregisters a driver.
-
- This deregisters a driver. The way that this works is;
- - decrements usage count
- - if usage count is 0 then remove driver registration info from ODBC sys
info
-
- This does not remove any files - that should be done after the usage
count is 0
- and the driver registration info has been removed from ODBC sys info.
-
- This uses SQLRemoveDriver().
- */
- static BOOL doDeregisterDriver( const QString &stringName, BOOL bRemoveDSNs =
false, DWORD *pnUsageCount = NULL );
-
- /*!
- \brief Inserts a new data source into the ODBC sys info.
- */
- static BOOL doInsertDataSource( const QString &stringName, const QString
&stringAttributes, MYODBCInsDataSource::DATASOURCE_SCOPE nScope );
-
- /*!
- \brief Updates an existing data source in the ODBC sys info.
- */
- static BOOL doUpdateDataSource( const QString &stringName, const QString
&stringAttributes, MYODBCInsDataSource::DATASOURCE_SCOPE nScope );
-
- /*!
- \brief Deletes an existing data source from the ODBC sys info.
- */
- static BOOL doDeleteDataSource( const QString &stringName,
MYODBCInsDataSource::DATASOURCE_SCOPE nScope );
-
- /*!
- \brief Use this to check if there are installer errors.
- */
- static BOOL isError();
-
- /*!
- \brief Use this to check if a data source name exists in the ODBC sys info.
- */
- static BOOL isExistsDataSourceName( const QString &stringName,
MYODBCInsDataSource::DATASOURCE_SCOPE nScope );
-
-protected:
- /*!
- \brief Use this to check if a character is a keyword/value pair delimiter or a
- end-of-string marker.
- */
- static BOOL isDelim( const QString &stringKeywordValues, int nScanChar, DELIM
*pnDelim );
-
- /*!
- \brief Use this to check if a character is a keyword/value pair delimiter.
-
- The delimiter is typically a ';' or a '\0' but in some cases it can be
either. If it
- is either (DELIM_BOTH) then this function will try to switch the *pnDelim
to the
- actual delimiter character detected.
-
- \note Auto detection is not fool proof and as such the use of DELIM_BOTH is not
recommended.
- */
- static BOOL isDelimKeywordValue( const QChar &charChar, DELIM *pnDelim );
-
- /*!
- \brief Use this to check if a character is a end-of-string marker for a
keyword/value string.
-
- The delimiter (end-of-string marker) is always a '\0' but for DELIM_NULL
you would find
- two '\0' chars (one for the keryword/value pair delimiter and another for
a end-of-string).
-
- In the case of a ';' (DELIM_SEMI) delimited keyword/value pair - the last
';' may be
- omitted. This means that the end-of-string marker (in this case a single
'\0') can act as
- both a keyword/value pair delimiter and as the end-of-string marker.
- */
- static BOOL isDelimKeywordValues( const QString &stringKeywordValues, int
nScanChar, DELIM nDelim );
-};
-
-#endif
-
Deleted: trunk/SDK/Installer/include/MYODBCInsDataSource.h
===================================================================
--- trunk/SDK/Installer/include/MYODBCInsDataSource.h 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/Installer/include/MYODBCInsDataSource.h 2007-05-22 18:47:33 UTC (rev 925)
@@ -1,145 +0,0 @@
-/*!
- \file MYODBCInsDataSource.h
- \author Peter Harvey <pharvey@stripped>
- Copyright (C) MySQL AB 2004-2007, Released under GPL.
- \version Connector/ODBC v5
- \date 2007
- \brief Code to provide abstraction and portability for I/O of ODBC system
information information.
-
- \license GPL
-
- 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
-*/
-#ifndef MYODBC_INS_DATASOURCE_H
-#define MYODBC_INS_DATASOURCE_H
-
-#include <MYODBCC.h>
-
-#include <QString>
-#include <QStringList>
-#include <QTextStream>
-#include <QHash>
-#include <QVector>
-
-class MYODBCInsDriverConnect;
-
-/*!
- \brief Data Source Name (DSN).
-
- This is a DSN - it holds the data source name and attributes
- and can be used to; read, write and edit a data source. \sa MYODBCIns
- for methods to create and delete a DSN.
-
- The DSN may exist in the; User, System or both scope.
-
- \code
- // create a new DSN
- MYODBCIns::doInsertDataSource( "MyDSN",
- "SERVER=localhost;DATABASE=db;UID=myid",
- DATASOURCE_SCOPE_USER );
- // later... edit DSN
- MYODBCInsDataSource ds;
-
- ds.setMode( DATASOURCE_MODE_DSN_VIEW );
- ds.doRead( "MyDSN", DATASOURCE_SCOPE_USER );
- da.setDATABASE( "test" );
- da.doWrite( DATASOURCE_SCOPE_USER );
- \endcode
-
- \sa MYODBCIns
- MYODBCInsDriver
- MYODBCInsDriverConnect
-*/
-class MYODBCInsDataSource
-{
- friend class MYODBCInsDriverConnect;
-public:
- /*!
- \brief DSN edit mode.
-
- Reason why we have created a MYODBC_INS_DATASOURCE.
- */
- enum DATASOURCE_MODE
- {
- DATASOURCE_MODE_DSN_ADD, /* For ConfigDSN() - ODBC_ADD_DSN.
*/
- DATASOURCE_MODE_DSN_EDIT, /* For ConfigDSN() - ODBC_CONFIG_DSN.
*/
- DATASOURCE_MODE_DSN_VIEW /* For command-line tools to list DSN details.
*/
- };
-
- enum DATASOURCE_SCOPE
- {
- DATASOURCE_SCOPE_BOTH = ODBC_BOTH_DSN,
- DATASOURCE_SCOPE_USER = ODBC_USER_DSN,
- DATASOURCE_SCOPE_SYSTEM = ODBC_SYSTEM_DSN
- };
-
- MYODBCInsDataSource();
-
- BOOL setAttributes( const QHash<QString,QString> &hashAttributes, BOOL
bReplace = true, BOOL bStrict = true );
- BOOL setName( const QString &stringName );
- BOOL setDRIVER( const QString &stringDRIVER );
- BOOL setDESCRIPTION( const QString &stringDESCRIPTION );
- BOOL setSERVER( const QString &stringSERVER );
- BOOL setUID( const QString &stringUID );
- BOOL setPWD( const QString &stringPWD );
- 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( DATASOURCE_MODE nMode );
- BOOL setScope( DATASOURCE_SCOPE nScope );
-
- QString getName();
- QString getDRIVER();
- QString getDESCRIPTION();
- QString getSERVER();
- QString getUID();
- QString getPWD();
- QString getDATABASE();
- QString getPORT();
- QString getSOCKET();
- QString getSTMT();
- QString getOPTION();
- DATASOURCE_MODE getMode();
- DATASOURCE_SCOPE getScope();
-
- BOOL doRead( const QString &stringDataSourceName, DATASOURCE_SCOPE nScope );
- BOOL doRead( const QString &stringDataSourceName );
- BOOL doRead();
- BOOL doWrite( DATASOURCE_SCOPE nScope );
- BOOL doWrite();
- void doClear();
- static BOOL doDelete( const QString &stringDataSourceName );
-
- BOOL isValidAttributes( const QHash<QString,QString> &hashAttributes, BOOL
bStrict = true );
-
- MYODBCInsDataSource operator=( MYODBCInsDataSource rval );
- friend QTextStream &operator<<( QTextStream &stream, const
MYODBCInsDataSource &rval );
-
-protected:
- QString stringName; /*!< DSN (For example; odbc.ini section
name) */
- QHash<QString,QString> hashAttributes; /*!< DSN attributes (for example;
DRIVER, UID, PWD, DATABASE,... does NOT include DSN */
-
- DATASOURCE_MODE nMode;
- DATASOURCE_SCOPE nScope;
-};
-
-#endif
-
Deleted: trunk/SDK/Installer/include/MYODBCInsDriver.h
===================================================================
--- trunk/SDK/Installer/include/MYODBCInsDriver.h 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/Installer/include/MYODBCInsDriver.h 2007-05-22 18:47:33 UTC (rev 925)
@@ -1,93 +0,0 @@
-/*!
- \file MYODBCInsDriver.h
- \author Peter Harvey <pharvey@stripped>
- Copyright (C) MySQL AB 2004-2007, Released under GPL.
- \version Connector/ODBC v5
- \date 2007
- \brief Code to provide abstraction and portability for I/O of ODBC system
information information.
-
- \license GPL
-
- 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
-*/
-#ifndef MYODBC_INS_DRIVER_H
-#define MYODBC_INS_DRIVER_H
-
-#include <MYODBCC.h>
-
-#include <QString>
-#include <QStringList>
-#include <QTextStream>
-
-/*!
- \brief Driver
-
- This is a driver (in the ODBC system information) - it holds the driver name
and attributes
- and can be used to; read, write and edit this information. \sa MYODBCIns for
methods to
- register/deregister a driver.
-
- \code
- // register a driver in the ODBC system information so we can use it
- MYODBCIns::doRegisterDriver( "MySQL Connector/ODBC v5",
- "DRIVER=myodbc5.dll;SETUP=myodbc5S.dll" );
- // later... get the name of the SETUP library
- MYODBCInsDriver d;
-
- ds.doRead( "MySQL Connector/ODBC v5" );
- stringSetup = da.getSETUP();
- \endcode
-
- \sa MYODBCIns
- MYODBCInsDataSource
- MYODBCInsDriverConnect
-*/
-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 SQLWCHAR *getAttributesNullDelim( const QString &stringFriendlyName, const
QString &stringDRIVER, const QString &stringSETUP );
-
- BOOL doRead( const QString &stringFriendlyName );
- BOOL doWrite();
- void doClear();
- static BOOL doDelete( const QString &stringDriverName, BOOL
bRemoveDataSourceNames, LPDWORD pnUsageCount );
-
- MYODBCInsDriver operator=( MYODBCInsDriver rval );
- friend QTextStream &operator<<( QTextStream &stream, const
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
-
Deleted: trunk/SDK/Installer/include/MYODBCInsDriverConnect.h
===================================================================
--- trunk/SDK/Installer/include/MYODBCInsDriverConnect.h 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/Installer/include/MYODBCInsDriverConnect.h 2007-05-22 18:47:33 UTC (rev 925)
@@ -1,121 +0,0 @@
-/*!
- \file MYODBCInsDriverConnect.h
- \author Peter Harvey <pharvey@stripped>
- Copyright (C) MySQL AB 2004-2007, Released under GPL.
- \version Connector/ODBC v5
- \date 2007
- \brief Code to provide abstraction and portability for I/O of ODBC system
information information.
-
- \license GPL
-
- 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
-*/
-#ifndef MYODBC_INS_DRIVERCONNECT_H
-#define MYODBC_INS_DRIVERCONNECT_H
-
-#include "MYODBCInsDataSource.h"
-
-class MYODBCInsDriverConnect
-{
-public:
- /*!
- \brief Driver connect method.
-
- Used to indicate what is being used to do
- a SQLDriverConnect.
- */
- enum DRIVERCONNECT_METHOD
- {
- DRIVERCONNECT_METHOD_DRIVER,
- DRIVERCONNECT_METHOD_DSN,
- DRIVERCONNECT_METHOD_UNKNOWN
- };
-
- /*!
- \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.
- */
- enum DRIVERCONNECT_PROMPT
- {
- DRIVERCONNECT_PROMPT_PROMPT,
- DRIVERCONNECT_PROMPT_COMPLETE,
- DRIVERCONNECT_PROMPT_REQUIRED,
- DRIVERCONNECT_PROMPT_NOPROMPT
-
- };
-
- MYODBCInsDriverConnect( DRIVERCONNECT_PROMPT nPrompt = DRIVERCONNECT_PROMPT_NOPROMPT
);
-
- BOOL setAttributes( const QString &stringAttributes ); /*!< Parses and
stores a comma delimited set of key=value attributes. */
- BOOL setDSN( const QString &stringDSN );
- BOOL setDRIVER( const QString &stringDRIVER );
- BOOL setDESCRIPTION( const QString &stringDESCRIPTION );
- BOOL setSERVER( const QString &stringSERVER );
- BOOL setUID( const QString &stringUID );
- BOOL setPWD( const QString &stringPWD );
- 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 setSETUP( const QString &stringSETUP );
- BOOL setMethod( DRIVERCONNECT_METHOD nMethod );
- BOOL setPrompt( DRIVERCONNECT_PROMPT nPrompt );
- BOOL setFILEDSN( const QString &stringFILEDSN );
- BOOL setSAVEFILE( const QString &stringSAVEFILE );
-
- QString getAttributes(); /*!< Returns a comma delimited set of
key=value attributes. */
- QString getDSN();
- QString getDRIVER();
- QString getDESCRIPTION();
- QString getSERVER();
- QString getUID();
- QString getPWD();
- QString getDATABASE();
- QString getPORT();
- QString getSOCKET();
- QString getSTMT();
- QString getOPTION();
- QString getSETUP();
- DRIVERCONNECT_METHOD getMethod();
- DRIVERCONNECT_PROMPT getPrompt();
- QString getFILEDSN();
- QString getSAVEFILE();
- static QString getSETUP( const QString &stringDRIVER );
-
- void doClear(); /*!< Sets all attributes to QString::null
- does not change Method nor Prompt. */
- BOOL doRead();
-
-protected:
- QHash<QString,QString> hashAttributes; /*!< Attributes. Use hash to
avoid many "if key". We use "contains()" instead. */
- QVector<QString> vectorAttributesValid; /*!< Attributes we
understand in a connection string. */
- QString stringSETUP; /*!< Path & file name of
drivers setup library. Used to provide plugin prompting. */
- DRIVERCONNECT_METHOD nMethod; /*!< Indicates whether we are to
use DRIVER or DSN based rules for connecting. */
- DRIVERCONNECT_PROMPT nPrompt; /*!< Prompting we need (if any).
This corresponds to DriverCompletion in SQLDriverConnect. */
-};
-
-
-#endif
-
Added: trunk/SDK/Installer/include/installer.h
===================================================================
--- trunk/SDK/Installer/include/installer.h 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/Installer/include/installer.h 2007-05-22 18:47:33 UTC (rev 925)
@@ -0,0 +1,93 @@
+/*!
+ \file installer.h
+ \author Jess Balint <jbalint@stripped>
+ Copyright (C) MySQL AB 2004-2007, Released under GPL.
+ \version Connector/ODBC v5
+ \date 2007
+ \brief Wrapper for some installer API functionality and structs
+ for drivers and data sources.
+
+ \license GPL
+
+ 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
+*/
+/*
+ * Function prototypes and structures for installer-wrapper functionality.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef _WIN32
+# include <windows.h>
+# define wcscasecmp wcsicmp
+#endif
+
+#include <wchar.h>
+
+#include <sql.h>
+#include <sqlext.h>
+#include <odbcinst.h>
+
+UWORD config_get();
+UWORD config_set(UWORD mode);
+
+typedef struct {
+ SQLWCHAR *name;
+ SQLWCHAR *lib;
+ SQLWCHAR *setup_lib;
+} Driver;
+
+/* SQL_MAX_OPTION_STRING_LENGTH = 256, should be ok */
+#define ODBCDRIVER_STRLEN SQL_MAX_OPTION_STRING_LENGTH
+#define ODBCDATASOURCE_STRLEN SQL_MAX_OPTION_STRING_LENGTH
+
+Driver *driver_new();
+void driver_delete(Driver *driver);
+int driver_lookup(Driver *driver);
+int driver_from_kvpair_semicolon(Driver *driver, const SQLWCHAR *attrs);
+int driver_to_kvpair_null(Driver *driver, SQLWCHAR *attrs, size_t attrslen);
+
+typedef struct {
+ SQLWCHAR *name;
+ SQLWCHAR *driver;
+ SQLWCHAR *description;
+ SQLWCHAR *server;
+ SQLWCHAR *uid;
+ SQLWCHAR *pwd;
+ SQLWCHAR *database;
+ int port;
+ SQLWCHAR *socket;
+ SQLWCHAR *initstmt;
+} DataSource;
+
+DataSource *ds_new();
+void ds_delete(DataSource *ds);
+int ds_set_strattr(SQLWCHAR **attr, const SQLWCHAR *val);
+int ds_set_strnattr(SQLWCHAR **attr, const SQLWCHAR *val, size_t charcount);
+int ds_lookup(DataSource *ds);
+int ds_from_kvpair(DataSource *ds, const SQLWCHAR *attrs, SQLWCHAR delim);
+int ds_add(DataSource *ds);
+int ds_exists(SQLWCHAR *name);
+
+#ifdef __cplusplus
+}
+#endif
+
Modified: trunk/SDK/MYSQLPlus/Library/MConnection.cpp
===================================================================
--- trunk/SDK/MYSQLPlus/Library/MConnection.cpp 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/MYSQLPlus/Library/MConnection.cpp 2007-05-22 18:47:33 UTC (rev 925)
@@ -34,7 +34,7 @@
#include "MMysql.h"
-typedef BOOL (*MYODBCInsDriverConnectFunc)(SQLHWND, MYODBCInsDriverConnect *);
+typedef BOOL (*MYODBCInsDriverConnectFunc)(SQLHWND, DataSource *);
/*!
\brief Construct an MConnection.
@@ -282,11 +282,16 @@
DBUG_RETURN(nConnectionDead);
}
-ulong MConnection::getClientFlag(ulong nOptions, const QString &stringSTMT)
+ulong MConnection::getClientFlag(DataSource *ds)
{
DBUG_ENTER("MConnection::getClientFlag");
ulong nClientFlag = CLIENT_ODBC;
+ /* this is needed for stored procedure calls */
+ nClientFlag |= CLIENT_MULTI_RESULTS;
+
+ /* TODO apply client-flag options from the data source */
+#if 0
if (nOptions & (MYODBC_FLAG_FOUND_ROWS | MYODBC_FLAG_SAFE))
nClientFlag |= CLIENT_FOUND_ROWS;
@@ -303,9 +308,6 @@
if (nOptions & MYODBC_FLAG_IGNORE_SPACE)
nClientFlag |= CLIENT_IGNORE_SPACE;
- /* this is needed for stored procedure calls */
- nClientFlag |= CLIENT_MULTI_RESULTS;
-
#ifdef __WIN__
if (nOptions & MYODBC_FLAG_NAMED_PIPE)
mysql_options((MYSQL*)pMySQL, MYSQL_OPT_NAMED_PIPE, NULL);
@@ -318,6 +320,7 @@
mysql_options((MYSQL*)pMySQL, MYSQL_INIT_COMMAND, stringSTMT.toUtf8().data());
mysql_options((MYSQL*)pMySQL, MYSQL_OPT_CONNECT_TIMEOUT, (const char
*)&nLoginTimeout);
+#endif
DBUG_RETURN(nClientFlag);
}
@@ -430,6 +433,8 @@
{
DBUG_ENTER("MConnection::doBrowseConnect");
+ /* TODO */
+#if 0
pDiagnostic->doClear();
/*!
@@ -483,7 +488,6 @@
value is required - the connect will fail.
*/
- /* we will work with a MYODBCInsDataSource (even as we abuse the DRIVER attribute
within) because its so near perfect for this purpose */
MYODBCInsDataSource datasource;
datasource.setMode(MYODBCInsDataSource::DATASOURCE_MODE_DSN_VIEW);
@@ -660,14 +664,22 @@
*/
if (doConnectInternal(&datasource) != SQL_SUCCESS)
DBUG_RETURN(getDiagnostic()->doAppend(MDiagnostic::STATE_08001));
+#endif
DBUG_RETURN(SQL_SUCCESS);
}
SQLRETURN MConnection::doConnect(SQLWCHAR *psServerName, SQLSMALLINT nNameLength1,
SQLWCHAR *psUserName, SQLSMALLINT nNameLength2, SQLWCHAR *psAuthentication, SQLSMALLINT
nNameLength3)
{
+ DataSource *ds;
+ SQLRETURN rc = SQL_SUCCESS;
+ UWORD scope;
+
DBUG_ENTER("MConnection::doConnect");
+ scope = config_set(ODBC_BOTH_DSN);
+ ds = ds_new();
+
pDiagnostic->doClear();
/*!
@@ -681,7 +693,10 @@
directly to driver.
*/
if (getState() != STATE_C2_ALLOC)
- DBUG_RETURN(getDiagnostic()->doAppend(MDiagnostic::STATE_08002));
+ {
+ rc = getDiagnostic()->doAppend(MDiagnostic::STATE_08002);
+ goto end;
+ }
/*!
\internal ODBC RULE (DM)
@@ -692,7 +707,10 @@
if ((nNameLength1 < 0 && nNameLength1 != SQL_NTS) ||
(nNameLength2 < 0 && nNameLength2 != SQL_NTS) ||
(nNameLength3 < 0 && nNameLength3 != SQL_NTS))
- DBUG_RETURN(getDiagnostic()->doAppend(MDiagnostic::STATE_HY090));
+ {
+ rc = getDiagnostic()->doAppend(MDiagnostic::STATE_HY090);
+ goto end;
+ }
/*!
\internal ODBC RULE (DM)
@@ -701,51 +719,53 @@
maximum length for a data source name.
*/
if (nNameLength1 > SQL_MAX_DSN_LENGTH)
- DBUG_RETURN(getDiagnostic()->doAppend(MDiagnostic::STATE_HY090));
+ {
+ rc = getDiagnostic()->doAppend(MDiagnostic::STATE_HY090);
+ goto end;
+ }
- QString stringServerName;
- QString stringUserName;
- QString stringAuthentication;
-
- if (psServerName)
- stringServerName = MYODBCCString::QString_fromWCharArray(psServerName,
- nNameLength1 == SQL_NTS ? wcslen(psServerName) : nNameLength1);
-
- if (psUserName)
- stringUserName = MYODBCCString::QString_fromWCharArray(psUserName,
- nNameLength2 == SQL_NTS ? wcslen(psUserName) : nNameLength2);
-
- if (psAuthentication)
- stringAuthentication = MYODBCCString::QString_fromWCharArray(psAuthentication,
- nNameLength3 == SQL_NTS ? wcslen(psAuthentication) : nNameLength3);
-
/*!
\internal ODBC RULE (DM)
ServerName was longer than SQL_MAX_DSN_LENGTH characters.
*/
- if (psServerName && nNameLength1 == SQL_NTS &&
stringServerName.length() > SQL_MAX_DSN_LENGTH)
- DBUG_RETURN(getDiagnostic()->doAppend(MDiagnostic::STATE_IM010));
+ if (psServerName && nNameLength1 == SQL_NTS && wcslen(psServerName)
> SQL_MAX_DSN_LENGTH)
+ {
+ rc = getDiagnostic()->doAppend(MDiagnostic::STATE_IM010);
+ goto end;
+ }
/*!
\internal MYODBC RULE
psUserName was longer than SQL_MAX_OPTION_STRING_LENGTH characters.
*/
- if (psUserName && nNameLength2 == SQL_NTS && stringUserName.length()
> SQL_MAX_OPTION_STRING_LENGTH)
- DBUG_RETURN(getDiagnostic()->doAppend(MDiagnostic::STATE_HY000, 0, "psUserName
is too long"));
+ if (psUserName && nNameLength2 == SQL_NTS && wcslen(psUserName) >
SQL_MAX_OPTION_STRING_LENGTH)
+ {
+ rc = getDiagnostic()->doAppend(MDiagnostic::STATE_HY000, 0, "psUserName is too
long");
+ goto end;
+ }
if (psUserName && nNameLength2 != SQL_NTS && nNameLength2 >
SQL_MAX_OPTION_STRING_LENGTH)
- DBUG_RETURN(getDiagnostic()->doAppend(MDiagnostic::STATE_HY000, 0, "psUserName
is too long"));
+ {
+ rc = getDiagnostic()->doAppend(MDiagnostic::STATE_HY000, 0, "psUserName is too
long");
+ goto end;
+ }
/*!
\internal MYODBC RULE
psAuthentication was longer than SQL_MAX_OPTION_STRING_LENGTH characters.
*/
- if (psAuthentication && nNameLength3 == SQL_NTS &&
stringAuthentication.length() > SQL_MAX_OPTION_STRING_LENGTH)
- DBUG_RETURN(getDiagnostic()->doAppend(MDiagnostic::STATE_HY000, 0,
"pszAuthentication is too long"));
+ if (psAuthentication && nNameLength3 == SQL_NTS &&
wcslen(psAuthentication) > SQL_MAX_OPTION_STRING_LENGTH)
+ {
+ rc = getDiagnostic()->doAppend(MDiagnostic::STATE_HY000, 0, "pszAuthentication
is too long");
+ goto end;
+ }
if (psAuthentication && nNameLength3 != SQL_NTS && nNameLength3 >
SQL_MAX_OPTION_STRING_LENGTH)
- DBUG_RETURN(getDiagnostic()->doAppend(MDiagnostic::STATE_HY000, 0,
"pszAuthentication is too long"));
+ {
+ rc = getDiagnostic()->doAppend(MDiagnostic::STATE_HY000, 0, "pszAuthentication
is too long");
+ goto end;
+ }
/*!
\internal ODBC RULE (DM)
@@ -753,45 +773,34 @@
ServerName argument that cannot be found, is a null pointer, or is
"DEFAULT", the Driver Manager connects to the default data source.
*/
- QString stringDSN = stringServerName;
- if (stringServerName.isEmpty())
- stringDSN = "DEFAULT";
+ if(psServerName)
+ ds_set_strattr(&ds->name, psServerName);
+ else
+ ds_set_strattr(&ds->name, L"DEFAULT");
/* see if we can load a DSN */
- MYODBCInsDataSource datasource;
+ if (ds_lookup(ds))
+ {
+ rc = getDiagnostic()->doAppend(MDiagnostic::STATE_IM002);
+ goto end;
+ }
- datasource.setMode(MYODBCInsDataSource::DATASOURCE_MODE_DSN_VIEW);
- datasource.setScope(MYODBCInsDataSource::DATASOURCE_SCOPE_BOTH);
- if (!datasource.doRead(stringDSN))
- DBUG_RETURN(getDiagnostic()->doAppend(MDiagnostic::STATE_IM002));
-
- /*!
- \internal ODBC RULE
-
- Precedence for UID is;
- \li as provided to function
- \li as found in system information
-
- */
- if (!stringUserName.isNull())
- datasource.setUID(stringUserName);
-
- /*!
- \internal ODBC RULE
-
- Precedence for PWD is;
- \li as provided to function
- \li as found in system information
-
- */
- if (!stringAuthentication.isEmpty())
- datasource.setPWD(stringAuthentication);
+ if (psUserName)
+ ds_set_strnattr(&ds->uid, psUserName,
+ nNameLength2 == SQL_NTS ? 0 : nNameLength2);
+ if (psAuthentication)
+ ds_set_strnattr(&ds->pwd, psAuthentication,
+ nNameLength3 == SQL_NTS ? 0 : nNameLength3);
- /* do it */
- DBUG_RETURN(doConnectInternal(&datasource));
+ rc = doConnectInternal(ds);
+
+end:
+ config_set(scope);
+ ds_delete(ds);
+ return rc;
}
-SQLRETURN MConnection::doConnect(MYODBCInsDataSource *pDataSource)
+SQLRETURN MConnection::doConnect(DataSource *pDataSource)
{
DBUG_ENTER("MConnection::doConnect");
@@ -899,9 +908,11 @@
{
DBUG_ENTER("MConnection::doDriverConnect");
+ SQLRETURN nReturn = SQL_SUCCESS;
+ /* TODO */
+#if 0
MYODBCInsDriverConnect driverconnect;
QString stringInConnectionString;
- SQLRETURN nReturn = SQL_SUCCESS;
BOOL bPrompt = false;
#if MYODBC_DBG > 1
@@ -1143,6 +1154,7 @@
}
MYODBCDrvDriverConnectExit2:
+#endif
DBUG_RETURN(nReturn);
}
@@ -1392,32 +1404,47 @@
DBUG_VOID_RETURN;
}
-SQLRETURN MConnection::doConnectInternal(MYODBCInsDataSource *pDataSource)
+SQLRETURN MConnection::doConnectInternal(DataSource *pDataSource)
{
+ SQLRETURN rc = SQL_SUCCESS;
+ char *server;
+ char *uid;
+ char *pwd;
+ char *database;
+ char *socket;
+
DBUG_ENTER("MConnection::doConnectInternal");
+ /* convert SQLWCHAR to UTF8 for MySQL API */
+ server = MYODBCCString::wcstoutf8(pDataSource->server , "");
+ uid = MYODBCCString::wcstoutf8(pDataSource->uid , "");
+ pwd = MYODBCCString::wcstoutf8(pDataSource->pwd , "");
+ database = MYODBCCString::wcstoutf8(pDataSource->database, "");
+ socket = MYODBCCString::wcstoutf8(pDataSource->socket , "");
+
/* allocate the MYSQL handle (this will silently do the library init as needed) */
pMySQL = mysql_init(NULL);
/* translate our flags into client while appling pre-connect flags */
- ulong nFlags = getClientFlag(0, pDataSource->getSTMT());
+ ulong nFlags = getClientFlag(pDataSource);
/* ask mysql for a connection */
if (!mysql_real_connect((MYSQL*)pMySQL,
- pDataSource->getSERVER().toUtf8().data(),
- pDataSource->getUID().toUtf8().data(),
- pDataSource->getPWD().toUtf8().data(),
- pDataSource->getDATABASE().toUtf8().data(),
- pDataSource->getPORT().toInt(),
- pDataSource->getSOCKET().toUtf8().data(),
+ server,
+ uid,
+ pwd,
+ database,
+ pDataSource->port,
+ socket,
(uint)nFlags) ||
/* use utf8 for all server communication */
mysql_set_character_set((MYSQL*)pMySQL, "utf8"))
{
- getDiagnostic()->doAppend(MDiagnostic::STATE_08001,
mysql_errno((MYSQL*)pMySQL), mysql_error((MYSQL*)pMySQL));
+ getDiagnostic()->doAppend(MDiagnostic::STATE_08001,
+ mysql_errno((MYSQL*)pMySQL), mysql_error((MYSQL*)pMySQL));
mysql_close((MYSQL*)pMySQL);
pMySQL = NULL;
- DBUG_RETURN(SQL_ERROR);
+ goto end;
}
/*!
@@ -1442,78 +1469,23 @@
this is the value of the DSN keyword in the connection string passed to the
driver. If the connection string
did not contain the DSN keyword (such as when it contains the DRIVER keyword),
this is an empty string.
*/
- getDiagnostic()->setServerName(pDataSource->getName());
+ getDiagnostic()->setServerName(QString::fromWCharArray(pDataSource->name));
/* we avoid using setCurrentCatalog() as it will try to "USE db" and that is
redundant in this context */
- stringCurrentCatalog = pDataSource->getDATABASE();
+ stringCurrentCatalog = QString::fromWCharArray(pDataSource->database);
- setDataSourceName(pDataSource->getName());
- setUserIdentifier(pDataSource->getUID());
+ setDataSourceName(QString::fromWCharArray(pDataSource->name));
+ setUserIdentifier(QString::fromWCharArray(pDataSource->uid));
setState(STATE_C4_CONN);
- DBUG_RETURN(SQL_SUCCESS);
-}
+end:
+ free(server);
+ free(uid);
+ free(pwd);
+ free(database);
+ free(socket);
-SQLRETURN MConnection::doConnectInternal(MYODBCInsDriverConnect *pDriverConnect)
-{
- DBUG_ENTER("MConnection::doConnectInternal");
-
- /* allocate the MYSQL handle (this will silently do the library init as needed) */
- pMySQL = mysql_init(NULL);
-
- /* translate our flags into client while appling pre-connect flags */
- ulong nFlags = getClientFlag(0, pDriverConnect->getSTMT());
-
- /* ask mysql for a connection */
- if (!mysql_real_connect((MYSQL*)pMySQL,
- pDriverConnect->getSERVER().toUtf8().data(),
- pDriverConnect->getUID().toUtf8().data(),
- pDriverConnect->getPWD().toUtf8().data(),
- pDriverConnect->getDATABASE().toUtf8().data(),
- pDriverConnect->getPORT().toInt(),
- pDriverConnect->getSOCKET().toUtf8().data(),
- (uint)nFlags) ||
- /* use utf8 for all server communication */
- mysql_set_character_set((MYSQL*)pMySQL, "utf8"))
- {
- getDiagnostic()->doAppend(MDiagnostic::STATE_08001,
mysql_errno((MYSQL*)pMySQL), mysql_error((MYSQL*)pMySQL));
- mysql_close((MYSQL*)pMySQL);
- pMySQL = NULL;
- DBUG_RETURN(SQL_ERROR);
- }
-
- /*!
- \internal ODBC RULE
-
- A string that indicates the name of the connection that the diagnostic record
relates to. This field is
- driver-defined. For diagnostic data structures associated with the environment
handle and for diagnostics
- that do not relate to any connection, this field is a zero-length string.
- */
- getDiagnostic()->setConnectionName(mysql_get_host_info((MYSQL*)pMySQL));
-
- /*!
- \internal ODBC RULE
-
- A string that indicates the server name that the diagnostic record relates to. It
is the same as the value
- returned for a call to SQLGetInfo with the SQL_DATA_SOURCE_NAME option. For
diagnostic data structures
- associated with the environment handle and for diagnostics that do not relate to
any server, this field is
- a zero-length string.
-
- A character string with the data source name used during connection. If the
application called SQLConnect,
- this is the value of the szDSN argument. If the application called
SQLDriverConnect or SQLBrowseConnect,
- this is the value of the DSN keyword in the connection string passed to the
driver. If the connection string
- did not contain the DSN keyword (such as when it contains the DRIVER keyword),
this is an empty string.
- */
- getDiagnostic()->setServerName(pDriverConnect->getDSN());
-
- /* we avoid using setCurrentCatalog() as it will try to "USE db" and that is
redundant in this context */
- stringCurrentCatalog = pDriverConnect->getDATABASE();
-
- setDataSourceName(pDriverConnect->getDSN());
- setUserIdentifier(pDriverConnect->getUID());
- setState(STATE_C4_CONN);
-
- DBUG_RETURN(SQL_SUCCESS);
+ DBUG_RETURN(rc);
}
SQLRETURN MConnection::doSubmitCommand(const QString &stringCommand)
Modified: trunk/SDK/MYSQLPlus/Library/MResultPlus.cpp
===================================================================
--- trunk/SDK/MYSQLPlus/Library/MResultPlus.cpp 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/MYSQLPlus/Library/MResultPlus.cpp 2007-05-22 18:47:33 UTC (rev 925)
@@ -750,7 +750,7 @@
"FROM INFORMATION_SCHEMA.STATISTICS "
"WHERE TABLE_SCHEMA='" + stringCatalog + "' AND TABLE_NAME='"
+ stringTable + "' " +
(nUnique == SQL_INDEX_UNIQUE ? " AND NON_UNIQUE=0 " : " ");
- stringStatement += "ORDER BY NON_UNIQUE, TYPE, INDEX_QUALIFIER, INDEX_NAME, and
ORDINAL_POSITION ";
+ stringStatement += "ORDER BY NON_UNIQUE, INDEX_TYPE, INDEX_NAME";
if (mysql_query(mysql, stringStatement.toUtf8().data()))
DBUG_RETURN(getDiagnostic()->doAppend(MDiagnostic::STATE_HY000,
Modified: trunk/SDK/MYSQLPlus/Tests/MYSQLPlusTest.cpp
===================================================================
--- trunk/SDK/MYSQLPlus/Tests/MYSQLPlusTest.cpp 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/MYSQLPlus/Tests/MYSQLPlusTest.cpp 2007-05-22 18:47:33 UTC (rev 925)
@@ -137,19 +137,20 @@
{
MEnvironment * pEnvironment = new MEnvironment();
MConnection * pConnection = new MConnection(pEnvironment);
+ DataSource *ds = ds_new();
pEnvironment->doAddConnection(pConnection);
- MYODBCInsDataSource datasource;
- datasource.setSERVER("localhost");
- datasource.setUID("myodbctest");
- datasource.setPWD("myodbctest");
- datasource.setDATABASE("test");
+ ds_set_strattr(&ds->server, L"localhost");
+ ds_set_strattr(&ds->uid, L"myodbctest");
+ ds_set_strattr(&ds->pwd, L"myodbctest");
+ ds_set_strattr(&ds->database, L"test");
- SQLRETURN nReturn = pConnection->doConnect(&datasource);
+ SQLRETURN nReturn = pConnection->doConnect(ds);
delete pEnvironment;
QCOMPARE(nReturn, (SQLRETURN)SQL_SUCCESS);
+ ds_delete(ds);
}
/*!
Modified: trunk/SDK/MYSQLPlus/include/M.h
===================================================================
--- trunk/SDK/MYSQLPlus/include/M.h 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/MYSQLPlus/include/M.h 2007-05-22 18:47:33 UTC (rev 925)
@@ -30,7 +30,7 @@
#define M_H
#include <MYODBCC.h>
-#include <MYODBCIns.h>
+#include "installer.h"
#include <QObject>
#include <QFile>
Modified: trunk/SDK/MYSQLPlus/include/MConnection.h
===================================================================
--- trunk/SDK/MYSQLPlus/include/MConnection.h 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/SDK/MYSQLPlus/include/MConnection.h 2007-05-22 18:47:33 UTC (rev 925)
@@ -99,7 +99,7 @@
SQLRETURN doBrowseConnect(SQLWCHAR *psInConnectionString, SQLSMALLINT nStringLength1,
SQLWCHAR *psOutConnectionString, SQLSMALLINT nBufferLength, SQLSMALLINT
*pnStringLength2Ptr);
SQLRETURN doConnect(SQLWCHAR *psServerName, SQLSMALLINT nNameLength1, SQLWCHAR
*psUserName, SQLSMALLINT nNameLength2, SQLWCHAR *psAuthentication, SQLSMALLINT
nNameLength3);
- SQLRETURN doConnect(MYODBCInsDataSource *pDataSource);
+ SQLRETURN doConnect(DataSource *pDataSource);
SQLRETURN doDisconnect();
SQLRETURN doDriverConnect(SQLHWND hWnd, SQLWCHAR *pszInConnectionString, SQLSMALLINT
nStringLength1, SQLWCHAR *pszOutConnectionString, SQLSMALLINT nBufferLength, SQLSMALLINT
*pnStringLength2Ptr, SQLUSMALLINT nDriverCompletion);
virtual SQLRETURN doEndTran(SQLSMALLINT nCompletionType);
@@ -154,7 +154,7 @@
MDiagnostic * getDiagnostic();
MEnvironment * getEnvironment();
protected:
- ulong getClientFlag(ulong nOptions, const QString &stringSTMT);
+ ulong getClientFlag(DataSource *ds);
int getServerAliveSanityCheckInterval();
QString getDataSourceName();
QString getUserIdentifier();
@@ -214,8 +214,7 @@
MConnectionInfo *pInfo;
/* doers */
- SQLRETURN doConnectInternal(MYODBCInsDataSource *pDataSource);
- SQLRETURN doConnectInternal(MYODBCInsDriverConnect *pDriverConnect);
+ SQLRETURN doConnectInternal(DataSource *pDataSource);
SQLRETURN doSubmitCommand(const QString &stringCommand);
SQLRETURN doSubmitCommandForResult(const QString cmd, QString &result);
BOOL doServerAliveSanityCheck();
Modified: trunk/Tools/Installer/Installer.pro
===================================================================
--- trunk/Tools/Installer/Installer.pro 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/Tools/Installer/Installer.pro 2007-05-22 18:47:33 UTC (rev 925)
@@ -18,6 +18,7 @@
INCLUDEPATH += ../../SDK/C/include
INCLUDEPATH += ../../SDK/Dbg/include
INCLUDEPATH += ../../SDK/Installer/include
+INCLUDEPATH += ../..
LIBS += -L../../SDK/lib
LIBS += -lMYODBCIns
LIBS += -lMYODBCC
@@ -48,9 +49,5 @@
# #########################################################
# FILES
# #########################################################
-HEADERS = \
- MYODBCInstaller.h
-SOURCES = \
- main.cpp \
- MYODBCInstaller.cpp
+SOURCES = MYODBCInstaller.c
Added: trunk/Tools/Installer/MYODBCInstaller.c
===================================================================
--- trunk/Tools/Installer/MYODBCInstaller.c 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/Tools/Installer/MYODBCInstaller.c 2007-05-22 18:47:33 UTC (rev 925)
@@ -0,0 +1,671 @@
+/*!
+ \file MYODBCInstaller.c
+ \author Jess Balint <jbalint@stripped>
+ Copyright (C) MySQL AB 2004-2007, Released under GPL.
+ \version Connector/ODBC v5
+ \date 2007
+ \brief This program will aid installers when installing/uninstalling
+ MyODBC.
+
+ This program can; register/deregister a myodbc driver and create
+ a sample dsn. The key thing here is that it does this with
+ cross-platform code - thanks to the ODBC installer API. This is
+ most useful to those creating installers (apps using myodbc or
+ myodbc itself).
+
+ \license GPL
+
+ 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
+*/
+/*
+ * Installer utility application. Handles installing/removing/listing, etc
+ * driver and data source entries in the system. See usage text for details.
+ */
+
+#ifdef _WIN32
+# include <windows.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <sql.h>
+#include <sqlext.h>
+#include <odbcinst.h>
+
+#include "installer.h"
+#include "VersionInfo.h"
+
+const char *usage =
+"+--- \n"
+"| MYODBCInstaller v" MYODBC_VERSION " \n"
+"+--- \n"
+"| \n"
+"| Description \n"
+"| \n"
+"| This program can be used to; create, edit, and remove a DSN. It \n"
+"| can also be used to; register, and deregister a driver. In other \n"
+"| words - it can be used to manage ODBC system information. \n"
+"| \n"
+"| This operates consistently across platforms. This has been created\n"
+"| specificaly for MySQL Connector/ODBC. \n"
+"| \n"
+"| Syntax \n"
+"| \n"
+"| MYODBCInstaller <Object> <Action> [Options] \n"
+"| \n"
+"| Object \n"
+"| \n"
+"| -d driver \n"
+"| -s datasource \n"
+"| \n"
+"| Action \n"
+"| \n"
+"| -l list \n"
+"| -a add (add/update for data source) \n"
+"| -r remove \n"
+"| \n"
+"| Options \n"
+"| \n"
+"| -n <name> \n"
+"| -t <attribute string> \n"
+/* Note: These scope values line up with the SQLSetConfigMode constants */
+"| -c0 both \n"
+"| -c1 user data source \n"
+"| -c2 system data source (default) \n"
+"| \n"
+"| Examples \n"
+"| \n"
+"| List drivers... \n"
+"| -d -l \n"
+"| \n"
+"| Register a driver (Windows specific)... \n"
+"| -d -a -n \"MySQL Connector/ODBC v5\" \\ \n"
+"| -t \"DRIVER=MYODBCDriver5.dll;SETUP=MYODBCSetup5.dll\" \n"
+"| \n"
+"| Add a new data source name... \n"
+"| -s -a -c2 -n \"test\" \\ \n"
+"| -t \"DRIVER=MySQL Connector/ODBC
v5;SERVER=localhost;DATABASE=test;UID=myid;PWD=mypwd\"\n"
+"| \n"
+"| List data source name attributes for 'test'... \n"
+"| -s -l -c2 -n \"test\" \n"
+"+--- \n";
+
+/* command line args */
+#define OBJ_DRIVER 'd'
+#define OBJ_DATASOURCE 's'
+
+#define ACTION_LIST 'l'
+#define ACTION_ADD 'a'
+#define ACTION_REMOVE 'r'
+
+#define OPT_NAME 'n'
+#define OPT_ATTR 't'
+#define OPT_SCOPE 'c'
+
+static char obj = 0;
+static char action = 0;
+static UWORD scope = ODBC_SYSTEM_DSN; /* default = system */
+
+/* these two are 'paired' and the char data is converted to the wchar buf.
+ * we check the char * to see if the arg was given then use the wchar in the
+ * installer api. */
+static const char *name = NULL;
+static SQLWCHAR wname[256];
+
+static const char *attrstr = NULL;
+static SQLWCHAR wattrs[4096];
+
+void object_usage()
+{
+ fprintf(stderr,
+ "[ERROR] Object must be either driver (d) or data source (s)\n");
+}
+
+void action_usage()
+{
+ fprintf(stderr, "[ERROR] One action must be specified\n");
+}
+
+void main_usage()
+{
+ fprintf(stderr, usage);
+}
+
+/*
+ * Print an error retrieved from SQLInstallerError.
+ */
+void print_installer_error()
+{
+ int msgno;
+ DWORD errcode;
+ SQLWCHAR errmsg[256];
+ for(msgno = 1; msgno < 9; ++msgno)
+ {
+ if(SQLInstallerError(
+ msgno, &errcode, errmsg, 256, NULL) != SQL_SUCCESS)
+ return;
+ fprintf(stderr,
+ "[ERROR] SQLInstaller error %d: %ws\n", errcode, errmsg);
+ }
+}
+
+/*
+ * Print a general ODBC error (non-odbcinst).
+ */
+void print_odbc_error(SQLHANDLE hnd, SQLSMALLINT type)
+{
+ /* TODO */
+ fprintf(stderr, "[ERROR] ODBC ERROR!!!\n");
+}
+
+/*
+ * Handler for "list driver" command (-d -l -n drivername)
+ */
+int list_driver_details(Driver *driver)
+{
+ SQLWCHAR buf[50000];
+ SQLWCHAR *entries = buf;
+ int rc;
+
+ /* lookup the driver */
+ if((rc = driver_lookup(driver)) < 0)
+ {
+ fprintf(stderr, "[ERROR] Driver not found '%ws'\n", driver->name);
+ return 1;
+ }
+ else if(rc > 0)
+ {
+ print_installer_error();
+ return 1;
+ }
+
+ /* print driver details */
+ printf("FriendlyName: %ws\n", driver->name);
+ printf("DRIVER : %ws\n", driver->lib);
+ printf("SETUP : %ws\n", driver->setup_lib);
+
+ return 0;
+}
+
+/*
+ * Handler for "list drivers" command (-d -l)
+ */
+int list_drivers()
+{
+ SQLWCHAR buf[50000];
+ SQLWCHAR *drivers = buf;
+
+ if(!SQLGetInstalledDrivers(buf, 50000, NULL))
+ {
+ print_installer_error();
+ return 1;
+ }
+
+ while(*drivers)
+ {
+ printf("%ws\n", drivers);
+ drivers += wcslen(drivers) + 1;
+ }
+
+ return 0;
+}
+
+/*
+ * Handler for "add driver" command (-d -a -n drivername -t attrs)
+ */
+int add_driver(Driver *driver, const SQLWCHAR *attrs)
+{
+ DWORD usage_count;
+ SQLWCHAR attrs_null[4096]; /* null-delimited pairs */
+ SQLWCHAR prevpath[256];
+
+ /* read driver attributes into object */
+ if(driver_from_kvpair_semicolon(driver, attrs))
+ {
+ fprintf(stderr, "[ERROR] Could not "
+ "parse key-value pair attribute string\n");
+ return 1;
+ }
+
+ /* convert to null-delimited for installer API */
+ if(driver_to_kvpair_null(driver, attrs_null, 4096))
+ {
+ fprintf(stderr, "[ERROR] Could not "
+ "create new key-value pair attribute string\n");
+ return 1;
+ }
+
+ if(SQLInstallDriverEx(attrs_null, NULL, prevpath, 256, NULL,
+ ODBC_INSTALL_COMPLETE, &usage_count) != TRUE)
+ {
+ print_installer_error();
+ return 1;
+ }
+
+ printf("Success: Usage count is %d\n", usage_count);
+
+ return 0;
+}
+
+/*
+ * Handler for "remove driver" command (-d -a -n drivername)
+ */
+int remove_driver(Driver *driver)
+{
+ DWORD usage_count;
+
+ if(SQLRemoveDriver(driver->name, FALSE, &usage_count) != TRUE)
+ {
+ print_installer_error();
+ return 1;
+ }
+
+ printf("Success: Usage count is %d\n", usage_count);
+
+ return 0;
+}
+
+/*
+ * Handle driver actions. We setup a driver object to be used
+ * for all actions.
+ */
+int handle_driver_action()
+{
+ int rc = 0;
+ Driver *driver = driver_new();
+
+ /* check name is given if needed */
+ switch(action)
+ {
+ case ACTION_ADD:
+ case ACTION_REMOVE:
+ if(!name)
+ {
+ fprintf(stderr, "[ERROR] Name missing to add/remove driver\n");
+ rc = 1;
+ goto end;
+ }
+ }
+
+ /* set the driver name */
+ if(name)
+ wcscpy(driver->name, wname);
+
+ /* perform given action */
+ switch(action)
+ {
+ case ACTION_LIST:
+ if(name)
+ rc = list_driver_details(driver);
+ else
+ rc = list_drivers();
+ break;
+ case ACTION_ADD:
+ if(attrstr)
+ rc = add_driver(driver, wattrs);
+ else
+ {
+ fprintf(stderr,
+ "[ERROR] Attribute string missing to add driver\n");
+ rc = 1;
+ }
+ break;
+ case ACTION_REMOVE:
+ rc = remove_driver(driver);
+ break;
+ }
+
+end:
+ driver_delete(driver);
+ return rc;
+}
+
+/*
+ * Handler for "list data source" command (-s -l -n drivername)
+ */
+int list_datasource_details(DataSource *ds)
+{
+ int rc;
+
+ if((rc = ds_lookup(ds)) < 0)
+ {
+ fprintf(stderr, "[ERROR] Data source not found '%ws'\n", ds->name);
+ return 1;
+ }
+ else if(rc > 0)
+ {
+ print_installer_error();
+ return 1;
+ }
+
+ /* print the data source fields */
+ printf("Name: %ws\n", ds->name);
+ if(ds->driver ) printf("Driver: %ws\n", ds->driver);
+ if(ds->description) printf("Description: %ws\n", ds->description);
+ if(ds->server ) printf("Server: %ws\n", ds->server );
+ if(ds->uid ) printf("Uid: %ws\n", ds->uid );
+ if(ds->pwd ) printf("Pwd: %ws\n", ds->pwd );
+ if(ds->database ) printf("Database: %ws\n", ds->database );
+ if(ds->socket ) printf("Socket: %ws\n", ds->socket );
+ if(ds->initstmt ) printf("Initial statement: %ws\n", ds->initstmt );
+ if(ds->port ) printf("Port: %d \n", ds->port );
+
+ return 0;
+}
+
+/*
+ * Handler for "list data sources" command (-s -l)
+ */
+int list_datasources()
+{
+ SQLHANDLE env;
+ SQLRETURN rc;
+ SQLUSMALLINT dir = 0; /* SQLDataSources fetch direction */
+ SQLWCHAR name[256];
+ SQLWCHAR description[256];
+
+ /* determine 'direction' to pass to SQLDataSources */
+ switch(scope)
+ {
+ case ODBC_BOTH_DSN:
+ dir = SQL_FETCH_FIRST;
+ break;
+ case ODBC_USER_DSN:
+ dir = SQL_FETCH_FIRST_USER;
+ break;
+ case ODBC_SYSTEM_DSN:
+ dir = SQL_FETCH_FIRST_SYSTEM;
+ break;
+ }
+
+ /* allocate handle and set ODBC API v3 */
+ if((rc = SQLAllocHandle(
+ SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env)) != SQL_SUCCESS)
+ {
+ fprintf(stderr, "[ERROR] Failed to allocate env handle\n");
+ return 1;
+ }
+
+ if((rc = SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION,
+ (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER)) != SQL_SUCCESS)
+ {
+ print_odbc_error(env, SQL_HANDLE_ENV);
+ SQLFreeHandle(SQL_HANDLE_ENV, env);
+ return 1;
+ }
+
+ /* retrieve and print data source */
+ while((rc = SQLDataSources(env, dir, name, 256, NULL,
+ description, 256, NULL)) == SQL_SUCCESS)
+ {
+ printf("%-20ws - %ws\n", name, description);
+ dir = SQL_FETCH_NEXT;
+ }
+
+ if(rc != SQL_NO_DATA)
+ {
+ print_odbc_error(env, SQL_HANDLE_ENV);
+ SQLFreeHandle(SQL_HANDLE_ENV, env);
+ return 1;
+ }
+
+ SQLFreeHandle(SQL_HANDLE_ENV, env);
+
+ return 0;
+}
+
+/*
+ * Handler for "add data source" command (-s -a -n drivername -t attrs)
+ */
+int add_datasource(DataSource *ds, const SQLWCHAR *attrs)
+{
+ /* read datasource object from attributes */
+ if(ds_from_kvpair(ds, attrs, L','))
+ {
+ fprintf(stderr, "[ERROR] Could not "
+ "parse key-value pair attribute string\n");
+ return 1;
+ }
+
+ /* validate */
+ if(!ds->driver)
+ {
+ fprintf(stderr, "[ERROR] Driver must be "
+ "specified for a data source\n");
+ return 1;
+ }
+
+ /* Add it */
+ if(ds_add(ds))
+ {
+ print_installer_error();
+ fprintf(stderr, "[ERROR] Data source entry failed, "
+ "remove or try again\n");
+ return 1;
+ }
+
+ printf("Success\n");
+
+ return 0;
+}
+
+/*
+ * Handler for "remove data source" command (-s -r -n drivername)
+ */
+int remove_datasource(DataSource *ds)
+{
+ if(SQLRemoveDSNFromIni(ds->name) != TRUE)
+ {
+ print_installer_error();
+ return 1;
+ }
+
+ printf("Success\n");
+
+ return 0;
+}
+
+/*
+ * Handle driver actions. We setup a data source object to be used
+ * for all actions. Config/scope set+restore is wrapped around the
+ * action.
+ */
+int handle_datasource_action()
+{
+ int rc = 0;
+ UWORD config_mode = config_set(scope);
+ DataSource *ds = ds_new();
+
+ /* check name is given if needed */
+ switch(action)
+ {
+ case ACTION_ADD:
+ case ACTION_REMOVE:
+ if(!name)
+ {
+ fprintf(stderr,
+ "[ERROR] Name missing to add/remove data source\n");
+ rc = 1;
+ goto end;
+ }
+ }
+
+ /* set name if given */
+ if(name)
+ ds_set_strattr(&ds->name, wname);
+
+ /* perform given action */
+ switch(action)
+ {
+ case ACTION_LIST:
+ if(name)
+ rc = list_datasource_details(ds);
+ else
+ rc = list_datasources();
+ break;
+ case ACTION_ADD:
+ if(scope == ODBC_BOTH_DSN)
+ {
+ fprintf(stderr, "[ERROR] Adding data source must be either "
+ "user or system scope (not both)\n");
+ rc = 1;
+ }
+ else if(!attrstr)
+ {
+ fprintf(stderr,
+ "[ERROR] Attribute string missing to add data source\n");
+ rc = 1;
+ }
+ else
+ {
+ rc = add_datasource(ds, wattrs);
+ }
+ break;
+ case ACTION_REMOVE:
+ rc = remove_datasource(ds);
+ break;
+ }
+
+end:
+ ds_delete(ds);
+ config_set(config_mode);
+ return rc;
+}
+
+/*
+ * Entry point, parse args and do first set of validation.
+ */
+int main(int argc, char **argv)
+{
+ char *arg;
+ int i;
+
+ /* minimum number of args to do anything useful */
+ if(argc < 3)
+ {
+ fprintf(stderr, "[ERROR] Not enough arguments given\n");
+ main_usage();
+ return 1;
+ }
+
+ /* parse args */
+ for(i = 1; i < argc; ++i)
+ {
+ arg = argv[i];
+ if(*arg == '-')
+ arg++;
+
+ /* we should be left with a single character option (except scope)
+ * all strings are skipped by the respective option below */
+ if(*arg != OPT_SCOPE && *(arg + 1))
+ {
+ fprintf(stderr, "[ERROR] Invalid command line option: %s\n", arg);
+ return 1;
+ }
+
+ switch(*arg)
+ {
+ case OBJ_DRIVER:
+ case OBJ_DATASOURCE:
+ /* make sure we haven't already assigned the object */
+ if(obj)
+ {
+ object_usage();
+ return 1;
+ }
+ obj = *arg;
+ break;
+ case ACTION_LIST:
+ case ACTION_ADD:
+ case ACTION_REMOVE:
+ if(action)
+ {
+ action_usage();
+ return 1;
+ }
+ action = *arg;
+ break;
+ case OPT_NAME:
+ if(i + 1 == argc || *argv[i + 1] == '-')
+ {
+ fprintf(stderr, "[ERROR] Missing name\n");
+ return 1;
+ }
+ name = argv[++i];
+ break;
+ case OPT_ATTR:
+ if(i + 1 == argc || *argv[i + 1] == '-')
+ {
+ fprintf(stderr, "[ERROR] Missing attribute string\n");
+ return 1;
+ }
+ attrstr = argv[++i];
+ break;
+ case OPT_SCOPE:
+ /* convert to integer */
+ scope = *(++arg) - '0';
+ if(scope < 0 || scope > 2 || *(arg + 1) /* another char exists */)
+ {
+ fprintf(stderr, "[ERROR] Invalid scope: %s\n", arg);
+ return 1;
+ }
+ break;
+ case 'h':
+ /* print usage if -h is given anywhere */
+ main_usage();
+ return 1;
+ default:
+ fprintf(stderr, "[ERROR] Invalid command line option: %s\n", arg);
+ return 1;
+ }
+ }
+
+ if(!action)
+ {
+ action_usage();
+ return 1;
+ }
+
+ /* convert to SQLWCHAR for installer API */
+ if(name && mbstowcs(wname, name, strlen(name) + 1) < 0)
+ {
+ fprintf(stderr, "[ERROR] Name is invalid\n");
+ return 1;
+ }
+
+ if(attrstr && mbstowcs(wattrs, attrstr, strlen(attrstr) + 1) < 0)
+ {
+ fprintf(stderr, "[ERROR] Attribute string is invalid\n");
+ return 1;
+ }
+
+ /* handle appropriate action */
+ switch(obj)
+ {
+ case OBJ_DRIVER:
+ return handle_driver_action();
+ case OBJ_DATASOURCE:
+ return handle_datasource_action();
+ default:
+ object_usage();
+ return 1;
+ }
+}
+
Deleted: trunk/Tools/Installer/MYODBCInstaller.cpp
===================================================================
--- trunk/Tools/Installer/MYODBCInstaller.cpp 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/Tools/Installer/MYODBCInstaller.cpp 2007-05-22 18:47:33 UTC (rev 925)
@@ -1,197 +0,0 @@
-/*!
- \file MYODBCInstaller.cpp
- \author Peter Harvey <pharvey@stripped>
- Copyright (C) MySQL AB 2004-2007, Released under GPL.
- \version Connector/ODBC v5
- \date 2007
- \brief This program will aid installers when installing/uninstalling
- MyODBC.
-
- This program can; register/deregister a myodbc driver and create
- a sample dsn. The key thing here is that it does this with
- cross-platform code - thanks to the ODBC installer API. This is
- most useful to those creating installers (apps using myodbc or
- myodbc itself).
-
- \license GPL
-
- 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 "MYODBCInstaller.h"
-
-#include <stdio.h>
-
-MYODBCInstaller::MYODBCInstaller()
-{
- pstreamStdOut = new QTextStream(stdout, QIODevice::WriteOnly);
- pstreamStdErr = new QTextStream(stderr, QIODevice::WriteOnly);
-}
-
-MYODBCInstaller::~MYODBCInstaller()
-{
- delete pstreamStdOut;
- delete pstreamStdErr;
-}
-
-bool MYODBCInstaller::doShowDrivers()
-{
- QStringList stringlistDriverNames = MYODBCIns::getDriverNames();
- QStringList::const_iterator i;
-
- if (MYODBCIns::isError())
- {
- doShowErrors();
- return false;
- }
-
- for (i = stringlistDriverNames.constBegin(); i != stringlistDriverNames.constEnd();
++i)
- (*pstreamStdOut) << (*i) << endl;
-
- return true;
-}
-
-bool MYODBCInstaller::doShowDataSources(MYODBCInsDataSource::DATASOURCE_SCOPE nScope)
-{
- QStringList stringlistDataSourceNames =
MYODBCIns::getDataSourceNames(nScope);
- QStringList::const_iterator i;
-
- if (MYODBCIns::isError())
- {
- doShowErrors();
- return false;
- }
-
- for (i = stringlistDataSourceNames.constBegin(); i !=
stringlistDataSourceNames.constEnd(); ++i)
- (*pstreamStdOut) << (*i) << endl;
-
- return true;
-}
-
-bool MYODBCInstaller::doShowDriver(const QString &stringName)
-{
- MYODBCInsDriver driver;
-
- if (!driver.doRead(stringName))
- {
- doShowErrors();
- return false;
- }
-
- (*pstreamStdOut) << driver;
-
- return true;
-}
-
-bool MYODBCInstaller::doShowDataSource(const QString &stringName,
MYODBCInsDataSource::DATASOURCE_SCOPE nScope)
-{
- MYODBCInsDataSource datasource;
-
- datasource.setMode(MYODBCInsDataSource::DATASOURCE_MODE_DSN_VIEW);
-
- if (!datasource.doRead(stringName, nScope))
- {
- doShowErrors();
- return false;
- }
-
- (*pstreamStdOut) << datasource;
-
- return true;
-}
-
-bool MYODBCInstaller::doRegisterDriver(const QString &stringName, const QString
&stringAttributes)
-{
- DWORD nUsageCount = 0;
-
- if (!MYODBCIns::doRegisterDriver(stringName, stringAttributes, &nUsageCount))
- {
- doShowErrors();
- return false;
- }
-
- (*pstreamStdOut) << "Success: Usage count is " << nUsageCount <<
endl;
-
- return true;
-}
-
-bool MYODBCInstaller::doDeregisterDriver(const QString &stringName)
-{
- DWORD nUsageCount = 0;
-
- if (!MYODBCIns::doDeregisterDriver(stringName, false, &nUsageCount))
- {
- doShowErrors();
- return false;
- }
-
- (*pstreamStdOut) << "Success: Usage count is " << nUsageCount <<
endl;
-
- return true;
-}
-
-bool MYODBCInstaller::doInsertDataSource(const QString &stringName, const QString
&stringAttributes, MYODBCInsDataSource::DATASOURCE_SCOPE nScope)
-{
- if (!MYODBCIns::doInsertDataSource(stringName, stringAttributes, nScope))
- {
- doShowErrors();
- return false;
- }
-
- (*pstreamStdOut) << "Success" << endl;
-
- return true;
-}
-
-bool MYODBCInstaller::doUpdateDataSource(const QString &stringName, const QString
&stringAttributes, MYODBCInsDataSource::DATASOURCE_SCOPE nScope)
-{
- if (!MYODBCIns::doUpdateDataSource(stringName, stringAttributes, nScope))
- {
- doShowErrors();
- return false;
- }
-
- (*pstreamStdOut) << "Success" << endl;
-
- return true;
-}
-
-bool MYODBCInstaller::doDeleteDataSource(const QString &stringName,
MYODBCInsDataSource::DATASOURCE_SCOPE nScope)
-{
- if (!MYODBCIns::doDeleteDataSource(stringName, nScope))
- {
- doShowErrors();
- return false;
- }
-
- (*pstreamStdOut) << "Success" << endl;
-
- return true;
-}
-
-bool MYODBCInstaller::doShowErrors()
-{
- QStringList stringlistErrors = MYODBCIns::getErrors();
- QStringList::const_iterator i;
-
- for (i = stringlistErrors.constBegin(); i != stringlistErrors.constEnd(); ++i)
- (*pstreamStdOut) << (*i) << endl;
-
- return true;
-}
Deleted: trunk/Tools/Installer/MYODBCInstaller.h
===================================================================
--- trunk/Tools/Installer/MYODBCInstaller.h 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/Tools/Installer/MYODBCInstaller.h 2007-05-22 18:47:33 UTC (rev 925)
@@ -1,79 +0,0 @@
-/*!
- \file MYODBCInstaller.cpp
- \author Peter Harvey <pharvey@stripped>
- Copyright (C) MySQL AB 2004-2007, Released under GPL.
- \version Connector/ODBC v5
- \date 2007
- \brief This program will aid installers when installing/uninstalling
- MyODBC.
-
- This program can; register/deregister a myodbc driver and create
- a sample dsn. The key thing here is that it does this with
- cross-platform code - thanks to the ODBC installer API. This is
- most useful to those creating installers (apps using myodbc or
- myodbc itself).
-
- \license GPL
-
- 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
-*/
-#ifndef MYODBC_INSTALLER_H
-#define MYODBC_INSTALLER_H
-
-#include <QObject>
-#include <QCoreApplication>
-#include <QString>
-#include <QTextStream>
-
-#include <MYODBCC.h>
-#include <MYODBCIns.h>
-
-/*!
- \brief MYODBCInstaller supporting class.
-
- This supports the MYODBCInstaller command-line utility by simplifying
- access to the MYODBCIns library while providing meaningful output for
- a command-line utility such as error messages.
-
- \sa MYODBCInstaller
-*/
-class MYODBCInstaller : public QObject
-{
-public:
- MYODBCInstaller();
- ~MYODBCInstaller();
-
- bool doShowDrivers();
- bool doShowDataSources(MYODBCInsDataSource::DATASOURCE_SCOPE nScope =
MYODBCInsDataSource::DATASOURCE_SCOPE_BOTH);
- bool doShowDriver(const QString &stringName);
- bool doShowDataSource(const QString &stringName,
MYODBCInsDataSource::DATASOURCE_SCOPE nScope =
MYODBCInsDataSource::DATASOURCE_SCOPE_BOTH);
- bool doRegisterDriver(const QString &stringName, const QString
&stringAttributes);
- bool doDeregisterDriver(const QString &stringName);
- bool doInsertDataSource(const QString &stringName, const QString
&stringAttributes, MYODBCInsDataSource::DATASOURCE_SCOPE nScope =
MYODBCInsDataSource::DATASOURCE_SCOPE_BOTH);
- bool doUpdateDataSource(const QString &stringName, const QString
&stringAttributes, MYODBCInsDataSource::DATASOURCE_SCOPE nScope =
MYODBCInsDataSource::DATASOURCE_SCOPE_BOTH);
- bool doDeleteDataSource(const QString &stringName,
MYODBCInsDataSource::DATASOURCE_SCOPE nScope =
MYODBCInsDataSource::DATASOURCE_SCOPE_BOTH);
-
-protected:
- bool doShowErrors();
-
- QTextStream *pstreamStdOut;
- QTextStream *pstreamStdErr;
-};
-
-#endif
Deleted: trunk/Tools/Installer/main.cpp
===================================================================
--- trunk/Tools/Installer/main.cpp 2007-05-22 18:30:28 UTC (rev 924)
+++ trunk/Tools/Installer/main.cpp 2007-05-22 18:47:33 UTC (rev 925)
@@ -1,271 +0,0 @@
-/*!
- \file main.cpp
- \author Peter Harvey <pharvey@stripped>
- Copyright (C) MySQL AB 2004-2007, Released under GPL.
- \version Connector/ODBC v5
- \date 2007
- \brief This program will aid installers when installing/uninstalling
- MyODBC.
-
- This program can; register/deregister a myodbc driver and create
- a sample dsn. The key thing here is that it does this with
- cross-platform code - thanks to the ODBC installer API. This is
- most useful to those creating installers (apps using myodbc or
- myodbc itself).
-
- \license GPL
-
- 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 "MYODBCInstaller.h"
-
-#include <iostream>
-
-MYODBCInstaller *pinstaller = NULL;
-
-QChar cObject;
-QChar cAction;
-QChar cOption;
-QChar cScope;
-QString stringName;
-QString stringAttributes;
-
-int doShowSyntax()
-{
- std::cout << "+---" << std::endl;
- std::cout << "| MYODBCInstaller v" << MYODBC_VERSION << std::endl;
- std::cout << "+---" << std::endl;
- std::cout << "|" << std::endl;
- std::cout << "| Description" << std::endl;
- std::cout << "|" << std::endl;
- std::cout << "| This program can be used to; create, edit, and delete a DSN.
It" << std::endl;
- std::cout << "| can also be used to; register, and deregister a driver. In
other" << std::endl;
- std::cout << "| words - it can be used to manage ODBC system information."
<< std::endl;
- std::cout << "|" << std::endl;
- std::cout << "| This operates consistently across platforms. This has been
created" << std::endl;
- std::cout << "| specificaly for MySQL Connector/ODBC." << std::endl;
- std::cout << "|" << std::endl;
- std::cout << "| Syntax" << std::endl;
- std::cout << "|" << std::endl;
- std::cout << "| MYODBCInstaller <Object> <Action> [Options]"
<< std::endl;
- std::cout << "|" << std::endl;
- std::cout << "| Object" << std::endl;
- std::cout << "|" << std::endl;
- std::cout << "| -d driver" << std::endl;
- std::cout << "| -s datasource" << std::endl;
- std::cout << "|" << std::endl;
- std::cout << "| Action" << std::endl;
- std::cout << "|" << std::endl;
- std::cout << "| -l list" << std::endl;
- std::cout << "| -a add" << std::endl;
- std::cout << "| -r delete" << std::endl;
- std::cout << "| -u update" << std::endl;
- std::cout << "|" << std::endl;
- std::cout << "| Options" << std::endl;
- std::cout << "|" << std::endl;
- std::cout << "| -n <name>" << std::endl;
- std::cout << "| -t <attribute string>" << std::endl;
- std::cout << "| -c1 system data source" << std::endl;
- std::cout << "| -c2 user data source" << std::endl;
- std::cout << "| -c3 both" << std::endl;
- std::cout << "|" << std::endl;
- std::cout << "| Examples" << std::endl;
- std::cout << "|" << std::endl;
- std::cout << "| List drivers..." << std::endl;
- std::cout << "| -d -l" << std::endl;
- std::cout << "|" << std::endl;
- std::cout << "| Register a driver (Windows specific)..." << std::endl;
- std::cout << "| -d -a -n \"MySQL Connector/ODBC v5\" -t
\"DRIVER=MYODBCDriver5.dll;SETUP=MYODBCSetup5.dll\"" << std::endl;
- std::cout << "|" << std::endl;
- std::cout << "| Add a new data source name..." << std::endl;
- std::cout << "| -s -a -c2 -n \"test\" -t \"DRIVER=MySQL Connector/ODBC
v5;SERVER=localhost;DATABASE=test;UID=myid;PWD=mypwd\"" << std::endl;
- std::cout << "|" << std::endl;
- std::cout << "| List data source name attributes for 'test'..." <<
std::endl;
- std::cout << "| -s -l -c2 -n \"test\"" << std::endl;
- std::cout << "+---" << std::endl;
-
- return 1;
-}
-
-bool doDriver()
-{
- switch (cAction.toAscii())
- {
- case 'l':
- if (stringName.isNull())
- return pinstaller->doShowDrivers();
- else
- return pinstaller->doShowDriver(stringName);
- break;
- case 'a':
- return pinstaller->doRegisterDriver(stringName, stringAttributes);
- case 'r':
- return pinstaller->doDeregisterDriver(stringName);
- case 'u':
- default:
- std::cout << "[ERROR] Missing a viable action." << std::endl;
- return false;
- }
-
- return true;
-}
-
-bool doDataSource()
-{
- // validate scope and translate to internal type
- MYODBCInsDataSource::DATASOURCE_SCOPE nScope;
-
- switch (cScope.toAscii())
- {
- case '1':
- nScope = MYODBCInsDataSource::DATASOURCE_SCOPE_SYSTEM;
- break;
- case '2':
- nScope = MYODBCInsDataSource::DATASOURCE_SCOPE_USER;
- break;
- case '3':
- nScope = MYODBCInsDataSource::DATASOURCE_SCOPE_BOTH;
- break;
- default:
- std::cout << "[ERROR] Invalid scope " << cScope.toAscii()
<< std::endl;
- return false;
- }
-
- // process action
- switch (cAction.toAscii())
- {
- case 'l':
- if (stringName.isNull())
- return pinstaller->doShowDataSources(nScope);
- else
- return pinstaller->doShowDataSource(stringName, nScope);
- break;
- case 'a':
- return pinstaller->doInsertDataSource(stringName, stringAttributes,
nScope);
- case 'r':
- return pinstaller->doDeleteDataSource(stringName, nScope);
- case 'u':
- return pinstaller->doUpdateDataSource(stringName, stringAttributes,
nScope);
- default:
- std::cout << "[ERROR] Missing a viable action." << std::endl;
- return false;
- }
-
- return true;
-}
-
-bool doObject()
-{
- // process object
- switch (cObject.toAscii())
- {
- case 'd':
- return doDriver();
- case 's':
- return doDataSource();
- default:
- std::cout << "[ERROR] Object not supplied." << std::endl;
- return false;
- }
-
- return true;
-}
-
-/*!
- \brief This is the entry point to this program.
-
- \note More features/args will probably be added in the future.
-*/
-int main(int argc, char *argv[])
-{
- QCoreApplication app(argc, argv);
-
- MYODBCInstaller installer;
- QStringList stringlistArguments = app.arguments();
-
- pinstaller = &installer;
-
- if (stringlistArguments.count() < 2)
- return doShowSyntax();
-
- // extract args from command-line
- QStringList::const_iterator i;
-
- for (i = stringlistArguments.constBegin(), ++i; i != stringlistArguments.constEnd();
++i)
- {
- if (i->at(0) == '-')
- {
- switch (i->at(1).toAscii())
- {
- case 'd':
- case 's':
- cObject = i->at(1);
- break;
- case 'l':
- case 'a':
- case 'r':
- case 'u':
- cAction = i->at(1);
- break;
- case 'n':
- cOption = i->at(1);
- if (i->length() > 2)
- stringName = i->mid(2);
- break;
- case 't':
- cOption = i->at(1);
- if (i->length() > 2)
- stringAttributes = i->mid(2);
- break;
- case 'c':
- cScope = i->at(2);
- break;
- default:
- std::cout << "[ERROR] Invalid object/action/option " <<
i->at(1).toAscii() << std::endl;
- return 1;
- }
- }
- else
- {
- /*! \todo address case where this text may get picked up from later in
command-line - not right after arg */
- switch (cOption.toAscii())
- {
- case 'n':
- stringName = *i;
- break;
- case 't':
- stringAttributes = *i;
- break;
- default:
- std::cout << "[ERROR] Invalid option " <<
cOption.toAscii() << std::endl;
- return 1;
- }
- }
- }
-
- if (!doObject())
- return 1;
-
-
-// We do not need the event loop so we skip exec() - we are good like that :)
-// return app.exec();
-
- return 0;
-}
| Thread |
|---|
| • Connector/ODBC 5 commit: r925 - in trunk: Driver/Driver/Library Driver/Setup/Library SDK/C/Library SDK/C/include SDK/Installer/Library SDK/Installer/T... | jbalint | 22 May |