logo       

Sponsor
FREE Network Mapping Tool for Microsoft® Office Visio® Professional 2007
Don't map your network by hand - let LANsurveyor Exx press for Microsoft Visio Professional 2007 automatically create network diagrams for you!

bk commit - MyODBC 3.51 (1.353): msg#00022

db.mysql.odbc

Subject: bk commit - MyODBC 3.51 (1.353)

Below is the list of changes that have just been commited into a local
MyODBC 3.51 repository of 'pharvey'. When 'pharvey' does a push, they will
be propogaged to the main repository and within 2 hours after the push
into the public repository.

For more information on how to access the public repository see:
http://www.mysql.com/products/myodbc/faq_2.html#Development_source

You can also browse the changes from public repository:
Complete repository: http://mysql.bkbits.net:8080/myodbc3/
This changeset : http://mysql.bkbits.net:8080/myodbc3/cset@xxxxx

ChangeSet
1.353 04/08/07 15:51:45 peterh@xxxxxxxxx +1 -0
tweeks to tools (on Linux)

myodbcinst/myodbcinst.c
1.15 04/08/07 15:51:45 peterh@xxxxxxxxx +191 -146
tweeks to tools (on Linux)

# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: peterh
# Host: thinkpad.peterharvey.org
# Root: /home/pharvey/SandBox/MySQL/myodbc-3.51

--- 1.14/myodbcinst/myodbcinst.c Fri Aug 6 22:00:53 2004
+++ 1.15/myodbcinst/myodbcinst.c Sat Aug 7 15:51:45 2004
@@ -44,31 +44,64 @@
"\n" \
"Purpose:\n" \
"\n" \
-" Use this program to manage ODBC drivers and data sources from the\n" \
+" Use this program to manage the MyODBC driver and data sources from the\n" \
" command-line. This is particularly useful for installation processes.\n" \
"\n" \
"Usage:\n" \
"\n" \
-" $ myodbcinst <action>\n" \
+" $ myodbcinst <action> <option>\n" \
"\n" \
"Actions:\n" \
"\n" \
-" -i install\n" \
-" -u uninstall\n" \
-" -e edit\n" \
+" -q query\n" \
+" -i register Driver or increase usage count\n" \
+" -u deregister Driver or decrease usage count\n" \
+" -s create sample Data Source Name\n" \
+" -e edit Data Source Name\n" \
+" -r remove Data Source Name\n" \
"\n" \
"Options:\n" \
"\n" \
-" -g use GUI if needed\n" \
+" -d query is for drivers (default is data source names)\n" \
+" -g use GUI as needed (provided by ConfigDSN)\n" \
+" -n driver name or data source name (optional)\n" \
+"\n" \
+"Example Session:\n" \
+"\n" \
+" 1. <copy driver and setup libs to /usr/lib or system32>\n" \
+" 2. # myodbcinst -i\n" \
+" 3. $ myodbcinst -s -ntest\n" \
+" 4. $ myodbcinst -e -g -ntest\n" \
+"\n" \
"Enjoy\n" \
"Peter Harvey\n";

-char *szDriverName = "MySQL ODBC 3.51 Driver";
-char *szSampleDataSource =
"DSN=myodbc\0SERVER=localhost\0USER=\0PASSWORD=\0DATABASE=test\0PORT=\0OPTION=3\0SOCKET=\0STMT=\0\0";
-char cAction = '_';
-int bGUI = 0;
-
+char * pszDriverName = "MySQL ODBC 3.51 Driver";
#ifdef _WIN_
+char * pszDriverAttributes =
"DRIVER=myodbc3.dll\0SETUP=myodbc3S.dll\0\0";
+int nDriverAttributesLength = 39;
+#endif
+#ifdef _OSX_
+char * pszDriverAttributes =
"DRIVER=/usr/lib/libmyodbc3.dylib\0SETUP=/usr/lib/libmyodbc3S.dylib\0\0";
+int nDriverAttributesLength = 67;
+#endif
+#ifdef _UNIX_
+char * pszDriverAttributes =
"DRIVER=/usr/lib/libmyodbc3.so\0SETUP=/usr/lib/libmyodbc3S.so\0\0";
+int nDriverAttributesLength = 61;
+#endif
+
+char * pszDataSourceName = "myodbc";
+char * pszDataSourceNameAttributes =
"SERVER=localhost\0USER=\0PASSWORD=\0DATABASE=test\0PORT=\0OPTION=3\0SOCKET=\0STMT=\0\0";
+int nDataSourceNameAttributesLength = 77;
+
+char cAction = '_';
+int bGUI = 0;
+int bQueryDrivers = 1;
+
+#if defined(_WIN_)
+/*!
+ \brief Get the last error and display string ver of it.
+*/
void printLastErrorString()
{
LPVOID pszMsg;
@@ -109,93 +142,90 @@
fprintf( stderr, "[%s][%d][ERROR] ODBC Installer error (unknown)\n",
__FILE__, __LINE__ );
}

-#ifdef _WIN_
-int doRegisterDriver()
+/*!
+ \brief Show a list of sections.
+*/
+int doQuery( char *pszSource )
{
- char szLoc[1024];
- WORD nLocLen;
- DWORD nUsageCount = -1;
-
- /*!
- \note On MS Windows (XP for example) the driver is registered in two
places;
- 1) \windows\system32\odbcinst.ini
- 2) registry
- Fortunately the installer calls will ensure they are both
updated.
- */
+ char szResults[4048];
+ char * ptr;

- /*!
- \note All ODBC drivers *should* be installed in the standard location
(\windows\system32) and this call
- reflects this as no path is given for the driver file.
- */
- if ( !SQLInstallDriverEx( "MySQL ODBC 3.51
Driver\0Driver=myodbc3.dll\0Setup=myodbc3S.dll\0\0", 0, szLoc, 1023, &nLocLen,
ODBC_INSTALL_COMPLETE, &nUsageCount ) )
+#ifdef _OSX_
+ if ( GetPrivateProfileString( NULL, NULL, NULL, szResults, sizeof(
szResults ) - 1, pszSource ) < 1 )
+#else
+ if ( SQLGetPrivateProfileString( NULL, NULL, NULL, szResults, sizeof(
szResults ) - 1, pszSource ) < 1 )
+#endif
{
printInstallerError();
- fprintf( stderr, "[%s][%d][ERROR] Failed to register driver\n",
__FILE__, __LINE__ );
+ fprintf( stderr, "[%s][%d][INFO] Call returned no data. Could be an
error or just no data to return.\n", __FILE__, __LINE__ );
return 0;
}
+ ptr = szResults;
+ while ( *ptr )
+ {
+ printf( "[%s]\n", ptr );
+ ptr += strlen( ptr ) + 1;
+ }

- printf( "[%s][%d][INFO] Driver registered. Usage count is %d. Location
\"%s\" \n", __FILE__, __LINE__, nUsageCount, szLoc );
return 1;
}
-#endif

-#ifdef _OSX_
-int doRegisterDriver()
-{
- char szLoc[1024];
- WORD nLocLen;
- DWORD nUsageCount = -1;
+/*!
+ \brief Register the driver (or just increase usage count).

- /*!
- \note On OSX there are many odbcinst.ini files - each account has one
in ~/Library/ODBC and there
- is a system wide one in /Library/ODBC. This function will
register the driver in ~/Library/ODBC.
- There are at least two notable complicating factors;
+ \note XP
+
+ On MS Windows (XP for example) the driver is registered in two
places;
+ 1) \windows\system32\odbcinst.ini
+ 2) registry
+ Fortunately the installer calls will ensure they are both
updated.
+
+ All ODBC drivers *should* be installed in the standard location
(\windows\system32) and this call
+ reflects this as no path is given for the driver file.
+
+ \note OSX
+
+ On OSX there are many odbcinst.ini files - each account has one in
~/Library/ODBC and there
+ is a system wide one in /Library/ODBC. This function will register
the driver in ~/Library/ODBC.
+
+ There are at least two notable complicating factors;
- the files are read-ony for average user so one should use sudo
when doing this
- the files do not exist until someone manually creates entries
using the ODBC Administrator AND
they are not created by iodbc installer lib when we execute
this code (we get error)
- */

- /*!
- \note ODBC spec says that "Driver" should NOT include path
- but path seems needed for iodbc. The implication is that
- the driver *must* be installed in /usr/lib for this to work.
- */
- if ( !SQLInstallDriverEx( "MySQL ODBC 3.51
Driver\0Driver=/usr/local/lib/libmyodbc3_r.dylib\0Setup=/usr/local/lib/libmyodbc3S.dylib\0\0",
0, szLoc, 1023, &nLocLen, ODBC_INSTALL_COMPLETE, &nUsageCount ) )
- {
- printInstallerError();
- fprintf( stderr, "[%s][%d][ERROR] Failed to register driver. The most
likely reason for this is that you do not have write privs. to
~/Library/ODBC/odbcinst.ini or that the files do not exist.\n", __FILE__,
__LINE__ );
- return 0;
- }
+ ODBC spec says that "Driver" should NOT include path
+ but path seems needed for iodbc. The implication is that
+ the driver *must* be installed in /usr/lib for this to work.

- /*!
- \note Usage Count is not returned on OSX and returned location does
not seem to reflect reality.
- */
- printf( "[%s][%d][INFO] Driver registered. Usage count is %d. Location
\"%s\" \n", __FILE__, __LINE__, nUsageCount, szLoc );
- return 1;
-}
-#endif
+ Usage Count is not returned on OSX and returned location does not
seem to reflect reality.
+
+ \note Linux/UNIX
+
+ ODBC spec says that "Driver" should NOT include path
+ but path seems needed for unixODBC. The implication is that
+ the driver *must* be installed in /usr/lib for this to work.

-#ifdef _UNIX_
+ Location returned does not seem to reflect reality.
+*/
int doRegisterDriver()
{
+ char szAttributes[nDriverAttributesLength + strlen(pszDriverName) + 1];
char szLoc[1024];
WORD nLocLen;
DWORD nUsageCount = -1;

- if ( !SQLInstallDriverEx( "MySQL ODBC 3.51
Driver\0Driver=/usr/local/lib/libmyodbc3_r.so\0Setup=/usr/local/lib/libmyodbc3S.so\0\0",
0, szLoc, 1023, &nLocLen, ODBC_INSTALL_COMPLETE, &nUsageCount ) )
+ strcpy( szAttributes, pszDriverName );
+ memcpy( &(szAttributes[strlen(szAttributes) + 1]), pszDriverAttributes,
nDriverAttributesLength );
+ if ( !SQLInstallDriverEx( szAttributes, 0, szLoc, 1023, &nLocLen,
ODBC_INSTALL_COMPLETE, &nUsageCount ) )
{
printInstallerError();
- fprintf( stderr, "[%s][%d][ERROR] Failed to register driver. The most
likely reason for this is that you do not have write privs. to
odbcinst.ini.\n", __FILE__, __LINE__ );
+ fprintf( stderr, "[%s][%d][ERROR] Failed to register driver\n",
__FILE__, __LINE__ );
return 0;
}

- /*!
- \note Usage Count is not returned on OSX and returned location does
not seem to reflect reality.
- */
printf( "[%s][%d][INFO] Driver registered. Usage count is %d. Location
\"%s\" \n", __FILE__, __LINE__, nUsageCount, szLoc );
return 1;
}
-#endif

/*!
\brief Deregister the driver.
@@ -206,9 +236,9 @@
int doDeregisterDriver()
{
DWORD nUsageCount;
- BOOL bRemoveDSNs = TRUE;
+ BOOL bRemoveDSNs = FALSE;

- if ( !SQLRemoveDriver( szDriverName, bRemoveDSNs, &nUsageCount ) )
+ if ( !SQLRemoveDriver( pszDriverName, bRemoveDSNs, &nUsageCount ) )
{
printInstallerError();
fprintf( stderr, "[%s][%d][ERROR] Failed to deregister driver.\n",
__FILE__, __LINE__ );
@@ -219,62 +249,17 @@
return 1;
}

+#if defined(_DIRECT_)
/*!
- \brief Create a test/example data source name (DSN).
-
- This must be called *after* the driver is copied
- to target system and registered with ODBC because
- it results in a call to ConfigDSN() in the driver.
-
- MyODBC currently only supports a GUI interface for
- setup on XP but since we lack a window handle we
- are not going to get the driver to do any GUI stuff
- anyway (see doManageDataSources()).
+ \brief Call drivers ConfigDSN when we are linked directly to driver.
*/
-int doCreateDataSource()
+int doConfigDataSource( WORD nRequest )
{
- if ( !SQLConfigDataSource( 0, ODBC_ADD_DSN, szDriverName,
szSampleDataSource ) )
- {
- printInstallerError();
- fprintf( stderr, "[%s][%d][ERROR] Failed to create sample DSN.\n",
__FILE__, __LINE__ );
- return 0;
- }
-
- printf( "[%s][%d][INFO] Sample DSN created as \"myodbc\".\n", __FILE__,
__LINE__ );
- return 1;
-}
-
-#ifdef _WIN_
-int doManageDataSources()
-{
- /* execute ODBC Administrator program */
- fprintf( stderr, "[%s][%d][ERROR] Feature not implemented yet\n",
__FILE__, __LINE__ );
- return 1;
-}
-#endif
-
-#ifdef _OSX_
-int doManageDataSources()
-{
- /* execute ODBC Administrator program */
- fprintf( stderr, "[%s][%d][ERROR] Feature not implemented yet\n",
__FILE__, __LINE__ );
- return 1;
-}
-#endif
-
-#ifdef _UNIX_
-int doManageDataSources()
-{
- /* execute ODBC Administrator program */
- fprintf( stderr, "[%s][%d][ERROR] Feature not implemented yet\n",
__FILE__, __LINE__ );
- return 1;
-}
-#endif
+ char szAttributes[nDataSourceNameAttributesLength +
strlen(pszDataSourceName) + 5];

-#ifdef _DIRECT_
-int doEditDataSource()
-{
- if ( !ConfigDSN( (HWND)1 /* fake window handle */, ODBC_CONFIG_DSN,
szDriverName, szSampleDataSource ) )
+ sprintf( szAttributes, "DSN=%s", pszDataSourceName );
+ memcpy( &(szAttributes[strlen(szAttributes) + 1]),
pszDataSourceNameAttributes, nDataSourceNameAttributesLength );
+ if ( !ConfigDSN( (HWND)bGUI /* fake window handle */, nRequest,
pszDriverName, szAttributes ) )
{
printInstallerError();
return 0;
@@ -282,18 +267,21 @@

return 1;
}
-#else
-#ifdef _WIN_
-int doEditDataSource()
+#elif defined(_WIN_)
+/*!
+ \brief Call drivers ConfigDSN without going through the DM.
+*/
+int doConfigDataSource( WORD nRequest )
{
- BOOL (*pFunc)( HWND, WORD, LPCSTR, LPCSTR );
- HINSTANCE hLib = 0;
- char szDriverSetup[FILENAME_MAX + 1];
+ char szAttributes[nDataSourceNameAttributesLength +
strlen(pszDataSourceName) + 5];
+ BOOL (*pFunc)( HWND, WORD, LPCSTR, LPCSTR );
+ HINSTANCE hLib = 0;
+ char szDriverSetup[FILENAME_MAX + 1];

/* get the setup library from odbcinst */
- if ( !SQLGetPrivateProfileString( szDriverName, "Setup", "",
szDriverSetup, FILENAME_MAX, "ODBCINST.INI" ) )
+ if ( !SQLGetPrivateProfileString( pszDriverName, "SETUP", "",
szDriverSetup, FILENAME_MAX, "ODBCINST.INI" ) )
{
- fprintf( stderr, "[%s][%d][ERROR] Could not determine the
path/filename of driver setup library for driver (%s).\n", __FILE__, __LINE__,
szDriverName );
+ fprintf( stderr, "[%s][%d][ERROR] Could not determine the
path/filename of driver setup library for driver (%s).\n", __FILE__, __LINE__,
pszDriverName );
return 0;
}

@@ -317,7 +305,9 @@
}

/* make call */
- if ( !pFunc( (HWND)1 /* fake window handle */, ODBC_CONFIG_DSN,
szDriverName, szSampleDataSource ) )
+ sprintf( szAttributes, "DSN=%s", pszDataSourceName );
+ memcpy( &(szAttributes[strlen(szAttributes) + 1]),
pszDataSourceNameAttributes, nDataSourceNameAttributesLength );
+ if ( !pFunc( (HWND)bGUI /* fake window handle */, nRequest, pszDriverName,
szAttributes ) )
{
printInstallerError();
return 0;
@@ -329,16 +319,24 @@
return 1;
}
#else
-int doEditDataSource()
+/*!
+ \brief Call drivers ConfigDSN without going through the DM.
+*/
+int doConfigDataSource( WORD nRequest )
{
+ char szAttributes[nDataSourceNameAttributesLength +
strlen(pszDataSourceName) + 5];
BOOL (*pFunc)( HWND, WORD, LPCSTR, LPCSTR );
void * hLib = 0;
char szDriverSetup[FILENAME_MAX + 1];

/* get the setup library from odbcinst */
- if ( !SQLGetPrivateProfileString( szDriverName, "Setup", "",
szDriverSetup, FILENAME_MAX, "ODBCINST.INI" ) )
+#ifdef _OSX_
+ if ( !GetPrivateProfileString( pszDriverName, "SETUP", "", szDriverSetup,
FILENAME_MAX, "ODBCINST.INI" ) )
+#else
+ if ( !SQLGetPrivateProfileString( pszDriverName, "SETUP", "",
szDriverSetup, FILENAME_MAX, "ODBCINST.INI" ) )
+#endif
{
- fprintf( stderr, "[%s][%d][ERROR] Could not determine the
path/filename of driver setup library for driver (%s).\n", __FILE__, __LINE__,
szDriverName );
+ fprintf( stderr, "[%s][%d][ERROR] Could not determine the
path/filename of driver setup library for driver (%s).\n", __FILE__, __LINE__,
pszDriverName );
return 0;
}

@@ -360,7 +358,9 @@
}

/* make call */
- if ( !pFunc( (HWND)1 /* fake window handle */, ODBC_CONFIG_DSN,
szDriverName, szSampleDataSource ) )
+ sprintf( szAttributes, "DSN=%s", pszDataSourceName );
+ memcpy( &(szAttributes[strlen(szAttributes) + 1]),
pszDataSourceNameAttributes, nDataSourceNameAttributesLength );
+ if ( !pFunc( (HWND)bGUI /* fake window handle */, nRequest, pszDriverName,
szAttributes ) )
{
printInstallerError();
return 0;
@@ -372,7 +372,21 @@
return 1;
}
#endif
-#endif
+
+/*!
+ \brief Remove data source name from ODBC system information.
+*/
+int doRemoveDataSource()
+{
+ if ( SQLRemoveDSNFromIni( pszDataSourceName ) == FALSE )
+ {
+ printInstallerError();
+ fprintf( stderr, "[%s][%d][ERROR] Request failed.\n", __FILE__,
__LINE__ );
+ return 0;
+ }
+
+ return 1;
+}

/*!
\brief This is the entry point to this program.
@@ -382,6 +396,7 @@
int main( int argc, char *argv[] )
{
int nArg;
+ int nName = -1;

if ( argc <= 1 )
{
@@ -397,13 +412,23 @@
switch ( argv[nArg][1] )
{
/* actions (more args to be added) */
+ case 'q':
case 'i':
case 'u':
case 'e':
+ case 's':
+ case 'r':
cAction = argv[nArg][1];
break;
case 'g':
bGUI = 1;
+ break;
+ case 'd':
+ bQueryDrivers = 0;
+ break;
+ case 'n':
+ nName = nArg;
+ break;
default:
{
printf( szSyntax );
@@ -413,28 +438,48 @@
}
}

+ /* */
+ if ( nName >= 0 )
+ {
+ if ( cAction == 'i' || cAction == 'u' )
+ pszDriverName = &(argv[nArg][2]);
+ else if ( cAction == 's' || cAction == 'e' || cAction == 'r' )
+ pszDataSourceName = &(argv[nArg][2]);
+ }
+
+ if ( !(*pszDriverName) || !(*pszDataSourceName) )
+ {
+ printf( "[%s][%d][ERROR] Missing driver name or data source name.\n",
__FILE__, __LINE__ );
+ exit( 1 );
+ }
+
/* do it */
switch ( cAction )
{
+ case 'q':
+ if ( bQueryDrivers )
+ doQuery( "ODBCINST.INI" );
+ else
+ doQuery( "ODBC.INI" );
+ break;
case 'i':
- if ( !doRegisterDriver() )
- return 1;
- if ( !doCreateDataSource() )
- return 1;
- if ( bGUI )
- doManageDataSources();
+ doRegisterDriver();
break;
case 'u':
doDeregisterDriver();
break;
+ case 's':
+ doConfigDataSource( ODBC_ADD_DSN );
+ break;
case 'e':
- doEditDataSource();
+ doConfigDataSource( ODBC_CONFIG_DSN );
+ break;
+ case 'r':
+ doRemoveDataSource();
break;
default:
- {
- printf( "[%s][%d][ERROR] Invalid, or missing, action (%c)
specified.\n", __FILE__, __LINE__, cAction );
- exit( 1 );
- }
+ printf( "[%s][%d][ERROR] Invalid, or missing, action (%c)
specified.\n", __FILE__, __LINE__, cAction );
+ exit( 1 );
}

return 0;

--
MySQL ODBC Mailing List
For list archives: http://lists.mysql.com/myodbc
To unsubscribe: http://lists.mysql.com/myodbc?unsub=gcdmo-myodbc@xxxxxxxxxxx




<Prev in Thread] Current Thread [Next in Thread>
Sponsor
FREE Network Mapping Tool for Microsoft® OfficeVisio Professional 2007
Don't map your network by hand - let LANsurveyor Express for Microsoft Visio Professional 2007
automatically create network diagrams for you!
Google Custom Search

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation

Home | sitemap | advertise | OSDir is an inevitable website. super tiny logo