Exemplo n.º 1
0
//----------------------------------------------------------------------------------------
bool BrowserDB::OnCloseDB(int Quiet)
{
    if (!Quiet)
        wxLogMessage(_("-I-> BrowserDB::OnCloseDB() : Begin "));
    if (db_BrowserDB)
    {
//        db_BrowserDB->Close();
        wxDbFreeConnection(db_BrowserDB);

        DbConnectInf.FreeHenv();

        db_BrowserDB = NULL;
    }
    if (!Quiet)
        wxLogMessage(_("\n-I-> BrowserDB::OnCloseDB() : End "));
    return true;
}
Exemplo n.º 2
0
Arquivo: doc.cpp Projeto: EdgarTx/wx
//----------------------------------------------------------------------------------------
bool MainDoc::OnInitODBC()
{
    wxChar Dsn[SQL_MAX_DSN_LENGTH+1];
    wxChar DsDesc[254+1]; // BJO20002501 instead of 512
    Temp0 = wxEmptyString;
    i_DSN = 0;       // Counter
    int i;
    //---------------------------------------------------------------------------------------
    // Initialize the ODBC Environment for Database Operations

    if (!DbConnectInf.AllocHenv())
    {
        return false;
    }

    //---------------------------------------------------------------------------------------
    const wxChar sep = 3; // separator character used in string between DSN and DsDesc
    wxSortedArrayString s_SortDSNList, s_SortDsDescList;
    // BJO-20000127
    // In order to have same sort result on both Dsn and DsDesc, create a 'keyed' string.
    // The key will be removed after sorting
    wxString KeyString;
    //---------------------------------------------------------------------------------------
    while (wxDbGetDataSource(DbConnectInf.GetHenv(), Dsn, SQL_MAX_DSN_LENGTH, DsDesc, 254))
    {
        i_DSN++;   // How many Dsn have we ?
        KeyString.Printf(_T("%s%c%s"),Dsn, sep, DsDesc);
        s_SortDSNList.Add(Dsn);
        s_SortDsDescList.Add(KeyString);
    }

    //---------------------------------------------------------------------------------------
    // Allocate n ODBC-DSN objects to hold the information
    // Allocate n wxDatabase objects to hold the column information
    p_DSN = new DSN[i_DSN];  //BJO
    db_Br = new BrowserDB[i_DSN];
    for (i=0;i<i_DSN;i++)
    {
        KeyString = s_SortDsDescList[i];
        KeyString = KeyString.AfterFirst(sep);

        // ODBC-DSN object
        (p_DSN+i)->Dsn = s_SortDSNList[i];
        (p_DSN+i)->Drv = KeyString;
        (p_DSN+i)->Usr = wxEmptyString;
        (p_DSN+i)->Pas = wxEmptyString;
        Temp0.Printf(_T("%02d) Dsn(%s) DsDesc(%s)"),i,(p_DSN+i)->Dsn.c_str(),(p_DSN+i)->Drv.c_str());
        wxLogMessage(Temp0);

        // wxDataBase object
        (db_Br+i)->p_LogWindow = p_LogWin;
        (db_Br+i)->ODBCSource  = (p_DSN+i)->Dsn;
        (db_Br+i)->UserName    = (p_DSN+i)->Usr;
        (db_Br+i)->Password    = (p_DSN+i)->Pas;
        (db_Br+i)->pDoc        = this;
        (db_Br+i)->i_Which     = i;
    }

    DbConnectInf.FreeHenv();

    //---------------------------------------------------------------------------------------
    if (!i_DSN)
    {
        wxString message = _("No Dataset names found in ODBC!\n");
        message += _("           Program will exit!\n\n");
        message += _("                       Ciao");
        wxMessageBox( message,_("-E-> Fatal situation"));
        return false;
    }
    //---------------------------------------------------------------------------------------
    return true;
}
Exemplo n.º 3
0
//----------------------------------------------------------------------------------------
bool BrowserDB::OnStartDB(int Quiet)
{
    wxStopWatch sw;
    if (!Quiet)
        wxLogMessage(_("\n-I-> BrowserDB::OnStartDB(%s) : Begin "),ODBCSource.c_str());
    if (db_BrowserDB != NULL)
    {
        if (!Quiet)
            wxLogMessage(_("\n-I-> BrowserDB::OnStartDB() : DB is already open."));
        return true;
    }

    DbConnectInf.AllocHenv();

    //---------------------------------------------------------------------------------------
    // Connect to datasource
    //---------------------------------------------------------------------------------------
    DlgUser *p_Dlg;
    p_Dlg = new DlgUser(pDoc->p_MainFrame,pDoc,wxEmptyString);
    p_Dlg->s_DSN      = ODBCSource;
    p_Dlg->s_User     = UserName;
    p_Dlg->s_Password = Password;
    p_Dlg->OnInit();
    p_Dlg->Fit();

    bool OK = false;
    if (p_Dlg->ShowModal() == wxID_OK)
    {
        (pDoc->p_DSN+i_Which)->Usr = p_Dlg->s_User;
        (pDoc->p_DSN+i_Which)->Pas = p_Dlg->s_Password;
        UserName  = p_Dlg->s_User;
        Password  = p_Dlg->s_Password;
        OK = true;
    }
    delete p_Dlg;
    if (OK)
    {
        //--------------------------------------------------------------------------------------
        DbConnectInf.SetDsn(ODBCSource);         // ODBC data source name (created with ODBC Administrator under Win95/NT)
        DbConnectInf.SetUserID(UserName);        // database username - must already exist in the data source
        DbConnectInf.SetPassword(Password);      // password database username
        db_BrowserDB = wxDbGetConnection(&DbConnectInf);
        // wxLogMessage(">>>%s<<<>>>%s<<<",UserName.c_str(),Password.c_str());
        if (db_BrowserDB == NULL)
        {
            DbConnectInf.SetDsn(wxEmptyString);
            DbConnectInf.SetUserID(wxEmptyString);
            DbConnectInf.SetPassword(wxEmptyString);
            if (!Quiet)
            {
                wxLogMessage(_("\n-E-> BrowserDB::OnConnectDataSource() DB CONNECTION ERROR : Unable to connect to the data source.\n\nCheck the name of your data source to verify it has been correctly entered/spelled.\n\nWith some databases, the user name and password must\nbe created with full rights to the table prior to making a connection\n(using tools provided by the database manufacturer)"));
                wxLogMessage(_("-I-> BrowserDB::OnStartDB(%s) : End - Time needed : %ld ms"),ODBCSource.c_str(),sw.Time());
            }
            DbConnectInf.FreeHenv();
            return false;
        }
        //--------------------------------------------------------------------------------------
        if (!Quiet)
        {
            Temp1 = db_BrowserDB->GetDatabaseName();
            Temp2 = db_BrowserDB->GetDataSource();
            wxLogMessage(_("-I-> BrowserDB::OnGetDataSourceODBC() - DatabaseName(%s) ; DataSource(%s)"),Temp1.c_str(),Temp2.c_str());
            wxLogMessage(_("-I-> BrowserDB::OnStartDB(%s) : End - Time needed : %ld ms"),ODBCSource.c_str(),sw.Time());
        }
        return true;
    }
    else
    {
        DbConnectInf.FreeHenv();
        return false;
    }
}