Beispiel #1
0
BOOL INSTAPI  SQLReadFileDSNW(LPCWSTR  lpszFileName,
                              LPCWSTR  lpszAppName,
                              LPCWSTR  lpszKeyName,
                              LPWSTR   lpszString,
                              WORD     cbString,
                              WORD    *pcbString)
{
    char *file;
    char *app;
    char *key;
    char *str;
    WORD len;
    BOOL ret;

    inst_logClear();

    file = lpszFileName ? _single_string_alloc_and_copy( lpszFileName ) : (char*)NULL;
    app = lpszAppName ? _single_string_alloc_and_copy( lpszAppName ) : (char*)NULL;
    key = lpszKeyName ? _single_string_alloc_and_copy( lpszKeyName ) : (char*)NULL;

    if ( lpszString )
    {
        if ( cbString > 0 )
        {
            str = calloc( cbString + 1, 1 );
        }
        else
        {
            str = NULL;
        }
    }
    else
    {
        str = NULL;
    }

    ret = SQLReadFileDSN( file, app, key, str, cbString, &len );

    if ( ret )
    {
        if ( str && lpszString )
        {
            _single_copy_to_wide( lpszString, str, len + 1 );
        }
    }

    if ( file )
        free( file );
    if ( app )
        free( app );
    if ( key )
        free( key );
    if ( str )
        free( str );

    if ( pcbString )
        *pcbString = len;

    return ret;
}
Beispiel #2
0
BOOL INSTAPI
SQLReadFileDSNW (LPCWSTR lpszFileName, LPCWSTR lpszAppName,
                 LPCWSTR lpszKeyName, LPWSTR lpszString, WORD cbString, WORD * pcbString)
{
    char *_filename_u8 = NULL;
    char *_appname_u8 = NULL;
    char *_keyname_u8 = NULL;
    char *_string_u8 = NULL;
    BOOL retcode = FALSE;

    _filename_u8 = (char *) dm_SQL_WtoU8 ((SQLWCHAR *) lpszFileName, SQL_NTS);
    if (_filename_u8 == NULL && lpszFileName)
    {
        PUSH_ERROR (ODBC_ERROR_OUT_OF_MEM);
        goto done;
    }

    _appname_u8 = (char *) dm_SQL_WtoU8 ((SQLWCHAR *) lpszAppName, SQL_NTS);
    if (_appname_u8 == NULL && lpszAppName)
    {
        PUSH_ERROR (ODBC_ERROR_OUT_OF_MEM);
        goto done;
    }

    _keyname_u8 = (char *) dm_SQL_WtoU8 ((SQLWCHAR *) lpszKeyName, SQL_NTS);
    if (_keyname_u8 == NULL && lpszKeyName)
    {
        PUSH_ERROR (ODBC_ERROR_OUT_OF_MEM);
        goto done;
    }

    if (cbString > 0)
    {
        if ((_string_u8 = malloc (cbString * UTF8_MAX_CHAR_LEN + 1)) == NULL)
        {
            PUSH_ERROR (ODBC_ERROR_OUT_OF_MEM);
            goto done;
        }
    }

    retcode =
        SQLReadFileDSN (_filename_u8, _appname_u8, _keyname_u8, _string_u8,
                        cbString * UTF8_MAX_CHAR_LEN, pcbString);

    if (retcode == TRUE)
    {
        dm_StrCopyOut2_U8toW (_string_u8, lpszString, cbString, pcbString);
    }

done:
    MEM_FREE (_filename_u8);
    MEM_FREE (_appname_u8);
    MEM_FREE (_keyname_u8);
    MEM_FREE (_string_u8);

    return retcode;
}
Beispiel #3
0
void
TKVList::ReadFileDSN (LPCTSTR filename, LPCTSTR names)
{
  TCHAR value[512];
  LPCTSTR key;
  WORD len;

  for (key = names; *key; key += _tcslen (key) + 1)
    {
      value[0] = 0;
      if (SQLReadFileDSN (filename, _T("ODBC"), key, value,
	  NUMCHARS (value), &len))
	{
	  Define (key, value);
	}
    }
}
Beispiel #4
0
void CFileList::Edit()
{
	// odbc.ini INFO
	QString				qsDataSourceName		= "";
	QString				qsDataSourceDescription		= "";
	QString				qsDataSourceDriver		= "";
	// odbcinst.ini INFO
	QString				qsDriverFile			= "";
	QString				qsSetupFile				= "";
	QString				qsError					= "";

	CPropertiesFrame		*pProperties;
	HODBCINSTPROPERTY	hFirstProperty	= NULL;
	HODBCINSTPROPERTY	hCurProperty	= NULL;
#ifdef QT_V4LAYOUT
	Q3ListViewItem		*pListViewItem;
#else
	QListViewItem		*pListViewItem;
#endif

	char				szEntryNames[4096];
	char				szProperty[INI_MAX_PROPERTY_NAME+1];
	char				szValue[INI_MAX_PROPERTY_VALUE+1];
	
	DWORD				nErrorCode;
	char				szErrorMsg[101];
	char				szINI[FILENAME_MAX+1];
	int					nElement;	

    char dir[ 256 ];
    char szDriver[ 256 ];
    QString qsFileName;

	// HAS THE USER SELECTED SOMETHING
    pListViewItem = currentItem();
	if ( pListViewItem )
	{
		qsFileName		= pListViewItem->text( 0 );

        /*
		qsDataSourceDescription	= pListViewItem->text( 1 );
		qsDataSourceDriver		= pListViewItem->text( 2 );
        */
	}
	else
	{
		QMessageBox::information( this, "ODBC Config",  "Please select a Data Source from the list first" );
		return;
	}

    sprintf( dir, "%s/%s", cwd.ascii(), qsFileName.ascii());
    szDriver[ 0 ] = '\0';
    if ( !SQLReadFileDSN( dir, "ODBC", "DRIVER", szDriver, sizeof( szDriver ), NULL ) ||
            strlen( szDriver ) < 1 )
    {
        char szDsn[ 256 ];

        szDsn[ 0 ] = '\0';
        if ( SQLReadFileDSN( dir, "ODBC", "DSN", szDsn, sizeof( szDsn ), NULL ) &&
                strlen( szDsn ) >= 1 )
        {
            SQLSetConfigMode( ODBC_BOTH_DSN );
			SQLGetPrivateProfileString( szDsn, "Driver", "", szDriver, sizeof( szDriver ), "odbc.ini" );

            if ( strlen( szDriver ) < 1 )
            {
                QMessageBox::information( this, "ODBC Config",  "Unable to extract driver from FILE DSN" );
                return;
            }
        }
        else
        {
            QMessageBox::information( this, "ODBC Config",  "Unable to extract driver from FILE DSN" );
            return;
        }
    }

    //
    // can we call SQLDriverConnect
    //

	// GET PROPERTY LIST FROM DRIVER
	if ( ODBCINSTConstructProperties( szDriver, &hFirstProperty ) != ODBCINST_SUCCESS )
	{
		qsError.sprintf( "Could not construct a property list for (%s)", szDriver );
		QMessageBox::information( this, "ODBC Config",  qsError );

        int i = 1;
		while ( SQLInstallerError( i ++, &nErrorCode, szErrorMsg, 100, NULL ) == SQL_SUCCESS )
			QMessageBox::information( this, "ODBC Config",  szErrorMsg );

		return;
	}

	ODBCINSTSetProperty( hFirstProperty, "Name", (char*)qsFileName.ascii());

    for ( hCurProperty = hFirstProperty->pNext; hCurProperty != NULL; hCurProperty = hCurProperty->pNext )
    {
        char szAttr[ 256 ];

        szAttr[ 0 ] = '\0';
        if ( SQLReadFileDSN( dir, "ODBC", hCurProperty->szName, szAttr, sizeof( szAttr ), NULL ))
        {
		    ODBCINSTSetProperty( hFirstProperty, hCurProperty->szName, szAttr );
        }
    }

	// ALLOW USER TO EDIT
	pProperties = new CPropertiesFrame( this, "Properties", hFirstProperty );
	pProperties->setCaption( "Data Source Properties (edit)" );
	if ( pProperties->exec() )
	{
        int ret;

        ret = SQLWriteFileDSN( dir, "ODBC", NULL, NULL );
        if ( !ret )
        {
            qsError.sprintf( "Could not write to (%s)", dir );
            QMessageBox::information( this, "ODBC Config",  qsError );

            int i = 1;
            while ( SQLInstallerError( i++, &nErrorCode, szErrorMsg, 100, NULL ) == SQL_SUCCESS )
                QMessageBox::information( this, "ODBC Config",  szErrorMsg );

            return;
        }

        for ( hCurProperty = hFirstProperty->pNext; hCurProperty != NULL; hCurProperty = hCurProperty->pNext )
        {
            if ( !SQLWriteFileDSN( dir, "ODBC", hCurProperty->szName, hCurProperty->szValue ))
            {
                qsError.sprintf( "Could not write to file dsn (%s)", dir );
                QMessageBox::information( this, "ODBC Config",  qsError );

                int i = 1;
                while ( SQLInstallerError( i ++, &nErrorCode, szErrorMsg, 100, NULL ) == SQL_SUCCESS )
                    QMessageBox::information( this, "ODBC Config",  szErrorMsg );

                return;
            }
        }
	}
	delete pProperties;
	ODBCINSTDestructProperties( &hFirstProperty );

	// RELOAD (slow but safe)
	Load();
}
Beispiel #5
0
pascal OSStatus
filedsn_configure_clicked (EventHandlerCallRef inHandlerRef,
    EventRef inEvent, void *inUserData)
{
  TDSNCHOOSER *choose_t = (TDSNCHOOSER *) inUserData;
  DataBrowserItemID first, last;
  OSStatus err;
  char str[1024], path[1024];
  int id;
  char *drv = NULL;
  char *attrs = NULL;
  char *_attrs = NULL;	/* attr list */
  size_t len = 0;	/* current attr list length (w/o list-terminating NUL) */
  char *p, *p_next;
  WORD read_len;
  char entries[4096];
  char *curr_dir;

  if (!choose_t)
    return noErr;

  curr_dir = choose_t->curr_dir;

  /* Retrieve the DSN name */
  if ((err = GetDataBrowserSelectionAnchor (choose_t->fdsnlist,
       &first, &last)) == noErr)
    {
      if (first > DBITEM_ID && first <= DBITEM_ID + FDSN_nrows)
        {
          id = first - DBITEM_ID - 1;
          CFStringGetCString(FDSN_array[id], str, sizeof(str), kCFStringEncodingUTF8);

          if (*curr_dir == '/' && strlen(curr_dir) == 1)
            snprintf(path, sizeof(path), "/%s", str);
          else
            snprintf(path, sizeof(path), "%s/%s", curr_dir, str);

          if (FDSN_type[id] == 0)  /* Directory */
            {
              addfdsns_to_list (choose_t, path, true);
            }

          else  /* File DSN*/
            {
              /* Get list of entries in .dsn file */
              if (!SQLReadFileDSN (path, "ODBC", NULL,
		       entries, sizeof (entries), &read_len))
                {
                  create_error (choose_t->mainwnd, NULL, "SQLReadFileDSN failed", NULL);
                  goto done;
                }

              /* add params from the .dsn file */
              for (p = entries; *p != '\0'; p = p_next)
                {
                  char *tmp;
                  size_t add_len;		/* length of added attribute */
                  char value[1024];

                  /* get next entry */
                  p_next = strchr (p, ';');
                  if (p_next)
                    *p_next++ = '\0';

                  if (!SQLReadFileDSN (path, "ODBC", p, value, sizeof(value), &read_len))
                    {
                      create_error (choose_t->mainwnd, NULL, "SQLReadFileDSN failed", NULL);
                      goto done;
                    }

                  if (!strcasecmp (p, "DRIVER"))
                    {
                      /* got driver keyword */
                      add_len = strlen ("DRIVER=") + strlen (value) + 1;
                      drv = malloc (add_len);
                      snprintf (drv, add_len, "DRIVER=%s", value);
                      continue;
                    }

                  /* +1 for '=', +1 for NUL */
                  add_len = strlen (p) + 1 + strlen (value) + 1;
                  /* +1 for list-terminating NUL */;
                  tmp = realloc (attrs, len + add_len + 1);
                  if (tmp == NULL)
                    {
                      create_error (choose_t->mainwnd, NULL, "Error adding file DSN:",
                         strerror (errno));
                      goto done;
                    }
                  attrs = tmp;
                  snprintf (attrs + len, add_len, "%s=%s", p, value);
                  len += add_len;
                }

              if (drv == NULL)
                {
                  /* no driver found, probably unshareable file data source */
                  create_error (choose_t->mainwnd, NULL,
            	    "Can't configure file DSN without DRIVER keyword (probably unshareable data source?)", NULL);
                  goto done;
                }

              if (attrs == NULL)
                attrs = "\0\0";
              else
                {
                  /* NUL-terminate the list */
                  attrs[len] = '\0';
                  _attrs = attrs;
                }

              /* Configure file DSN */
              filedsn_configure (choose_t, drv, path, attrs, FALSE, TRUE);
              addfdsns_to_list (choose_t, curr_dir, true);
            }
        }
    }

done:
  if (drv != NULL)
    free (drv);
  if (_attrs != NULL)
    free (_attrs);

  if ((err = GetDataBrowserSelectionAnchor (choose_t->sdsnlist,
        &first, &last)) == noErr)
    {
      if (!first && !last)
        {
          DeactivateControl (choose_t->sremove);
          DeactivateControl (choose_t->sconfigure);
          DeactivateControl (choose_t->stest);
        }
    }
  return noErr;
}