void
TableMakerAdvProperties::InitCollationCombo()
{
    MDIWindow   *wnd = GetActiveWin();
    wyString    query, collationstr;
    MYSQL_ROW   myrow;
    MYSQL_RES   *myres;
    wyInt32     index;

    HWND        hwndcombo = GetDlgItem(m_hwnd, IDC_TABCOLLATION);

    query.SetAs("show collation");
    myres = ExecuteAndGetResult(wnd, wnd->m_tunnel, &wnd->m_mysql, query);
    if(!myres)
    {
        ShowMySQLError(m_hwnd, wnd->m_tunnel, &wnd->m_mysql, query.GetString());
        return;
    }
    while(myrow = wnd->m_tunnel->mysql_fetch_row(myres))
    {
        collationstr.SetAs(myrow[0]);
        SendMessage(hwndcombo , CB_ADDSTRING, 0,(LPARAM)collationstr.GetAsWideChar());
    }
    if((index = SendMessage(hwndcombo , CB_ADDSTRING, 0,(LPARAM)TEXT(STR_DEFAULT))) != CB_ERR)
        index = SendMessage(hwndcombo, CB_SETCURSEL, index, (LPARAM)TEXT(STR_DEFAULT));
}
void
TableMakerAdvProperties::ReInitRelatedCollations(HWND hwnd, wyWChar *charsetname)
{
    MDIWindow	*pcquerywnd = GetActiveWin();
    MYSQL_RES   *myres;
    MYSQL_ROW   myrow;
    wyWChar     *relcollation  = NULL;
    wyString    query, collationstr;
    wyInt32     ret, selcharsetlen  = 0;

    HWND    hwndcombo = GetDlgItem(hwnd, IDC_TABCOLLATION);

    query.SetAs("show collation");
    myres = ExecuteAndGetResult(pcquerywnd, pcquerywnd->m_tunnel, &pcquerywnd->m_mysql, query);
    if(!myres)
    {
        ShowMySQLError(hwnd, pcquerywnd->m_tunnel, &pcquerywnd->m_mysql, query.GetString());
        return;
    }

    VERIFY((hwndcombo, CB_RESETCONTENT, 0, 0));

    if(charsetname)
        selcharsetlen = wcslen(charsetname);

    while(myrow = pcquerywnd->m_tunnel->mysql_fetch_row(myres))
    {
        collationstr.SetAs(myrow[0]);
        ret = SendMessage(hwndcombo, CB_FINDSTRINGEXACT, -1,(LPARAM)collationstr.GetAsWideChar());
        if(ret != CB_ERR)
        {
            //delete the items which are not relevent
            if(wcsstr(collationstr.GetAsWideChar(), charsetname) == NULL)
                SendMessage(hwndcombo, CB_DELETESTRING, ret, 0);
        }
        else if((relcollation = wcsstr(collationstr.GetAsWideChar(), charsetname)) != NULL)
        {
            // Add the relevent items
            if(collationstr.GetCharAt(selcharsetlen) == '_')
                SendMessage(hwndcombo, CB_ADDSTRING, 0, (LPARAM)collationstr.GetAsWideChar());
        }
    }
    pcquerywnd->m_tunnel->mysql_free_result(myres);
    SendMessage(hwndcombo, CB_SETCURSEL, (WPARAM)0, 0);
}
Exemplo n.º 3
0
//Getting databases from MySQL by executing show databases query
wyInt32  
DBListBuilder::GetDBFromServers(HWND hwnd, LPARAM lparam)
{
	HWND            hwndcombo;
	wyInt32         ret;
	MDIWindow		*pcquerywnd=NULL, *wnd=NULL;
	wyWChar         classname[SIZE_512] = {0};
	wyString        dbname, findvalue;
	LPDIFFCOMBOITEM	pdiffcombo = NULL;

	MYSQL_RES			*myres=NULL;
	MYSQL_ROW			myrow;
	wyString            query, database;

    hwndcombo =(HWND)lparam;
	
	VERIFY(GetClassName(hwnd, classname, SIZE_512 - 1));

	VERIFY(wnd = GetActiveWin());

	SetCursor(LoadCursor(NULL, IDC_WAIT));

	if((wcscmp(classname, QUERY_WINDOW_CLASS_NAME_STR)== 0))
    {
		VERIFY(pcquerywnd = (MDIWindow*)GetWindowLongPtr(hwnd, GWLP_USERDATA));
			
		// execute query to get all the database names.
		query.Sprintf("show databases");
        myres = ExecuteAndGetResult(pcquerywnd, pcquerywnd->m_tunnel, &pcquerywnd->m_mysql, query);

		if(!myres)
		{
			ShowMySQLError(hwnd, pcquerywnd->m_tunnel, &pcquerywnd->m_mysql, query.GetString());
			goto cleanup;
		}
		
		while(myrow = pcquerywnd->m_tunnel->mysql_fetch_row(myres))	
		{
			database.SetAs(myrow[0]);
			dbname.SetAs(database);
			/* starting from 4.1 BETA 4 we use connection name for unique values */
			findvalue.Sprintf("%s - %s", pcquerywnd->m_title.GetString(), dbname.GetString());

			// find it. if not found add it.
			ret = SendMessage(hwndcombo, CB_FINDSTRINGEXACT, -1,(LPARAM)findvalue.GetAsWideChar());

			if(ret == CB_ERR)
            {
				ret = SendMessage(hwndcombo, CB_ADDSTRING, 0,(LPARAM)findvalue.GetAsWideChar());

				pdiffcombo = new DIFFCOMBOITEM;
				
				//wcscpy(pdiffcombo->szDB, database.GetAsWideChar());
				wcsncpy(pdiffcombo->szDB, database.GetAsWideChar(), SIZE_128 - 1);
				pdiffcombo->szDB[SIZE_128 - 1] = '\0';
                
				pdiffcombo->wnd = pcquerywnd;
				
				pdiffcombo->mysql = &pcquerywnd->m_mysql;
				pdiffcombo->tunnel = pcquerywnd->m_tunnel;
				pdiffcombo->info = &pcquerywnd->m_conninfo;

				SendMessage(hwndcombo, CB_SETITEMDATA, ret, (LPARAM)pdiffcombo);
			}
		}

		pcquerywnd->m_tunnel->mysql_free_result(myres);
	}

	SetCursor(LoadCursor(NULL, IDC_ARROW));
	return wyTrue;

cleanup:
		SetCursor(LoadCursor(NULL, IDC_ARROW));
		return wyFalse;	
}