Author Topic: many impossible to understand errors  (Read 7361 times)

Offline cotede2

  • Multiple posting newcomer
  • *
  • Posts: 17
many impossible to understand errors
« on: May 03, 2010, 09:38:13 pm »
Hello, I found a script to handle database connection and queries.
I created two files:

testdbb.h
Code: [Select]
#ifndef TESTDB_H_INCLUDED
#define TESTDB_H_INCLUDED

#include <wx/app.h>

class testdb : public wxApp
{
    public:
         int connexion();
         int HandleError(wxString errmsg, wxDb *pDb=NULL);
};

#endif // TESTDB_H_INCLUDED

and

testdb.cpp

Code: [Select]
// ----------------------------------------------------------------------------
// HEADERS
// ----------------------------------------------------------------------------
#include "wx/log.h"         // #included to enable output of messages only
#include "wx/dbtable.h"

// ----------------------------------------------------------------------------
// FUNCTION USED FOR HANDLING/DISPLAYING ERRORS
// ----------------------------------------------------------------------------
// Very generic error handling function.
// If a connection to the database is passed in, then we retrieve all the
// database errors for the connection and add them to the displayed message
int HandleError(wxString errmsg, wxDb *pDb=NULL)
{
    // Retrieve all the error message for the errors that occurred
    wxString allErrors;
    if (!pDb == NULL)
        // Get the database errors and append them to the error message
        allErrors = wxDbLogExtendedErrorMsg(errmsg.c_str(), pDb, 0, 0);
    else
        allErrors = errmsg;

    // Do whatever you wish with the error message here
    // wxLogDebug() is called inside wxDbLogExtendedErrorMsg() so this
    // console program will show the errors in the console window,
    // but these lines will show the errors in RELEASE builds also
    wxFprintf(stderr, wxT("\n%s\n"), allErrors.c_str());
    fflush(stderr);

    return 1;
}


// ----------------------------------------------------------------------------
// entry point
// ----------------------------------------------------------------------------
int connexion()
{
wxDbConnectInf  *DbConnectInf    = NULL;    // DB connection information

wxDb            *db              = NULL;    // Database connection

wxDbTable       *table           = NULL;    // Data table to access
const wxChar     tableName[]     = wxT("USERS"); // Name of database table
const UWORD      numTableColumns = 2;       // Number table columns
wxChar           FirstName[50+1];           // column data: "FIRST_NAME"
wxChar           LastName[50+1];            // column data: "LAST_NAME"

wxString         msg;                       // Used for display messages

// -----------------------------------------------------------------------
// DEFINE THE CONNECTION HANDLE FOR THE DATABASE
// -----------------------------------------------------------------------
DbConnectInf = new wxDbConnectInf(NULL,
                                    wxT("CONTACTS-SqlServer"),
                                    wxT("sa"),
                                    wxT("abk"));

// Error checking....
if (!DbConnectInf || !DbConnectInf->GetHenv())
{
    return HandleError(wxT("DB ENV ERROR: Cannot allocate ODBC env handle"));
}


// -----------------------------------------------------------------------
// GET A DATABASE CONNECTION
// -----------------------------------------------------------------------
db = wxDbGetConnection(DbConnectInf);

if (!db)
{
    return HandleError(wxT("CONNECTION ERROR - Cannot get DB connection"));
}


// -----------------------------------------------------------------------
// DEFINE THE TABLE, AND THE COLUMNS THAT WILL BE ACCESSED
// -----------------------------------------------------------------------
table = new wxDbTable(db, tableName, numTableColumns, wxT(""),
                    !wxDB_QUERY_ONLY, wxT(""));
//
// Bind the columns that you wish to retrieve. Note that there must be
// 'numTableColumns' calls to SetColDefs(), to match the wxDbTable def
//
// Not all columns need to be bound, only columns whose values are to be
// returned back to the client.
//
table->SetColDefs(0, wxT("FIRST_NAME"), DB_DATA_TYPE_VARCHAR, FirstName,
                SQL_C_WXCHAR, sizeof(FirstName), true, true);
table->SetColDefs(1, wxT("LAST_NAME"), DB_DATA_TYPE_VARCHAR, LastName,
                SQL_C_WXCHAR, sizeof(LastName), true, true);


// -----------------------------------------------------------------------
// CREATE (or RECREATE) THE TABLE IN THE DATABASE
// -----------------------------------------------------------------------
if (!table->CreateTable(true))  //NOTE: No CommitTrans is required
{
    return HandleError(wxT("TABLE CREATION ERROR: "), table->GetDb());
}


// -----------------------------------------------------------------------
// OPEN THE TABLE FOR ACCESS
// -----------------------------------------------------------------------
if (!table->Open())
{
    return HandleError(wxT("TABLE OPEN ERROR: "), table->GetDb());
}


// -----------------------------------------------------------------------
// INSERT A NEW ROW INTO THE TABLE
// -----------------------------------------------------------------------
wxStrcpy(FirstName, wxT("JULIAN"));
wxStrcpy(LastName, wxT("SMART"));
if (!table->Insert())
{
    return HandleError(wxT("INSERTION ERROR: "), table->GetDb());
}

// Must commit the insert to write the data to the DB
table->GetDb()->CommitTrans();


// -----------------------------------------------------------------------
// RETRIEVE ROWS FROM THE TABLE BASED ON SUPPLIED CRITERIA
// -----------------------------------------------------------------------
// Set the WHERE clause to limit the result set to return
// all rows that have a value of 'JULIAN' in the FIRST_NAME
// column of the table.
table->SetWhereClause(wxT("FIRST_NAME = 'JULIAN'"));

// Result set will be sorted in ascending alphabetical
// order on the data in the 'LAST_NAME' column of each row
table->SetOrderByClause(wxT("LAST_NAME"));

// No other tables (joins) are used for this query
table->SetFromClause(wxT(""));

// Instruct the datasource to perform a query based on the
// criteria specified above in the where/orderBy/from clauses.
if (!table->Query())
{
    return HandleError(wxT("QUERY ERROR: "), table->GetDb());
}

// Loop through all rows matching the query criteria until
// there are no more records to rea d
while (table->GetNext())
{
    msg.Printf(wxT("Row #%lu -- First Name : %s  Last Name is %s"),
            table->GetRowNum(), FirstName, LastName);

    // Code to display 'msg' here
    wxLogMessage(wxT("\n%s\n"), msg.c_str());
}


// -----------------------------------------------------------------------
// DELETE A ROW FROM THE TABLE
// -----------------------------------------------------------------------
// Select the row which has FIRST_NAME of 'JULIAN' and LAST_NAME
// of 'SMART', then delete the retrieved row
//
if (!table->DeleteWhere(wxT("FIRST_NAME = 'JULIAN' and LAST_NAME = 'SMART'")))
{
    return HandleError(wxT("DELETION ERROR: "), table->GetDb());
}

// Must commit the deletion to the database
table->GetDb()->CommitTrans();


// -----------------------------------------------------------------------
// TAKE CARE OF THE ODBC CLASS INSTANCES THAT WERE BEING USED
// -----------------------------------------------------------------------
// If the wxDbTable instance was successfully created
// then delete it as we are done with it now.
wxDELETE(table);

// Free the cached connection
// (meaning release it back in to the cache of datasource
// connections) for the next time a call to wxDbGetConnection()
// is made.
wxDbFreeConnection(db);
db = NULL;


// -----------------------------------------------------------------------
// CLEANUP BEFORE EXITING APP
// -----------------------------------------------------------------------
// The program is now ending, so we need to close
// any cached connections that are still being
// maintained.
wxDbCloseConnections();

// Release the environment handle that was created
// for use with the ODBC datasource connections
wxDELETE(DbConnectInf);

//wxUnusedVar(argc);  // Here just to prevent compiler warnings
//wxUnusedVar(argv);  // Here just to prevent compiler warnings

return 0;
}

Quote
obj\Release\testdb.o:testdb.cpp:(.text+0x5f)||undefined reference to `__imp___Z23wxDbLogExtendedErrorMsgPKwP4wxDbS0_i'|
obj\Release\testdb.o:testdb.cpp:(.text+0x385)||undefined reference to `__imp___ZN14wxDbConnectInfC1EPvRK8wxStringS3_S3_S3_S3_S3_'|
obj\Release\testdb.o:testdb.cpp:(.text+0xbfc)||undefined reference to `__imp___Z17wxDbGetConnectionP14wxDbConnectInfb'|
obj\Release\testdb.o:testdb.cpp:(.text+0xd0d)||undefined reference to `__imp___ZN9wxDbTableC1EP4wxDbRK8wxStringtS4_bS4_'|
obj\Release\testdb.o:testdb.cpp:(.text+0xe1d)||undefined reference to `__imp___ZN9wxDbTable10SetColDefsEtRK8wxStringiPvsibbbb'|
obj\Release\testdb.o:testdb.cpp:(.text+0xedf)||undefined reference to `__imp___ZN9wxDbTable10SetColDefsEtRK8wxStringiPvsibbbb'|
obj\Release\testdb.o:testdb.cpp:(.text+0xf3a)||undefined reference to `__imp___ZN9wxDbTable11CreateTableEb'|
obj\Release\testdb.o:testdb.cpp:(.text+0x119e)||undefined reference to `__imp___ZN9wxDbTable4OpenEbb'|
obj\Release\testdb.o:testdb.cpp:(.text+0x12a9)||undefined reference to `__imp___ZN9wxDbTable6InsertEv'|
obj\Release\testdb.o:testdb.cpp:(.text+0x1389)||undefined reference to `__imp___ZN4wxDb11CommitTransEv'|
obj\Release\testdb.o:testdb.cpp:(.text+0x1616)||undefined reference to `__imp___ZN9wxDbTable6getRecEt'|
obj\Release\testdb.o:testdb.cpp:(.text+0x1627)||undefined reference to `__imp___ZN9wxDbTable9GetRowNumEv'|
obj\Release\testdb.o:testdb.cpp:(.text+0x16d0)||undefined reference to `__imp___ZN9wxDbTable11DeleteWhereERK8wxString'|
obj\Release\testdb.o:testdb.cpp:(.text+0x17f1)||undefined reference to `__imp___ZN4wxDb11CommitTransEv'|
obj\Release\testdb.o:testdb.cpp:(.text+0x181a)||undefined reference to `__imp___Z18wxDbFreeConnectionP4wxDb'|
obj\Release\testdb.o:testdb.cpp:(.text+0x1822)||undefined reference to `__imp___Z20wxDbCloseConnectionsv'|
obj\Release\testdb.o:testdb.cpp:(.text+0x183b)||undefined reference to `__imp___ZN14wxDbConnectInfD1Ev'|
||=== Build finished: 17 errors, 0 warnings ===|

I cannot understand those errors when I compile.
Thanks for ur help

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6483
    • My Best Post
Re: many impossible to understand errors
« Reply #1 on: May 03, 2010, 11:44:18 pm »
Read this
http://docs.wxwidgets.org/stable/wx_odbcoverview.html#wxodbcconfiguringyoursystem
http://docs.wxwidgets.org/stable/wx_librarieslist.html#librarieslist

After verifying your wxWidgets folder has an correct db library(I am not sure of its name), add it to the C::B Linker Library List.

Tim S.
« Last Edit: May 03, 2010, 11:46:46 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline cotede2

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: many impossible to understand errors
« Reply #2 on: May 04, 2010, 09:32:55 pm »
Is the db library related to wxwidgets?
In other words, how does the compiler knows which database type I want to query?
I am familiar with using connector with java (postgresql , mysql, sql server, db2..) but nope with c++ .
Let's say I want to query on a mysql database.
Where is the db library?
I read the documentation and I assume
"Most database vendors provide at least a minimal ODBC driver with their database product. In practice, many of these drivers have proven to be slow and/or incomplete. Rumour has it that this is because the vendors do not want you using the ODBC interface to their products; they want you to use their applications to access the data."


I am going to the system datasource of the admin datasources odbc of my windows XP.
I see several options and so I configure into my program :
Code: [Select]
DbConnectInf = new wxDbConnectInf(NULL,
                                    wxT("dsTracking"),
                                    wxT("sa"),
                                    wxT("***"));
But I still got the same error cause I don't know what kind of libraries and where exactly to put it.
Thanks for more information.

I also found interesting topic http://wiki.wxwidgets.org/ODBC
But I don't know how to import samples/db into codeblocks and make the project compiled.

Thanks for help


Offline stahta01

  • Lives here!
  • ****
  • Posts: 6483
    • My Best Post
Re: many impossible to understand errors
« Reply #3 on: May 04, 2010, 10:02:33 pm »
If your wxWidgets does not have the right library then re-compile it with the proper options to create the needed library for wxDbTable class methods.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline cotede2

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: many impossible to understand errors
« Reply #4 on: May 04, 2010, 10:31:28 pm »
I am a little confused right here.
What do I have to do step by step?
Open codeblocks? open wxwidgets? Usually when I do compile, I just hit the compile button and I dont provide any options.
thank you, could you be more precise

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6483
    • My Best Post
Re: many impossible to understand errors
« Reply #5 on: May 04, 2010, 11:09:09 pm »
I am a little confused right here.
What do I have to do step by step?
Open codeblocks? open wxwidgets? Usually when I do compile, I just hit the compile button and I dont provide any options.
thank you, could you be more precise

You either compiled wxWidgets Libraries yourself or downloaded them?
If you compiled them yourself, use the options to get ODBC library created and compile them again.
If downloaded, search the site for ones with ODBC; I do NOT think it will exist but try it.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline cotede2

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: many impossible to understand errors
« Reply #6 on: May 05, 2010, 09:46:47 pm »
yes I did compile myself:
using :
mingw32-make -f makefile.gcc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1
mingw32-make -f makefile.gcc BUILD=debug SHARED=1 MONOLITHIC=1 UNICODE=1

could you tell me please what are the options to get ODBC library created?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6483
    • My Best Post
Re: many impossible to understand errors
« Reply #7 on: May 05, 2010, 09:51:34 pm »
yes I did compile myself:
using :
mingw32-make -f makefile.gcc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1
mingw32-make -f makefile.gcc BUILD=debug SHARED=1 MONOLITHIC=1 UNICODE=1

could you tell me please what are the options to get ODBC library created?

You have to edit setup.h to changed the value of wxUSE_ODBC to 1;
Edit <WXWIN>\include\wx\msw\setup.h and delete the <WXWIN>\lib\gcc_dll\mswu\wx\setup.h
(The make commands copies <WXWIN>\include\wx\msw\setup.h to <WXWIN>\lib\gcc_dll\mswu\wx\setup.h)

Old
Code: [Select]
#define wxUSE_ODBC 0
Changed
Code: [Select]
#define wxUSE_ODBC 1

The build using the addition of USE_ODBC=1; note should do a clean before build

mingw32-make -f makefile.gcc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1 USE_ODBC=1 clean
mingw32-make -f makefile.gcc BUILD=debug SHARED=1 MONOLITHIC=1 UNICODE=1 USE_ODBC=1 clean

mingw32-make -f makefile.gcc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1 USE_ODBC=1
mingw32-make -f makefile.gcc BUILD=debug SHARED=1 MONOLITHIC=1 UNICODE=1 USE_ODBC=1

Tim S.
« Last Edit: May 05, 2010, 09:55:18 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline cotede2

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: many impossible to understand errors
« Reply #8 on: May 06, 2010, 06:16:51 am »
thank you I did that.
But now when I go back to my application, I still have those undefined references.
I'd like to be able to compile the db sample.
Once in the samples/db folder, what command should I do to compile ? thank you

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5214
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: many impossible to understand errors
« Reply #9 on: May 06, 2010, 07:54:10 am »
thank you I did that.
But now when I go back to my application, I still have those undefined references.
I'd like to be able to compile the db sample.
Once in the samples/db folder, what command should I do to compile ? thank you

You can still run the command:
Code: [Select]
mingw32-make -f makefile.gcc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1 USE_ODBC=1
mingw32-make -f makefile.gcc BUILD=debug SHARED=1 MONOLITHIC=1 UNICODE=1 USE_ODBC=1

in your samples/db folder.

Here is the steps:

1,Open the Dos prompt window,

2, change the current directory to
D:\code\wxWidgets-2.8.11\samples\db

3, run the command there to build the database samples.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline cotede2

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: many impossible to understand errors
« Reply #10 on: May 06, 2010, 08:34:47 pm »
thanks but here what I got:



Code: [Select]
C:\wxWidgets\samples\db>mingw32-make -f makefile.gcc BUILD=release SHARED=1 MONO
LITHIC=1 UNICODE=1 USE_ODBC=1
if not exist gcc_mswudll mkdir gcc_mswudll
g++ -c -o gcc_mswudll\dbtest_dbtest.o  -O2 -mthreads  -DHAVE_W32API_H -D__WXMSW_
_      -D_UNICODE   -I.\..\..\lib\gcc_dll\mswu -I.\..\..\include -W -Wall -I. -D
WXUSINGDLL -I.\..\..\samples -DNOPCH   -Wno-ctor-dtor-privacy   -MTgcc_mswudll\d
btest_dbtest.o -MFgcc_mswudll\dbtest_dbtest.o.d -MD -MP dbtest.cpp
In file included from ./../../include/wx/wx.h:21,
                 from dbtest.cpp:31:
./../../include/wx/hashmap.h:735: warning: type attributes are honored only at t
ype definition
./../../include/wx/hashmap.h:735: warning: type attributes are honored only at t
ype definition
In file included from ./../../include/wx/event.h:18,
                 from ./../../include/wx/wx.h:25,
                 from dbtest.cpp:31:
./../../include/wx/clntdata.h:20: warning: type attributes are honored only at t
ype definition
./../../include/wx/clntdata.h:20: warning: type attributes are honored only at t
ype definition
./../../include/wx/clntdata.h:25: warning: type attributes are honored only at t
ype definition
./../../include/wx/clntdata.h:25: warning: type attributes are honored only at t
ype definition
In file included from ./../../include/wx/wx.h:45,
                 from dbtest.cpp:31:
./../../include/wx/image.h:136: warning: type attributes are honored only at typ
e definition
./../../include/wx/image.h:136: warning: type attributes are honored only at typ
e definition
dbtest.cpp:70:4: #error Sample cannot be compiled unless setup.h has wxUSE_ODBC
set to 1
dbtest.cpp: In member function `bool DbGridFrame::Initialize()':
dbtest.cpp:3335: error: `wxDbGridColInfo' was not declared in this scope
dbtest.cpp:3335: error: `cols' was not declared in this scope
dbtest.cpp:3336: error: `wxDbGridColInfo' is not a type
dbtest.cpp:3337: error: `wxDbGridColInfo' is not a type
dbtest.cpp:3338: error: `wxDbGridColInfo' is not a type
dbtest.cpp:3339: error: `wxDbGridColInfo' is not a type
dbtest.cpp:3340: error: `wxDbGridColInfo' is not a type
dbtest.cpp:3341: error: `wxDbGridColInfo' is not a type
dbtest.cpp:3342: error: `wxDbGridColInfo' is not a type
dbtest.cpp:3343: error: `wxDbGridColInfo' is not a type
dbtest.cpp:3343: error: `wxGRID_VALUE_DBAUTO' was not declared in this scope
dbtest.cpp:3344: error: `wxDbGridColInfo' is not a type
dbtest.cpp:3345: error: `wxDbGridColInfo' is not a type
dbtest.cpp:3346: error: `wxDbGridColInfo' is not a type
dbtest.cpp:3348: error: `wxDbGridColInfo' is not a type
dbtest.cpp:3394: error: `wxDbGridTableBase' was not declared in this scope
dbtest.cpp:3394: error: `db' was not declared in this scope
dbtest.cpp:3394: error: `wxDbGridTableBase' is not a type
dbtest.cpp:3394: error: `wxUSE_QUERY' was not declared in this scope
dbtest.cpp:3396: error: type `<type error>' argument given to `delete', expected
 pointer
dbtest.cpp:3335: warning: unused variable 'wxDbGridColInfo'
dbtest.cpp:3343: warning: unused variable 'wxGRID_VALUE_DBAUTO'
dbtest.cpp:3394: warning: unused variable 'wxDbGridTableBase'
dbtest.cpp:3394: warning: unused variable 'wxUSE_QUERY'
mingw32-make: *** [gcc_mswudll\dbtest_dbtest.o] Error 1

C:\wxWidgets\samples\db>


what is wrong?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6483
    • My Best Post
Re: many impossible to understand errors
« Reply #11 on: May 06, 2010, 08:56:52 pm »

dbtest.cpp:70:4: #error Sample cannot be compiled unless setup.h has wxUSE_ODBC
set to 1

what is wrong?

You have to edit setup.h to changed the value of wxUSE_ODBC to 1;
Edit <WXWIN>\include\wx\msw\setup.h and delete the <WXWIN>\lib\gcc_dll\mswu\wx\setup.h
(The make commands copies <WXWIN>\include\wx\msw\setup.h to <WXWIN>\lib\gcc_dll\mswu\wx\setup.h)

Old
Code: [Select]
#define wxUSE_ODBC 0
Changed
Code: [Select]
#define wxUSE_ODBC 1

You either did not edit setup.h correctly or are NOT using the wxWidgets installation you edited.

Tim S.
« Last Edit: May 06, 2010, 09:30:27 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline cotede2

  • Multiple posting newcomer
  • *
  • Posts: 17
Re: many impossible to understand errors
« Reply #12 on: May 06, 2010, 11:50:33 pm »
thank you. It worked after I also moved the custom dll to the correct folder in inside the db folder cause first off, it said that a .dll was missing