コード例 #1
0
ファイル: filedsn.c プロジェクト: dancparkes/iODBC
static Boolean
_CheckDriverLoginDlg (
    char *drv
)
{
  char drvbuf[4096] = { L'\0'};
  HDLL handle;
  Boolean retVal = false;

  if (!drv)
    return false;

  SQLSetConfigMode (ODBC_USER_DSN);
  if (!access (drv, X_OK))
    { CHECK_DRVCONN_DIALBOX (drv); }
  if (SQLGetPrivateProfileString (drv, "Driver", "", drvbuf,
    sizeof (drvbuf), "odbcinst.ini"))
    { CHECK_DRVCONN_DIALBOX (drvbuf); }
  if (SQLGetPrivateProfileString (drv, "Setup", "", drvbuf,
    sizeof (drvbuf), "odbcinst.ini"))
    { CHECK_DRVCONN_DIALBOX (drvbuf); }

  SQLSetConfigMode (ODBC_SYSTEM_DSN);
  if (!access (drv, X_OK))
    { CHECK_DRVCONN_DIALBOX (drv); }
  if (SQLGetPrivateProfileString (drv, "Driver", "", drvbuf,
    sizeof (drvbuf), "odbcinst.ini"))
    { CHECK_DRVCONN_DIALBOX (drvbuf); }
  if (SQLGetPrivateProfileString (drv, "Setup", "", drvbuf,
    sizeof (drvbuf), "odbcinst.ini"))
    { CHECK_DRVCONN_DIALBOX (drvbuf); }

quit:
  return retVal;
}
コード例 #2
0
ファイル: henv.c プロジェクト: tws67/bayonne-cygwin
static void
_iodbcdm_env_settracing (GENV_t *genv)
{
  char buf[1024];

  genv = genv; /*UNUSED*/

  /*
   *  Check TraceFile keyword
   */
  SQLSetConfigMode (ODBC_BOTH_DSN);
  if( SQLGetPrivateProfileString ("ODBC", "TraceFile", "", buf, sizeof(buf) / sizeof(SQLTCHAR), "odbc.ini") == 0 || !buf[0])
    STRCPY (buf, SQL_OPT_TRACE_FILE_DEFAULT);
  trace_set_filename (buf);

  /*
   *  Check Trace keyword
   */
  SQLSetConfigMode (ODBC_BOTH_DSN);
  if ( SQLGetPrivateProfileString ("ODBC", "Trace", "", buf, sizeof(buf) / sizeof(SQLTCHAR), "odbc.ini") &&
      (STRCASEEQ (buf, "on") || STRCASEEQ (buf, "yes")
   || STRCASEEQ (buf, "1")))
    trace_start ();

  return;
}
コード例 #3
0
void DSN::loadAttributesFromRegistry()
{
	char buf[65536];
	const char* filename = "ODBC.INI";
	if (getName().size() == 0) return; // don't load from registry if this dsn does not have a name.
	SQLGetPrivateProfileString(getName().c_str(), "url", getUrl().c_str(), buf, 65536, filename);
	setUrl(buf);
	SQLGetPrivateProfileString(getName().c_str(), "uid", getUser().c_str(), buf, 65536, filename);
	setUser(buf);
	SQLGetPrivateProfileString(getName().c_str(), "pwd", getPassword().c_str(), buf, 65536, filename);
	setPassword(buf);
}
コード例 #4
0
ファイル: CODBCCreate.cpp プロジェクト: ystk/debian-unixodbc
void CODBCCreate::file_click()
{
	char path[ 1024 ];
	char def[ 1024 ];
	char buffer[ 128 ];

	sprintf( def, "%s/ODBCDataSources", odbcinst_system_file_path( buffer ));

	SQLGetPrivateProfileString( "ODBC", "FileDSNPath", 
			def, path, sizeof( path ), "odbcinst.ini" );

#ifdef QT_V4LAYOUT
	QString s = Q3FileDialog::getSaveFileName(
#else
	QString s = QFileDialog::getSaveFileName(
#endif
				path,
				"ODBC File Data Sources's (*.dsn)",
				this,
				"Select file name",
				"Choose a filename to save under" );

	if ( !s.isNull() )
	{
		file_edit->setText( s );
	}
}
コード例 #5
0
ファイル: misc.c プロジェクト: Chaduke/bah.mod
/*
 * Get FILEDSN file name
 *
 * If file name does not contain path component, the default directory for
 * saving and loading a .dsn file will be defined as follows:
 * 1. if FILEDSNPATH is set in environment: use environment
 * 2. if odbcinst.ini [odbc] FILEDSNPATH is set: use this
 * 3. else use DEFAULT_FILEDSNPATH
 *
 * ".dsn" extension is always appended to the resulting filename
 * (if not already exists).
 */
void
_iodbcdm_getdsnfile(const char *filedsn, char *buf, size_t buf_sz)
{
  char *p;
  char *default_path;

  if (strchr (filedsn, '/') != NULL)
    {
      /* has path component -- copy as is */
      _iodbcdm_strlcpy (buf, filedsn, buf_sz);
      goto done;
    }

  /* get default path */
  if ((default_path = getenv ("FILEDSNPATH")) != NULL)
    _iodbcdm_strlcpy (buf, default_path, buf_sz);
  else
    {
      SQLSetConfigMode (ODBC_BOTH_DSN);
      if (!SQLGetPrivateProfileString ("ODBC", "FileDSNPath", "",
				       buf, buf_sz, "odbcinst.ini"))
        _iodbcdm_strlcpy (buf, DEFAULT_FILEDSNPATH, buf_sz);
    }

  /* append filedsn file name */
  _iodbcdm_strlcat (buf, "/", buf_sz);
  _iodbcdm_strlcat (buf, filedsn, buf_sz);

done:
  /* append ".dsn" if extension is not ".dsn" */
  if ((p = strrchr (buf, '.')) == NULL ||
      strcasecmp (p, ".dsn") != 0)
    _iodbcdm_strlcat (buf, ".dsn", buf_sz);
}
コード例 #6
0
/*******************************************************
 * Init
 *******************************************************
 * Call the odbcinst to get Driver description.
 *
 * NOTE: 	This should be done via the Driver Manager by
 *			calling SQLDrivers() but the iODBC Driver Manager
 *			does not, at this time, adequately support this call.
 *******************************************************/
void classDriver::Init( char *pszDriverName, SQLHENV hEnv )
{
	char 				szResults[1024];
	char				szPropertyValue[INI_MAX_PROPERTY_VALUE+1];

	qsDriverName = "";
	if ( pszDriverName != 0 )
		qsDriverName = pszDriverName;

	this->pCanvas 	= pCanvas;
	this->hEnv 		= hEnv;
	setPixmap( 0, QPixmap( driver_xpm ) );

	szResults[0] 		= '\0';
    szPropertyValue[0]	= '\0';
	if ( SQLGetPrivateProfileString((char*) qsDriverName.data(), "Description", "", szResults, sizeof(szResults), "odbcinst" ) > 0 )
		iniElement( szResults, '\0', '\0', 0, szPropertyValue, INI_MAX_PROPERTY_VALUE );
	else
	{
		//SQLInstallerError( 1, &nError, szError, FILENAME_MAX, 0 );
		//if ( cVerbose == 0 ) printf( "[odbcinst] SQLGetPrivateProfileString failed with %s.\n", szError );
		//return;
	}

	setText( 0, qsDriverName );
	setText( 1, "" );
	setText( 2, szPropertyValue );
}
コード例 #7
0
/* {{{ MADB_ReadDSN */
my_bool MADB_ReadDSN(MADB_Dsn *Dsn, char *KeyValue, my_bool OverWrite)
{
  char *Value;
  /* if no key/value pair was specified, we will try to read Dsn->DSNName */
  if (!KeyValue)
  {
    if (!Dsn->DSNName)
      return FALSE;
    Value= Dsn->DSNName;
  }
  else 
  {
    if (Value= strchr(KeyValue, '='))
      ++Value;
  }
  
  if (Value)
  {
    int i= 1;
    char KeyVal[1024];
    Dsn->DSNName= _strdup(Value);
    while (DsnKeys[i].DsnKey)
    {
      if (SQLGetPrivateProfileString(Dsn->DSNName, DsnKeys[i].DsnKey, NULL, KeyVal, 1024, "ODBC.INI"))
      {
        if (!MADB_DsnStoreValue(Dsn, DsnKeys[i].DsnOffset, KeyVal, DsnKeys[i].Type, OverWrite))
          return FALSE;
      }
      ++i;
    }
    return TRUE;
  }
  return FALSE;
}
コード例 #8
0
BOOL		WINAPI
DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
	switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
			s_hModule = hInst;	/* Save for dialog boxes */

			if (initialize_global_cs() == 0)
				getCommonDefaults(DBMS_NAME, ODBCINST_INI, NULL);
#ifdef	PG_BIN
			if (s_hLModule = LoadLibraryEx(PG_BIN "\\libpq.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH), s_hLModule == NULL)
			{
				char dllPath[MAX_PATH] = "", message[MAX_PATH] = "";

				mylog("libpq in the folder %s couldn't be loaded\n", PG_BIN);
				SQLGetPrivateProfileString(DBMS_NAME, "Driver", "", dllPath, sizeof(dllPath), ODBCINST_INI);
				if (dllPath[0])
				{
					char drive[_MAX_DRIVE], dir[_MAX_DIR];

					_splitpath(dllPath, drive, dir, NULL, NULL);
					snprintf(dllPath, sizeof(dllPath), "%s%slibpq.dll", drive, dir);
					if (s_hLModule = LoadLibraryEx(dllPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH), s_hLModule == NULL)
					{
						mylog("libpq in the folder %s%s couldn't be loaded\n", drive, dir);
						snprintf(message, sizeof(message), "libpq in neither %s nor %s%s could be loaded", PG_BIN, drive, dir);
					}
				}
				else
					snprintf(message, sizeof(message),  "libpq in the folder %s couldn't be loaded", PG_BIN);
				if (message[0])
					MessageBox(NULL, message, "psqlsetup", MB_OK);
			}
			EnableDelayLoadHook();
#endif
			break;

		case DLL_THREAD_ATTACH:
			break;

		case DLL_PROCESS_DETACH:
			CleanupDelayLoadedDLLs();
			FreeLibrary(s_hLModule);
			finalize_global_cs();
			return TRUE;

		case DLL_THREAD_DETACH:
			break;

		default:
			break;
	}

	return TRUE;

	UNREFERENCED_PARAMETER(lpReserved);
}
コード例 #9
0
ファイル: dsn_config.cpp プロジェクト: psadusumilli/ignite
        std::string ReadDsnString(const char* dsn, const std::string& key, const std::string& dflt)
        {
            char buf[BUFFER_SIZE];

            memset(buf, 0, sizeof(buf));

            SQLGetPrivateProfileString(dsn, key.c_str(), dflt.c_str(), buf, sizeof(buf), CONFIG_FILE);

            return std::string(buf);
        }
コード例 #10
0
BOOL GetReadOnly(char *dsn)
{
    char readOnly[2] = "\0";

    SQLGetPrivateProfileString (dsn, KEY_READONLY, "", readOnly,
        sizeof(readOnly),ODBC_INI);
    if (!CMcmpnocase(&readOnly[0],"Y"))
        return 1;
    return 0;
}
コード例 #11
0
ファイル: connect.c プロジェクト: RQZeng/freetds
static char *
get_entry(const char *key)
{
	static char buf[256];

	entry = NULL;
	if (SQLGetPrivateProfileString(odbc_server, key, "", buf, sizeof(buf), "odbc.ini") > 0)
		entry = buf;

	return entry;
}
コード例 #12
0
my_bool MADB_DSN_Exists(char *DsnName)
{
  my_bool ret;
  char buffer[1024];
  char *p= "";
  if (!DsnName)
    return FALSE;

  ret= (SQLGetPrivateProfileString(DsnName, NULL, p, buffer, 1024, "ODBC.INI") > 0);
  return ret;
}
コード例 #13
0
ファイル: connectparams.c プロジェクト: abougouffa/mdbtools
gchar* GetConnectParam (ConnectParams* params, const gchar* paramName)
{
	static char tmp[FILENAME_MAX];

	/* use old servername */
	tmp[0] = '\0';
	if (SQLGetPrivateProfileString(params->dsnName->str, paramName, "", tmp, FILENAME_MAX, "odbc.ini") > 0) {
		return tmp;
	}
	return NULL;

}
コード例 #14
0
ファイル: dsn_config.cpp プロジェクト: psadusumilli/ignite
        int ReadDsnInt(const char* dsn, const std::string& key, int dflt)
        {
            char buf[BUFFER_SIZE];

            memset(buf, 0, sizeof(buf));

            std::string dflt0 = common::LexicalCast<std::string>(dflt);

            SQLGetPrivateProfileString(dsn, key.c_str(), dflt0.c_str(), buf, sizeof(buf), CONFIG_FILE);

            return common::LexicalCast<int, std::string>(buf);
        }
コード例 #15
0
ファイル: dsn_config.cpp プロジェクト: psadusumilli/ignite
        bool ReadDsnBool(const char* dsn, const std::string& key, bool dflt)
        {
            char buf[BUFFER_SIZE];

            memset(buf, 0, sizeof(buf));

            std::string dflt0 = dflt ? "true" : "false";

            SQLGetPrivateProfileString(dsn, key.c_str(), dflt0.c_str(), buf, sizeof(buf), CONFIG_FILE);

            return std::string(buf) == "true";
        }
コード例 #16
0
ファイル: kvlist.cpp プロジェクト: Rahien/virtuoso-opensource
void
TKVList::ReadODBCIni (LPCTSTR section, LPCTSTR names)
{
  TCHAR value[512];
  LPCTSTR key;

  for (key = names; *key; key += _tcslen (key) + 1)
    {
      SQLGetPrivateProfileString (section, key, _T(" "), value,
	  NUMCHARS (value), _T("odbc.ini"));
      if (_tcscmp (value, _T(" ")))
	Define (key, value);
    }
}
コード例 #17
0
ファイル: _odbcinst_UserINI.c プロジェクト: adler187/unixODBC
BOOL _odbcinst_FileINI( char *pszPath )
{
	char b1[ ODBC_FILENAME_MAX + 1 ];

    /* we need a viable buffer (with space for FILENAME_MAX chars)... */
    if ( !pszPath )
        return FALSE;

    /* system configured to use a special location... */
    *pszPath = '\0';
    SQLGetPrivateProfileString( "ODBC", "FileDSNPath", "", pszPath, FILENAME_MAX - 2, "odbcinst.ini" );
    if ( *pszPath )
        return TRUE;

    /* default location... */
    sprintf( pszPath, "%s/ODBCDataSources", odbcinst_system_file_path( b1 ));

    return TRUE;
}
コード例 #18
0
void COdbcDS::RetrieveMxDSInfo(int iType, CDSList& DSList)
{
	TCHAR Buff[255];
	char* DSName = NULL;
	int count = DSList.getCount();
	int length = sizeof(PRIV_PROFILE) / MAXKEYLEN;

	// Set the config mode to the desired type.
	UWORD oldMode, newMode;

	if (iType == COdbcDS::DS_TYPE_SYS)
	{
		newMode = ODBC_SYSTEM_DSN;
	}
	else
	{
		newMode = ODBC_USER_DSN;
	}

	SQLGetConfigMode(&oldMode);
	SQLSetConfigMode(newMode);

	for (int i = 0; i < count; i++)
	{
		DSName = DSList.getAt(i);

		for(int index = 0; index < length; index++)
		{

			// Retrieve the private profile strings.
			SQLGetPrivateProfileString(DSName, PRIV_PROFILE[index],
				"", Buff, sizeof(Buff), ODBC_INI);
			DSList.addAttrib(i, PRIV_PROFILE[index], Buff);
		}

		delete [] DSName;
	}

	// Restore old config mode.
	SQLSetConfigMode(oldMode);
}
コード例 #19
0
/*! 
 * \brief   Get the short name of the UI plugin.
 * 
 *          The short name is the file name without path or file extension.
 *
 *          We silently prepend "lib" here as well.
 *
 * \param   pszName     Place to put short name. Should be FILENAME_MAX bytes. 
 * \param   pszUI       Our generic window handle.
 * 
 * \return  char*       pszName returned for convenience.
 */
char *_getUIPluginName( char *pszName, char *pszUI )
{
    *pszName = '\0';

    /* is it being provided by caller? */
    if ( pszUI && *pszUI )
    {
        sprintf( pszName, "lib%s", pszUI );
        return pszName;
    }

    /* is it being provided by env var? */
    {
        char *pEnvVar = getenv( "ODBCINSTUI" );
        if ( pEnvVar )
        {
            sprintf( pszName, "lib%s", pEnvVar );
            return pszName;
        }
    }

    /* is it being provided by odbcinst.ini? */
    {
        char sz[FILENAME_MAX];
        *sz='\0';
        SQLGetPrivateProfileString( "ODBC", "ODBCINSTUI", "", sz, FILENAME_MAX, "odbcinst.ini" );
        if ( *sz )
        {
            sprintf( pszName, "lib%s", sz );
            return pszName;
        }
    }

    /* default to qt4 */
    strcpy( pszName, "libodbcinstQ4" );

    return pszName;
}
コード例 #20
0
void classDataSources::setOpen( bool bOpen )
{
	int					nElement;
	char 				szResults[9600];
	char				szObjectName[INI_MAX_OBJECT_NAME+1];

    memset( szResults, 0, sizeof(szResults) );  // Results buffer must be cleared 
    classDataSource     *pLastDataSource    = NULL;

    if ( bOpen )
    {
		memset( szResults, 0, sizeof(szResults) );
		if ( nDataSourceType == User )
			SQLSetConfigMode( ODBC_USER_DSN );
		else
			SQLSetConfigMode( ODBC_SYSTEM_DSN );

		if ( SQLGetPrivateProfileString( 0, 0, 0, szResults, 9600, 0 ) > 0 )
		{
			for ( nElement = 0; iniElement( szResults, '\0', '\0', nElement, szObjectName, INI_MAX_OBJECT_NAME ) == INI_SUCCESS; nElement++ )
			{
				listDataSources.append( pLastDataSource = new classDataSource( this, pLastDataSource, pCanvas, nDataSourceType, szObjectName, hEnv ) );
			}
		}
		else
		{
			//SQLInstallerError( 1, &nError, szError, FILENAME_MAX, 0 );
			//if ( cVerbose == 0 ) printf( "[odbcinst] SQLGetPrivateProfileString failed with %s.\n", szError );
			//return;
		}
		SQLSetConfigMode( ODBC_BOTH_DSN );
    }
    else
    {
        listDataSources.clear();
    }
    QListViewItem::setOpen( bOpen );
}
コード例 #21
0
ファイル: dlg_specific.c プロジェクト: greenplum-db/gpclients
int
getLogDir(char *dir, int dirmax)
{
	return SQLGetPrivateProfileString(DBMS_NAME, INI_LOGDIR, "", dir, dirmax, ODBCINST_INI);
}
コード例 #22
0
ファイル: dlg_specific.c プロジェクト: greenplum-db/gpclients
int
getDriverNameFromDSN(const char *dsn, char *driver_name, int namelen)
{
	return SQLGetPrivateProfileString(ODBC_DATASOURCES, dsn, "", driver_name, namelen, ODBC_INI);
}
コード例 #23
0
ファイル: dlg_specific.c プロジェクト: greenplum-db/gpclients
/*
 *	This function reads the ODBCINST.INI portion of
 *	the registry and gets any driver defaults.
 */
void
getCommonDefaults(const char *section, const char *filename, ConnInfo *ci)
{
	char		temp[256];
	GLOBAL_VALUES *comval;
	BOOL	inst_position = (stricmp(filename, ODBCINST_INI) == 0);

	if (ci)
		comval = &(ci->drivers);
	else
		comval = &globals;
	/* Fetch Count is stored in driver section */
	SQLGetPrivateProfileString(section, INI_FETCH, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
	{
		comval->fetch_max = atoi(temp);
		/* sanity check if using cursors */
		if (comval->fetch_max <= 0)
			comval->fetch_max = FETCH_MAX;
	}
	else if (inst_position)
		comval->fetch_max = FETCH_MAX;

	/* Socket Buffersize is stored in driver section */
	SQLGetPrivateProfileString(section, INI_SOCKET, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
		comval->socket_buffersize = atoi(temp);
	else if (inst_position)
		comval->socket_buffersize = SOCK_BUFFER_SIZE;

	/* Debug is stored in the driver section */
	SQLGetPrivateProfileString(section, INI_DEBUG, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
		comval->debug = atoi(temp);
	else if (inst_position)
		comval->debug = DEFAULT_DEBUG;

	/* CommLog is stored in the driver section */
	SQLGetPrivateProfileString(section, INI_COMMLOG, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
		comval->commlog = atoi(temp);
	else if (inst_position)
		comval->commlog = DEFAULT_COMMLOG;

	if (!ci)
		logs_on_off(0, 0, 0);
	/* Optimizer is stored in the driver section only */
	SQLGetPrivateProfileString(section, INI_OPTIMIZER, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
		comval->disable_optimizer = atoi(temp);
	else if (inst_position)
		comval->disable_optimizer = DEFAULT_OPTIMIZER;

	/* KSQO is stored in the driver section only */
	SQLGetPrivateProfileString(section, INI_KSQO, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
		comval->ksqo = atoi(temp);
	else if (inst_position)
		comval->ksqo = DEFAULT_KSQO;

	/* Recognize Unique Index is stored in the driver section only */
	SQLGetPrivateProfileString(section, INI_UNIQUEINDEX, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
		comval->unique_index = atoi(temp);
	else if (inst_position)
		comval->unique_index = DEFAULT_UNIQUEINDEX;


	/* Unknown Sizes is stored in the driver section only */
	SQLGetPrivateProfileString(section, INI_UNKNOWNSIZES, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
		comval->unknown_sizes = atoi(temp);
	else if (inst_position)
		comval->unknown_sizes = DEFAULT_UNKNOWNSIZES;


	/* Lie about supported functions? */
	SQLGetPrivateProfileString(section, INI_LIE, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
		comval->lie = atoi(temp);
	else if (inst_position)
		comval->lie = DEFAULT_LIE;

	/* Parse statements */
	SQLGetPrivateProfileString(section, INI_PARSE, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
		comval->parse = atoi(temp);
	else if (inst_position)
		comval->parse = DEFAULT_PARSE;

	/* SQLCancel calls SQLFreeStmt in Driver Manager */
	SQLGetPrivateProfileString(section, INI_CANCELASFREESTMT, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
		comval->cancel_as_freestmt = atoi(temp);
	else if (inst_position)
		comval->cancel_as_freestmt = DEFAULT_CANCELASFREESTMT;

	/* UseDeclareFetch is stored in the driver section only */
	SQLGetPrivateProfileString(section, INI_USEDECLAREFETCH, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
		comval->use_declarefetch = atoi(temp);
	else if (inst_position)
		comval->use_declarefetch = DEFAULT_USEDECLAREFETCH;

	/* Max Varchar Size */
	SQLGetPrivateProfileString(section, INI_MAXVARCHARSIZE, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
		comval->max_varchar_size = atoi(temp);
	else if (inst_position)
		comval->max_varchar_size = MAX_VARCHAR_SIZE;

	/* Max TextField Size */
	SQLGetPrivateProfileString(section, INI_MAXLONGVARCHARSIZE, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
		comval->max_longvarchar_size = atoi(temp);
	else if (inst_position)
		comval->max_longvarchar_size = TEXT_FIELD_SIZE;

	/* Text As LongVarchar	*/
	SQLGetPrivateProfileString(section, INI_TEXTASLONGVARCHAR, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
		comval->text_as_longvarchar = atoi(temp);
	else if (inst_position)
		comval->text_as_longvarchar = DEFAULT_TEXTASLONGVARCHAR;

	/* Unknowns As LongVarchar	*/
	SQLGetPrivateProfileString(section, INI_UNKNOWNSASLONGVARCHAR, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
		comval->unknowns_as_longvarchar = atoi(temp);
	else if (inst_position)
		comval->unknowns_as_longvarchar = DEFAULT_UNKNOWNSASLONGVARCHAR;

	/* Bools As Char */
	SQLGetPrivateProfileString(section, INI_BOOLSASCHAR, "",
							   temp, sizeof(temp), filename);
	if (temp[0])
		comval->bools_as_char = atoi(temp);
	else if (inst_position)
		comval->bools_as_char = DEFAULT_BOOLSASCHAR;

	/* Extra Systable prefixes */

	/*
	 * Use @@@ to distinguish between blank extra prefixes and no key
	 * entry
	 */
	SQLGetPrivateProfileString(section, INI_EXTRASYSTABLEPREFIXES, "@@@",
							   temp, sizeof(temp), filename);
	if (strcmp(temp, "@@@"))
		strcpy(comval->extra_systable_prefixes, temp);
	else if (inst_position)
		strcpy(comval->extra_systable_prefixes, DEFAULT_EXTRASYSTABLEPREFIXES);

	mylog("globals.extra_systable_prefixes = '%s'\n", comval->extra_systable_prefixes);


	/* Dont allow override of an override! */
	if (inst_position)
	{
		/*
		 * ConnSettings is stored in the driver section and per datasource
		 * for override
		 */
		SQLGetPrivateProfileString(section, INI_CONNSETTINGS, "",
		 comval->conn_settings, sizeof(comval->conn_settings), filename);

		/* Default state for future DSN's Readonly attribute */
		SQLGetPrivateProfileString(section, INI_READONLY, "",
								   temp, sizeof(temp), filename);
		if (temp[0])
			comval->onlyread = atoi(temp);
		else
			comval->onlyread = DEFAULT_READONLY;

		/*
		 * Default state for future DSN's protocol attribute This isn't a
		 * real driver option YET.	This is more intended for
		 * customization from the install.
		 */
		SQLGetPrivateProfileString(section, INI_PROTOCOL, "@@@",
								   temp, sizeof(temp), filename);
		if (strcmp(temp, "@@@"))
			strcpy(comval->protocol, temp);
		else
			strcpy(comval->protocol, DEFAULT_PROTOCOL);
	}
}
コード例 #24
0
ファイル: CTracing.cpp プロジェクト: ystk/debian-unixodbc
CTracing::CTracing( QWidget* parent, const char* name )
	: QWidget( parent, name, 0 )
{
	QBoxLayout	*playoutTop		= new QVBoxLayout( this, 5 );

    // Tracing
#ifdef QT_V4LAYOUT
	Q3GroupBox *pgroupbox = new Q3GroupBox( this );
#else
	QGroupBox *pgroupbox = new QGroupBox( this );
#endif
	pgroupbox->setFrameStyle( QFrame::Box | QFrame::Raised );
    pgroupbox->setTitle( QString("Tracing") );
	playoutTop->addWidget( pgroupbox, 5 );

    QGridLayout *playoutGrid = new QGridLayout( pgroupbox, 3, 2, 5 );

	QLabel *plabel1	= new QLabel( "Enabled", pgroupbox, "plabel1" );
	pTracing 		= new QCheckBox( pgroupbox, "pTracing" );
	QLabel *plabel3	= new QLabel( "Force Tracing", pgroupbox, "plabel1" );
	pForce 		    = new QCheckBox( pgroupbox, "pForce" );
	QLabel *plabel2	= new QLabel( "File", pgroupbox, "plabel2" );
	pTraceFile		= new CFileSelector( pgroupbox, "pTraceFile" );

	playoutGrid->addWidget( plabel1, 1, 0 );
    playoutGrid->addWidget( pTracing, 1, 1 );
    playoutGrid->addWidget( plabel3, 1, 2 );
    playoutGrid->addWidget( pForce, 1, 3 );
    playoutGrid->addWidget( plabel2, 2, 0 );
    playoutGrid->addWidget( pTraceFile, 2, 1 );

    // Connection Pooling
#ifdef QT_V4LAYOUT
	pgroupbox = new Q3GroupBox( this );
#else
	pgroupbox = new QGroupBox( this );
#endif
	pgroupbox->setFrameStyle( QFrame::Box | QFrame::Raised );
    pgroupbox->setTitle( QString("Connection Pooling") );
	playoutTop->addWidget( pgroupbox, 5 );

    playoutGrid = new QGridLayout( pgroupbox, 3, 3, 5 );
    playoutGrid->setColStretch( 2, 10 );

	plabel1	    = new QLabel( "Enabled", pgroupbox, "plabel1" );
	pPooling    = new QCheckBox( pgroupbox, "pPooling" );

	playoutGrid->addWidget( plabel1, 1, 0 );
    playoutGrid->addWidget( pPooling, 1, 1 );

    // Buttons
    playoutGrid = new QGridLayout( playoutTop, 1, 5, 2 );

	QPushButton *pSetDefault    = new QPushButton( "De&fault", this );
	QPushButton *pApply         = new QPushButton( "A&pply", this );

	playoutGrid->addWidget( pSetDefault, 1, 1 );
    playoutGrid->addWidget( pApply, 1, 3 );

	// helpt text
	QFrame *pframe;
	pframe = new QFrame( this, "Frame_7" );
	pframe->setFrameStyle( QFrame::Box | QFrame::Raised );
	playoutTop->addWidget( pframe, 4 );

    playoutGrid = new QGridLayout( pframe, 1, 2, 5 );

	plabel1 = new QLabel( pframe, "Label_1" );
	plabel1->setGeometry( 20, 20, 32, 32 );
	plabel1->setPixmap( xpmAdvanced );
	plabel1->setMinimumSize( 32, 32 );
//	plabel1->setMaximumSize( 32, 32 );

	plabel2 = new QLabel( pframe, "Label_2" );
	plabel2->setText( "These options are global. As such, they can only be set by the system administrator or someone else with 'root' access. Turn Tracing on to enable logging of calls. Turn Pooling on to enable Driver Pooling options." );
#ifdef QT_V4LAYOUT
	plabel2->setAlignment( Qt::AlignLeft | Qt::WordBreak );
  	plabel2->setWordWrap( true );
#else
	plabel2->setAlignment( AlignLeft | WordBreak );
#endif

	playoutGrid->addWidget( plabel1, 0, 0 );
    playoutGrid->addWidget( plabel2, 0, 1 );
    playoutGrid->setColStretch( 1, 10 );


	// init values        
	char szTracing[10];
	char szForce[10];
	char szTracingFile[FILENAME_MAX];
	char szPooling[10];
	char szGUIPlugin[FILENAME_MAX];

	SQLGetPrivateProfileString( "ODBC", "Trace", "No", szTracing, sizeof(szTracing), "odbcinst.ini" );
	if ( szTracing[0] == '1' || toupper( szTracing[0] ) == 'Y' 
            || ( toupper( szTracing[0] ) == 'O' && toupper( szForce[0] ) == 'N' ))
		pTracing->setChecked( true );
		
	SQLGetPrivateProfileString( "ODBC", "ForceTrace", "No", szForce, sizeof(szForce), "odbcinst.ini" );
	if ( szForce[0] == '1' || toupper( szForce[0] ) == 'Y' 
            || ( toupper( szForce[0] ) == 'O' && toupper( szForce[0] ) == 'N' ))
		pForce->setChecked( true );
		
	SQLGetPrivateProfileString( "ODBC", "TraceFile", "/tmp/sql.log", szTracingFile, sizeof(szTracingFile)-1, "odbcinst.ini" );
	pTraceFile->pLineEdit->setText( szTracingFile );

	SQLGetPrivateProfileString( "ODBC", "Pooling", "No", szPooling, sizeof(szPooling), "odbcinst.ini" );
	if ( szPooling[0] == '1' || toupper( szPooling[0] ) == 'Y' 
            || ( toupper( szPooling[0] ) == 'O'  && toupper( szForce[0] ) == 'N' ))
		pPooling->setChecked( true );
		
	connect( pSetDefault, SIGNAL(clicked()), SLOT(setDefault()) );
	connect( pApply, SIGNAL(clicked()), SLOT(apply()) );
}
コード例 #25
0
void    ReformatOpenString(char * old_xa_info, char * new_xa_info, int bPasswords)
{
    char   xa_info_wkbuf[300];  /* hold the old_xa_info here as null-termed tokens */
    char   szVNODEbuf[64];
    char   szDATABASEbuf[64];
    char   szSERVERTYPEbuf[64];
    char * s;
    char * szDSN       =NULL;
    char * szDATABASE  =NULL;
    char * szVNODE     =NULL;
    char * szSERVERTYPE=NULL;
    char * szROLE      =NULL;
    char * szROLEPWD   =NULL;
    char * szUID       =NULL;
    char * szPWD       =NULL;
    char * szGROUP     =NULL;
    char * szOPTIONS   =NULL;
    char * key, * value;      /* pointers to key and value tokens in xa_info_wkbuf*/ 

    memset(xa_info_wkbuf,'\0',sizeof(xa_info_wkbuf));  /* clear background to '\0' */
    strcpy(xa_info_wkbuf,old_xa_info);  /* copy orig xa_info into token buffer */

    s=xa_info_wkbuf;
    while (*s)
       { s=GetKeywordAndValue(s,&key,&value);
         if (key==NULL)
            break;
         if      (strcmp(key,"DSN")==0)             szDSN       =value;
         else if (strcmp(key,"SERVER")==0)          szVNODE     =value;
         else if (strcmp(key,"DATABASE")==0)        szDATABASE  =value;
         else if (strcmp(key,"SERVERTYPE")==0)      szSERVERTYPE=value;
         else if (strcmp(key,"ROLE")==0)            szROLE      =value;
         else if (strcmp(key,"ROLEPWD")==0)         szROLEPWD   =value;
         else if (strcmp(key,"UID")==0)             szUID       =value;
         else if (strcmp(key,"PWD")==0)             szPWD       =value;
         else if (strcmp(key,"GROUP")==0)           szGROUP     =value;
         else if (strcmp(key,"OPTIONS")==0)         szOPTIONS   =value;
       }  /* end while loop */

    if (szDSN)
       { SQLGetPrivateProfileString (szDSN,"Server","",szVNODE=szVNODEbuf, 
                               sizeof(szVNODEbuf),ODBC_INI);
         SQLGetPrivateProfileString (szDSN,"Database","",szDATABASE=szDATABASEbuf, 
                               sizeof(szDATABASEbuf),ODBC_INI);
         SQLGetPrivateProfileString (szDSN,"ServerType","",szSERVERTYPE=szSERVERTYPEbuf, 
                               sizeof(szSERVERTYPEbuf),ODBC_INI);
       }

#ifdef CAIIODXA_PASSWORDS_ARE_ENCRYPTED
    if (szPWD)
		pwcrypt(szUID, szPWD);      /* decrpts the szPWD     */  
    if (szROLEPWD)
		pwcrypt(szROLE, szROLEPWD); /* decrpts the szROLEPWD */
#endif
        
    strcpy(new_xa_info, "INGRES ");  /* start building the new Ingres Open String */

    if (szVNODE  &&  *szVNODE  &&  stricmp(szVNODE,"(local)") != 0)
       {strcat(new_xa_info, szVNODE);
        strcat(new_xa_info, "::");
       }
    if (szDATABASE)
       {strcat(new_xa_info, szDATABASE);
       }
    if (szSERVERTYPE  &&  *szSERVERTYPE)
       {strcat(new_xa_info, "/");
        strcat(new_xa_info, szSERVERTYPE);
       }

    if (!szROLE  &&  !szROLEPWD  &&  !szUID  &&  !szPWD  &&  !szOPTIONS)
       return;   /* if no OPTIONS, all done! */

    strcat(new_xa_info, " options = ");

    if (szROLE)
       {strcat(new_xa_info,"'-R"); 
        strcat(new_xa_info, szROLE);
        if (szROLEPWD)
           {strcat(new_xa_info,"/");
            if (bPasswords)
               strcat(new_xa_info, szROLEPWD);
            else
               strcat(new_xa_info, "********");
           }
        strcat(new_xa_info,"' ");
       }

    if (szUID)
       {strcat(new_xa_info,"'-u"); 
        strcat(new_xa_info, szUID);
        if (szPWD)
           {strcat(new_xa_info,"/");
            if (bPasswords)
               strcat(new_xa_info, szPWD);
            else
               strcat(new_xa_info, "********");
           }
        strcat(new_xa_info,"' ");
       }

    if (szGROUP)
       {strcat(new_xa_info,"'-G"); 
        strcat(new_xa_info, szGROUP);
        strcat(new_xa_info,"' ");
       }

    if (szOPTIONS)
       {if (*szOPTIONS!='\''  &&  *szOPTIONS!='\"')   /* don't wrap in quotes if already quoted */
           strcat(new_xa_info,"'"); 
        strcat(new_xa_info, szOPTIONS);
        if (*szOPTIONS!='\''  &&  *szOPTIONS!='\"')
           strcat(new_xa_info,"' ");
       }

    return;
}
コード例 #26
0
static void
ParseOptions (CfgData cfgdata[], TCHAR * s, int clean_up)
{
  TCHAR *cp, *n;
  TCHAR *section;
  int count;
  int i;

  if (clean_up)
    for (i = 0; i < sizeof (attrs) / sizeof (attrs[0]); i++)
      {
	if (cfgdata[i].data)
	  free (cfgdata[i].data);
	cfgdata[i].data = NULL;
	cfgdata[i].supplied = FALSE;
      }

  if (s == NULL)
    return;

  for (count = 0; *s; count++)
    {
      for (cp = s; *cp && *cp != ';'; cp++)
	;
      if (*cp)
	{
	  *cp = 0;
	  n = cp + 1;
	}
      else
	n = cp;
      for (cp = s; *cp && *cp != '='; cp++)
	;
      if (*cp)
	{
	  *cp++ = 0;
	  if (_tcsicmp (s, attrs[oDATABASE].shortName) || _tcsicmp (cp, DEFAULT_DATABASE_PER_USER))
	    for (i = 0; i < sizeof (attrs) / sizeof (attrs[0]); i++)
	      {
		if (attrs[i].shortName && !_tcsicmp (attrs[i].shortName, s))
		  {
		    cfgdata[i].data = _tcsdup (cp);
		    cfgdata[i].supplied = TRUE;
		    break;
		  }
	      }
	}
      /*
       *  Handle missing DSN=... from the beginning:
       *  'dsn_ora7;UID=scott;PWD=tiger'
       */
      else if (count == 0)
	{
	  cfgdata[oDSN].data = _tcsdup (s);
	  cfgdata[oDSN].supplied = TRUE;
	}
      s = n;
    }

  section = cfgdata[oDSN].data;

  if (section == NULL || !section[0])
    section = _T ("Default");

#if defined (DSN_TRANSLATION) && !defined (WIN32)
  {
    PCONFIG pConfig, cfg_odbc_sys, cfg_odbc_usr;
    char *odbcini_sys, *odbcini_usr, *ptr;
    char path[1024];
    char *long_name, *section_narrow;
    TCHAR *valueW;

    /*
     *  1a. Find out where system odbc.ini resides
     */
    if ((odbcini_sys = getenv ("ODBCINI")) == NULL || access (odbcini_sys, R_OK))
      odbcini_sys = "/etc/odbc.ini";

    /*
     *  1b. The default system odbc.ini on Mac OS X is located in
     *      /Library/ODBC/odbc.ini
     */
#ifdef __APPLE__
    if (access (odbcini_sys, R_OK) != 0)
      odbcini_sys = "/Library/ODBC/odbc.ini";
#endif

    /*
     *  1c. Open system odbc.ini
     */
    cfg_init (&cfg_odbc_sys, odbcini_sys);


    /*
     *  2a. Find out where user odbc.ini resides
     */
    if ((ptr = getenv ("HOME")) == NULL)
      {
	ptr = (char *) getpwuid (getuid ());

	if (ptr != NULL)
	  ptr = ((struct passwd *) ptr)->pw_dir;
      }

    if (ptr != NULL)
      snprintf (path, sizeof (path), "%.200s/.odbc.ini", ptr);
    else
      snprintf (path, sizeof (path), ".odbc.ini");

    /*
     *  2b. The default user odbc.ini on Mac OS X is located in
     *      ~/Library/ODBC/odbc.ini
     */
#ifdef __APPLE__
    if (access (path, R_OK) != 0)
      {
	snprintf (path, sizeof (path), "%.200s/Library/ODBC/odbc.ini", ptr ? ptr : "");
      }
#endif

    /*
     *  2c. Open user odbc.ini
     */
    odbcini_usr = path;
    cfg_init (&cfg_odbc_usr, odbcini_usr);

    cli_dbg_printf (("USING %s\n", odbcini_usr));

    section_narrow = virt_wide_to_ansi (section);

    /*
     *  Check where DSN is registered
     */
    if (cfg_find (cfg_odbc_usr, section_narrow, NULL) == 0)
      pConfig = cfg_odbc_usr;
    else
      pConfig = cfg_odbc_sys;
#endif

    for (i = 0; i < sizeof (attrs) / sizeof (attrs[0]); i++)
      if (!cfgdata[i].supplied && attrs[i].longName)
	{
	  if ((cfgdata[i].data = (TCHAR *) malloc ((attrs[i].maxLength + 1) * sizeof (TCHAR))) == NULL)
	    break;
#ifdef DSN_TRANSLATION
# ifdef WIN32
	  SQLGetPrivateProfileString (section, attrs[i].longName, _T (""), cfgdata[i].data, attrs[i].maxLength, _T ("odbc.ini"));
# else
	  valueW = NULL;
	  long_name = virt_wide_to_ansi (attrs[i].longName);
	  if (cfg_find (pConfig, section_narrow, long_name) == -1)
	    valueW = attrs[i].defVal;
	  else
	    valueW = virt_ansi_to_wide (pConfig->value);
	  free_wide_buffer (long_name);
	  _tcsncpy (cfgdata[i].data, valueW, attrs[i].maxLength);
	  cfgdata[i].data[attrs[i].maxLength] = 0;
	  if (valueW != attrs[i].defVal)
	    free_wide_buffer (valueW);
# endif
#else
	  _tcsncpy (cfgdata[i].data, _T (""), attrs[i].maxLength);
#endif
	}

#if defined (DSN_TRANSLATION) && !defined (WIN32)
    cfg_done (cfg_odbc_usr);
    cfg_done (cfg_odbc_sys);
    free_wide_buffer (section_narrow);
  }
#endif
}
コード例 #27
0
ファイル: __handles.c プロジェクト: Azure/unixODBC-MSSQL
DMHENV __alloc_env( void )
{
    DMHENV environment = NULL;

    mutex_entry( &mutex_lists );

    environment = calloc( sizeof( *environment ), 1 );

    if ( environment )
    {
        char tracing_string[ 64 ];
        char tracing_file[ 64 ];

#if defined ( COLLECT_STATS ) && defined( HAVE_SYS_SEM_H )
        if (uodbc_open_stats(&environment->sh, UODBC_STATS_WRITE) != 0)
        {
            ;
        }
        uodbc_update_stats(environment->sh, UODBC_STATS_TYPE_HENV, (void *)1);
#endif
        
        /*
         * add to list of env handles
         */

        environment -> next_class_list = enviroment_root;
        enviroment_root = environment;
        environment -> type = HENV_MAGIC;

        SQLGetPrivateProfileString( "ODBC", "Trace", "No",
                    tracing_string, sizeof( tracing_string ), 
                    "odbcinst.ini" );

        if ( tracing_string[ 0 ] == '1' ||
                toupper( tracing_string[ 0 ] ) == 'Y' ||
                    ( toupper( tracing_string[ 0 ] ) == 'O' &&
                    toupper( tracing_string[ 1 ] ) == 'N' ))
        {
            SQLGetPrivateProfileString( "ODBC", "TraceFile", "/tmp/sql.log",
                    tracing_file, sizeof( tracing_file ), 
                    "odbcinst.ini" );

            /*
             * start logging
             */

            SQLGetPrivateProfileString( "ODBC", "TracePid", "No",
                    tracing_string, sizeof( tracing_string ), 
                    "odbcinst.ini" );

            if ( tracing_string[ 0 ] == '1' ||
                        toupper( tracing_string[ 0 ] ) == 'Y' ||
                        ( toupper( tracing_string[ 0 ] ) == 'O' &&
                        toupper( tracing_string[ 1 ] ) == 'N' ))
            {
                dm_log_open( "ODBC", tracing_file, 1 );
            }
            else
            {
                dm_log_open( "ODBC", tracing_file, 0 );
            }

            sprintf( environment -> msg,
                    "\n\t\tExit:[SQL_SUCCESS]\n\t\t\tEnvironment = %p",	environment );

            dm_log_write( __FILE__,
                    __LINE__,
                    LOG_INFO,
                    LOG_INFO, environment -> msg );
        }
    }

    setup_error_head( &environment -> error, environment,
            SQL_HANDLE_ENV );

    mutex_exit( &mutex_lists );

    return environment;
}
コード例 #28
0
ファイル: dlg_specific.c プロジェクト: greenplum-db/gpclients
void
getDSNinfo(ConnInfo *ci, char overwrite)
{
	CSTR	func = "getDSNinfo";
	char	   *DSN = ci->dsn;
	char		encoded_item[LARGE_REGISTRY_LEN],
				temp[SMALL_REGISTRY_LEN];

/*
 *	If a driver keyword was present, then dont use a DSN and return.
 *	If DSN is null and no driver, then use the default datasource.
 */
	mylog("%s: DSN=%s overwrite=%d\n", func, DSN, overwrite);
	if (DSN[0] == '\0')
	{
		if (ci->drivername[0] != '\0')
			return;
		else
			strncpy_null(DSN, INI_DSN, sizeof(ci->dsn));
	}

	/* brute-force chop off trailing blanks... */
	while (*(DSN + strlen(DSN) - 1) == ' ')
		*(DSN + strlen(DSN) - 1) = '\0';

	if (ci->drivername[0] == '\0' || overwrite)
	{
		getDriverNameFromDSN(DSN, ci->drivername, sizeof(ci->drivername));
		if (ci->drivername[0] && stricmp(ci->drivername, DBMS_NAME))
			getCommonDefaults(ci->drivername, ODBCINST_INI, ci);
	}

	/* Proceed with getting info for the given DSN. */

	if (ci->desc[0] == '\0' || overwrite)
		SQLGetPrivateProfileString(DSN, INI_KDESC, "", ci->desc, sizeof(ci->desc), ODBC_INI);

	if (ci->server[0] == '\0' || overwrite)
		SQLGetPrivateProfileString(DSN, INI_SERVER, "", ci->server, sizeof(ci->server), ODBC_INI);

	if (ci->database[0] == '\0' || overwrite)
		SQLGetPrivateProfileString(DSN, INI_DATABASE, "", ci->database, sizeof(ci->database), ODBC_INI);

	if (ci->username[0] == '\0' || overwrite)
		SQLGetPrivateProfileString(DSN, INI_USERNAME, "", ci->username, sizeof(ci->username), ODBC_INI);

	if (ci->password[0] == '\0' || overwrite)
	{
		SQLGetPrivateProfileString(DSN, INI_PASSWORD, "", encoded_item, sizeof(encoded_item), ODBC_INI);
		decode(encoded_item, ci->password, sizeof(ci->password));
	}

	if (ci->port[0] == '\0' || overwrite)
		SQLGetPrivateProfileString(DSN, INI_PORT, "", ci->port, sizeof(ci->port), ODBC_INI);

	if (ci->onlyread[0] == '\0' || overwrite)
		SQLGetPrivateProfileString(DSN, INI_READONLY, "", ci->onlyread, sizeof(ci->onlyread), ODBC_INI);

	if (ci->show_oid_column[0] == '\0' || overwrite)
		SQLGetPrivateProfileString(DSN, INI_SHOWOIDCOLUMN, "", ci->show_oid_column, sizeof(ci->show_oid_column), ODBC_INI);

	if (ci->fake_oid_index[0] == '\0' || overwrite)
		SQLGetPrivateProfileString(DSN, INI_FAKEOIDINDEX, "", ci->fake_oid_index, sizeof(ci->fake_oid_index), ODBC_INI);

	if (ci->row_versioning[0] == '\0' || overwrite)
		SQLGetPrivateProfileString(DSN, INI_ROWVERSIONING, "", ci->row_versioning, sizeof(ci->row_versioning), ODBC_INI);

	if (ci->show_system_tables[0] == '\0' || overwrite)
		SQLGetPrivateProfileString(DSN, INI_SHOWSYSTEMTABLES, "", ci->show_system_tables, sizeof(ci->show_system_tables), ODBC_INI);

	if (ci->protocol[0] == '\0' || overwrite)
	{
		char	*ptr;
		SQLGetPrivateProfileString(DSN, INI_PROTOCOL, "", ci->protocol, sizeof(ci->protocol), ODBC_INI);
		if (ptr = strchr(ci->protocol, '-'), NULL != ptr)
		{
			*ptr = '\0';
			if (overwrite || ci->rollback_on_error < 0)
			{
				ci->rollback_on_error = atoi(ptr + 1);
				mylog("rollback_on_error=%d\n", ci->rollback_on_error);
			}
		}
	}

	if (ci->conn_settings[0] == '\0' || overwrite)
	{
		SQLGetPrivateProfileString(DSN, INI_CONNSETTINGS, "", encoded_item, sizeof(encoded_item), ODBC_INI);
		decode(encoded_item, ci->conn_settings, sizeof(ci->conn_settings));
	}

	if (ci->translation_dll[0] == '\0' || overwrite)
		SQLGetPrivateProfileString(DSN, INI_TRANSLATIONDLL, "", ci->translation_dll, sizeof(ci->translation_dll), ODBC_INI);

	if (ci->translation_option[0] == '\0' || overwrite)
		SQLGetPrivateProfileString(DSN, INI_TRANSLATIONOPTION, "", ci->translation_option, sizeof(ci->translation_option), ODBC_INI);

	if (ci->disallow_premature < 0 || overwrite)
	{
		SQLGetPrivateProfileString(DSN, INI_DISALLOWPREMATURE, "", temp, sizeof(temp), ODBC_INI);
		if (temp[0])
			ci->disallow_premature = atoi(temp);
	}

	if (ci->allow_keyset < 0 || overwrite)
	{
		SQLGetPrivateProfileString(DSN, INI_UPDATABLECURSORS, "", temp, sizeof(temp), ODBC_INI);
		if (temp[0])
			ci->allow_keyset = atoi(temp);
	}

	if (ci->lf_conversion < 0 || overwrite)
	{
		SQLGetPrivateProfileString(DSN, INI_LFCONVERSION, "", temp, sizeof(temp), ODBC_INI);
		if (temp[0])
			ci->lf_conversion = atoi(temp);
	}

	if (ci->true_is_minus1 < 0 || overwrite)
	{
		SQLGetPrivateProfileString(DSN, INI_TRUEISMINUS1, "", temp, sizeof(temp), ODBC_INI);
		if (temp[0])
			ci->true_is_minus1 = atoi(temp);
	}

	if (ci->int8_as < -100 || overwrite)
	{
		SQLGetPrivateProfileString(DSN, INI_INT8AS, "", temp, sizeof(temp), ODBC_INI);
		if (temp[0])
			ci->int8_as = atoi(temp);
	}

	if (ci->bytea_as_longvarbinary < 0 || overwrite)
	{
		SQLGetPrivateProfileString(DSN, INI_BYTEAASLONGVARBINARY, "", temp, sizeof(temp), ODBC_INI);
		if (temp[0])
			ci->bytea_as_longvarbinary = atoi(temp);
	}

	if (ci->use_server_side_prepare < 0 || overwrite)
	{
		SQLGetPrivateProfileString(DSN, INI_USESERVERSIDEPREPARE, "", temp, sizeof(temp), ODBC_INI);
		if (temp[0])
			ci->use_server_side_prepare = atoi(temp);
	}

	if (ci->lower_case_identifier < 0 || overwrite)
	{
		SQLGetPrivateProfileString(DSN, INI_LOWERCASEIDENTIFIER, "", temp, sizeof(temp), ODBC_INI);
		if (temp[0])
			ci->lower_case_identifier = atoi(temp);
	}

	if (ci->greenplum < 0 || overwrite)
	{
		SQLGetPrivateProfileString(DSN, INI_GREENPLUM, "", temp, sizeof(temp), ODBC_INI);
		if (temp[0])
			ci->greenplum = atoi(temp);
	}

	if (ci->gssauth_use_gssapi < 0 || overwrite)
	{
		SQLGetPrivateProfileString(DSN, INI_GSSAUTHUSEGSSAPI, "", temp, sizeof(temp), ODBC_INI);
		if (temp[0])
			ci->gssauth_use_gssapi = atoi(temp);
	}

	if (ci->sslmode[0] == '\0' || overwrite)
		SQLGetPrivateProfileString(DSN, INI_SSLMODE, "", ci->sslmode, sizeof(ci->sslmode), ODBC_INI);

#ifdef	_HANDLE_ENLIST_IN_DTC_
	if (ci->xa_opt < 0 || overwrite)
	{
		SQLGetPrivateProfileString(DSN, INI_XAOPT, "", temp, sizeof(temp), ODBC_INI);
		if (temp[0])
			ci->xa_opt = atoi(temp);
	}
#endif /* _HANDLE_ENLIST_IN_DTC_ */

	/* Force abbrev connstr or bde */
	SQLGetPrivateProfileString(DSN, INI_EXTRAOPTIONS, "",
					temp, sizeof(temp), ODBC_INI);
	if (temp[0])
	{
		UInt4	val = 0;

		sscanf(temp, "%x", &val);
		replaceExtraOptions(ci, val, overwrite);
		mylog("force_abbrev=%d bde=%d cvt_null_date=%d\n", ci->force_abbrev_connstr, ci->bde_environment, ci->cvt_null_date_string);
	}

	/* Allow override of odbcinst.ini parameters here */
	getCommonDefaults(DSN, ODBC_INI, ci);

	qlog("DSN info: DSN='%s',server='%s',port='%s',dbase='%s',user='******',passwd='%s'\n",
		 DSN,
		 ci->server,
		 ci->port,
		 ci->database,
		 ci->username,
		 ci->password ? "xxxxx" : "");
	qlog("          onlyread='%s',protocol='%s',showoid='%s',fakeoidindex='%s',showsystable='%s'\n",
		 ci->onlyread,
		 ci->protocol,
		 ci->show_oid_column,
		 ci->fake_oid_index,
		 ci->show_system_tables);

	if (get_qlog())
	{
		char	*enc = (char *) check_client_encoding(ci->conn_settings);

		qlog("          conn_settings='%s', conn_encoding='%s'\n", ci->conn_settings,
			NULL != enc ? enc : "(null)");
		if (NULL != enc)
			free(enc);
		qlog("          translation_dll='%s',translation_option='%s'\n",
		 	ci->translation_dll,
		 	ci->translation_option);
	}
}
コード例 #29
0
ファイル: __connection.c プロジェクト: ystk/debian-unixodbc
char *__find_lib_name( char *dsn, char *lib_name, char *driver_name )
{
    char driver[ INI_MAX_PROPERTY_VALUE + 1 ];
    char driver_lib[ INI_MAX_PROPERTY_VALUE + 1 ];

    SQLSetConfigMode( ODBC_USER_DSN );

	/*
	 * GET DRIVER FROM ODBC.INI
	 */

    SQLGetPrivateProfileString( dsn, "Driver", "",
            driver_lib, sizeof( driver_lib ), "ODBC.INI" );

    if ( driver_lib[ 0 ] == 0 )
    {
        /*
         * if not found look in system DSN
         */

        SQLSetConfigMode( ODBC_SYSTEM_DSN );

        SQLGetPrivateProfileString( dsn, "Driver", "",
                driver_lib, sizeof( driver_lib ), "ODBC.INI" );
        
        SQLSetConfigMode( ODBC_BOTH_DSN );
        if ( driver_lib[ 0 ] == 0 )
            return NULL;
    }

	/*
	 * GET DRIVER FROM ODBCINST.INI IF ODBC.INI HAD USER FRIENDLY NAME
	 */

    strcpy( driver_name, "" );

    if ( driver_lib[ 0 ] != '/' )
	{
        strcpy( driver, driver_lib );

		/*
		 * allow the use of "User odbcinst files
		 */

#ifdef PLATFORM64
		SQLGetPrivateProfileString( driver, "Driver64", "",
				driver_lib, sizeof( driver_lib ), "ODBCINST.INI" );

		if ( driver_lib[ 0 ] == '\0' )
		{
			SQLGetPrivateProfileString( driver, "Driver", "",
					driver_lib, sizeof( driver_lib ), "ODBCINST.INI" );
		}
#else
		SQLGetPrivateProfileString( driver, "Driver", "",
				driver_lib, sizeof( driver_lib ), "ODBCINST.INI" );
#endif

                strcpy( driver_name, driver );

		if ( driver_lib[ 0 ] == 0 ) {
		    return NULL;
		}
	}

	strcpy( lib_name, driver_lib );

    return lib_name;
}
コード例 #30
0
ファイル: SQLBrowseConnect.c プロジェクト: f7753/monetdb
static SQLRETURN
MNDBBrowseConnect(ODBCDbc *dbc,
		  SQLCHAR *InConnectionString,
		  SQLSMALLINT StringLength1,
		  SQLCHAR *OutConnectionString,
		  SQLSMALLINT BufferLength,
		  SQLSMALLINT *StringLength2Ptr)
{
	char *key, *attr;
	char *dsn, *uid, *pwd, *host, *dbname;
	int port;
	SQLSMALLINT len = 0;
	char buf[256];
	int n;
	SQLRETURN rc;
#ifdef ODBCDEBUG
	int allocated = 0;
#endif

	fixODBCstring(InConnectionString, StringLength1, SQLSMALLINT, addDbcError, dbc, return SQL_ERROR);

#ifdef ODBCDEBUG
	ODBCLOG(" \"%.*s\"\n", (int) StringLength1, (char*) InConnectionString);
#endif

	/* check connection state, should not be connected */
	if (dbc->Connected) {
		/* Connection name in use */
		addDbcError(dbc, "08002", NULL, 0);
		return SQL_ERROR;
	}

	dsn = dbc->dsn ? strdup(dbc->dsn) : NULL;
	uid = dbc->uid ? strdup(dbc->uid) : NULL;
	pwd = dbc->pwd ? strdup(dbc->pwd) : NULL;
	host = dbc->host ? strdup(dbc->host) : NULL;
	port = dbc->port;
	dbname = dbc->dbname ? strdup(dbc->dbname) : NULL;

	while ((n = ODBCGetKeyAttr(&InConnectionString, &StringLength1, &key, &attr)) > 0) {
		if (strcasecmp(key, "dsn") == 0 && dsn == NULL) {
			if (dsn)
				free(dsn);
			dsn = attr;
		} else if (strcasecmp(key, "uid") == 0 && uid == NULL) {
			if (uid)
				free(uid);
			uid = attr;
		} else if (strcasecmp(key, "pwd") == 0 && pwd == NULL) {
			if (pwd)
				free(pwd);
			pwd = attr;
		} else if (strcasecmp(key, "host") == 0 && host == NULL) {
			if (host)
				free(host);
			host = attr;
		} else if (strcasecmp(key, "port") == 0 && port == 0) {
			port = atoi(attr);
			free(attr);
		} else if (strcasecmp(key, "database") == 0 && dbname == NULL) {
			if (dbname)
				free(dbname);
			dbname = attr;
#ifdef ODBCDEBUG
		} else if (strcasecmp(key, "logfile") == 0 &&
			   getenv("ODBCDEBUG") == NULL) {
			/* environment trumps everything */
			if (ODBCdebug)
				free((void *) ODBCdebug); /* discard const */
			ODBCdebug = attr;
			allocated = 1;
#endif
		} else
			free(attr);
		free(key);
	}
	if (n < 0)
		goto nomem;

	if (dsn) {
		if (uid == NULL) {
			n = SQLGetPrivateProfileString(dsn, "uid", "", buf, sizeof(buf), "odbc.ini");
			if (n > 0 && buf[0]) {
				uid = strdup(buf);
				if (uid == NULL)
					goto nomem;
			}
		}
		if (pwd == NULL) {
			n = SQLGetPrivateProfileString(dsn, "pwd", "", buf, sizeof(buf), "odbc.ini");
			if (n > 0 && buf[0]) {
				pwd = strdup(buf);
				if (pwd == NULL)
					goto nomem;
			}
		}
		if (host == NULL) {
			n = SQLGetPrivateProfileString(dsn, "host", "", buf, sizeof(buf), "odbc.ini");
			if (n > 0 && buf[0]) {
				host = strdup(buf);
				if (host == NULL)
					goto nomem;
			}
		}
		if (port == 0) {
			n = SQLGetPrivateProfileString(dsn, "port", "", buf, sizeof(buf), "odbc.ini");
			if (n > 0 && buf[0]) {
				port = atoi(buf);
			}
		}
		if (dbname == NULL) {
			n = SQLGetPrivateProfileString(dsn, "database", "", buf, sizeof(buf), "odbc.ini");
			if (n > 0 && buf[0]) {
				dbname = strdup(buf);
				if (dbname == NULL)
					goto nomem;
			}
		}
#ifdef ODBCDEBUG
		if (!allocated && getenv("ODBCDEBUG") == NULL) {
			/* if not set from InConnectionString argument
			 * or environment, look in profile */
			n = SQLGetPrivateProfileString(dsn, "logfile", "", buf, sizeof(buf), "odbc.ini");
			if (n > 0 && buf[0])
				ODBCdebug = strdup(buf);
		}
#endif
	}

	if (uid != NULL && pwd != NULL) {
		rc = MNDBConnect(dbc, (SQLCHAR *) dsn, SQL_NTS, (SQLCHAR *) uid, SQL_NTS, (SQLCHAR *) pwd, SQL_NTS, host, port, dbname);
		if (SQL_SUCCEEDED(rc)) {
			rc = ODBCConnectionString(rc, dbc, OutConnectionString,
						  BufferLength,
						  StringLength2Ptr,
						  dsn, uid, pwd, host, port,
						  dbname);
		}
	} else {
		if (uid == NULL) {
			if (BufferLength > 0)
				strncpy((char *) OutConnectionString, "UID:Login ID=?;", BufferLength);
			len += 15;
			OutConnectionString += 15;
			BufferLength -= 15;
		}
		if (pwd == NULL) {
			if (BufferLength > 0)
				strncpy((char *) OutConnectionString, "PWD:Password=?;", BufferLength);
			len += 15;
			OutConnectionString += 15;
			BufferLength -= 15;
		}
		if (host == NULL) {
			if (BufferLength > 0)
				strncpy((char *) OutConnectionString, "*HOST:Server=?;", BufferLength);
			len += 15;
			OutConnectionString += 15;
			BufferLength -= 15;
		}
		if (port == 0) {
			if (BufferLength > 0)
				strncpy((char *) OutConnectionString, "*PORT:Port=?;", BufferLength);
			len += 13;
			OutConnectionString += 13;
			BufferLength -= 13;
		}
		if (dbname == NULL) {
			if (BufferLength > 0)
				strncpy((char *) OutConnectionString, "*DATABASE:Database=?;", BufferLength);
			len += 21;
			OutConnectionString += 21;
			BufferLength -= 21;
		}
#ifdef ODBCDEBUG
		if (ODBCdebug == NULL) {
			if (BufferLength > 0)
				strncpy((char *) OutConnectionString, "*LOGFILE:Debug log file=?;", BufferLength);
			len += 26;
			OutConnectionString += 26;
			BufferLength -= 26;
		}
#endif

		if (StringLength2Ptr)
			*StringLength2Ptr = len;

		rc = SQL_NEED_DATA;
	}

  bailout:
	if (dsn)
		free(dsn);
	if (uid)
		free(uid);
	if (pwd)
		free(pwd);
	if (host)
		free(host);
	if (dbname)
		free(dbname);
	return rc;

  nomem:
	/* Memory allocation error */
	addDbcError(dbc, "HY001", NULL, 0);
	rc = SQL_ERROR;
	goto bailout;
}