Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / problem reading data from a postgresql-db via odbc

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. problem reading data from a postgresql-db via odbc
#2420
Posted by: 2003-07-30 19:44:03
ich have tried to read data from a postgresql source.
i used nearly the same code like here: http://www.wxwindows.org/manuals/2.4.0/wx497.htm#wxodbcsamplecode1

here is my code:

void AuftragsFrame::DbTest()
{
    wxDbConnectInf *DbConnectInf = NULL;
    wxDbTable *table = NULL;
    wxDb *db = NULL;
    
    // LeseBuffer
    long kdnNr = 0;
    wxChar Name[30+1];
    wxChar vName[30+1];
    
    Name[0] = 0;
    vName[0] = 0;
    
    bool errorOccured = FALSE;
    
    
    const wxChar tableName[] = "kunde";
    const UWORD numTableColumns = 3;
    
    DbConnectInf = new wxDbConnectInf(NULL,"auftragsdb","auftragsuser", "ahc5u3k");
    
    if (!DbConnectInf || !DbConnectInf->GetHenv())
    {
      wxMessageBox("Unable to allocate an ODBC environment handle",
            "DB CONNECTION ERROR", wxOK | wxICON_EXCLAMATION);
              return;
    }
    
    db = wxDbGetConnection(DbConnectInf);
    
    if (!db)
    {
        wxLogMessage("Connection Error");
        delete DbConnectInf;
        return;
    }
    
    table = new wxDbTable(db, tableName, numTableColumns, "", 
                      wxDB_QUERY_ONLY, "");
                      
    table->SetColDefs(0, "KudenNr", DB_DATA_TYPE_INTEGER, &kdnNr,
                    SQL_C_LONG, sizeof(kdnNr), TRUE, TRUE);
    table->SetColDefs(1, "Name", DB_DATA_TYPE_VARCHAR, Name,
                    SQL_C_CHAR, sizeof(Name), FALSE, TRUE);
    table->SetColDefs(2, "vName", DB_DATA_TYPE_VARCHAR, vName,
                    SQL_C_CHAR, sizeof(vName), FALSE, TRUE);
    
    table->Open();
    
    table->SetWhereClause("");
    table->SetOrderByClause("");
    table->SetFromClause("");
    
    if (!table->Query())
    {
        wxMessageBox("Error on Query()","ERROR!",
                  wxOK | wxICON_EXCLAMATION);
        errorOccured = TRUE;
    }
    

    wxString msg;
    
    while (table->GetNext())
    {
        msg.Printf("Row #%lu -- First Name : %s  Last Name is %s",
               table->GetRowNum(), Name, vName);
        wxMessageBox(msg, "Data", wxOK | wxICON_INFORMATION, NULL);
    }
    
    if (table)
    {
        delete table;
        table = NULL;
    }
    
    if (db)
    {
        wxDbFreeConnection(db);
        db = NULL;
    }

    wxDbCloseConnections();
    delete DbConnectInf;

}
connecting to the database works, i get 3 rows with table->getnext(), and in the database are 3 rows. but in the vars kdNr, Name and vName do no change, the stay like the were initialised.

i think there is a problem at table->SetColDefs ...
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2024-3-29  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0