sqldata/sqlapibase.cpp
// Split connection string to user, password and database
Split connection string to user, password and database
Split connection string to user password and database
void SqlApiBase::SplitConnectionString(const char *conn, std::string &user, std::string &pwd, std::string &db)
{
	if(conn == NULL)
		return;
	const char *amp = strchr(conn, '@');
	const char *sl = strchr(conn, '/');
	if(amp != NULL)
	{
		db = amp + 1; 
		const char *cur = amp;
		while(cur != NULL)
		{
			cur = strchr(cur + 1, '@');
			if(cur != NULL)
			{
				amp = cur;
				db = amp + 1; 
			}
		}
	}
	if(amp == NULL)
		amp = conn + strlen(conn);
	const char *end = (sl == NULL || amp < sl) ? amp : sl;
	user.assign(conn, (size_t)(end - conn));
	if(sl != NULL && amp > sl)
	{
		pwd.assign(sl + 1, (size_t)(amp - sl - 1));
	}
}
void SqlApiBase :: SplitConnectionString ( const char * conn , std :: string & user , std :: string & pwd , std :: string & db ) { if ( conn == NULL ) return ; const char * amp = strchr ( conn , ' ' ) ; const char * sl = strchr ( conn , ' ' ) ; if ( amp != NULL ) { db = amp + 1 ; const char * cur = amp ; while ( cur != NULL ) { cur = strchr ( cur + 1 , ' ' ) ; if ( cur != NULL ) { amp = cur ; db = amp + 1 ; } } } if ( amp == NULL ) amp = conn + strlen ( conn ) ; const char * end = ( sl == NULL || amp < sl ) ? amp : sl ; user . assign ( conn , ( size_t ) ( end - conn ) ) ; if ( sl != NULL && amp > sl ) { pwd . assign ( sl + 1 , ( size_t ) ( amp - sl - 1 ) ) ; } }
Split connection string to user, password and database
Split connection string to user password and database
// Find @ that separates user/password from server name // Set database info // @ can be used in password, so find the latest @ // Define the end of the user name // Define password