List:MySQL++« Previous MessageNext Message »
From:Freyja Date:November 17 2006 1:18am
Subject:Re: Compile Error/Code Issue
View as plain text  
Thanks a million for the help, I was able to work through most of the issues
but I think my fundamental modifications of the code that I did last night
were what was giving me the most problems.  So, in short, I backed up the
version that I finally got to compile (which still doesn't compile into the
program itself which is why I think it might be a bigger set of what I did)
and then pulled a fresh copy of the file and did some very basic
modifications and I think I'm quite a bit further along but I appear to be
running into a big of an issue with it at this point and was wondering if I
could get any pointers as to if I have something with mysqlpp set up wrong?
I think I'm really really close, but a touch stuck =\.

### The Errors ###

lyra:src/SQL# make
g++  -Wall -Wno-deprecated -O -g    -I/usr/include/mysql++ -I/usr/include/my
sql -c DatabaseControl.cpp
DatabaseControl.h:29: error: ISO C++ forbids declaration of 'Connection'
with no type
DatabaseControl.h:29: error: expected ';' before '*' token
DatabaseControl.cpp: In constructor 'DatabaseControl::DatabaseControl()':
DatabaseControl.cpp:39: error: 'm_conDB' was not declared in this scope
DatabaseControl.cpp:39: error: expected type-specifier before 'Connection'
DatabaseControl.cpp:39: error: expected `;' before 'Connection'
DatabaseControl.cpp: In member function 'std::map<std::basic_string<char,
std::char_traits<char>, std::allocator<char> >, Command*,
std::less<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > >, std::allocator<std::pair<const
std::basic_string<char, std::char_traits<char>, std::allocator<char> >,
Command*> > > DatabaseControl::getCommands()':
DatabaseControl.cpp:54: error: 'm_conDB' was not declared in this scope

### The Snippets of Code ###

I have included mysql++.h and using namespace mysqlpp


DatabaseControl *DatabaseControl::s_DBCinstance((DatabaseControl*) 0);

/**
 * Private contructor for the class.  Creates a new Connection object
 * and connects to the database.
 */
DatabaseControl::DatabaseControl()
{
    try
    {
        m_conDB = new Connection();
        m_conDB->connect(DBNAME, DBHOST, DBUSER, DBPASS);
    }
    catch(const BadQuery& er)
    {
        cerr << "Error occured: " << er.what() << endl;
    }
}

###### 2nd error related to below ######

map<string, Command*> DatabaseControl::getCommands()
{
    map<string, Command*> theMap;

    try
    {
        Query query = m_conDB->query();
        query << "SELECT * FROM tbl_commands";

        Result res = query.store();
        Row row;

        Result::iterator it;
        for(it = res.begin(); it != res.end(); ++it)
        {
            row = *it;
            Command *newCmd = new Command(
                        row["Name"].get_string(),
                        row["Code"].get_string(),
                        (int)row["MinPosition"],
                        (int)row["Level"],
                        (int)row["Logged"],
                        (int)row["Enabled"] );
            theMap[newCmd->getName()] = newCmd;
        }
    }
    catch(const BadQuery& er)
    {
        cerr << "Error querying for Command:" << er.what() << endl;
    }

    return theMap;
}


### The Header File Snippets ###

I have included mysql++.h and using namespace mysqlpp here as well.

class Connection;

class DatabaseControl : public IDataPersist
{
    private:
        Connection *m_conDB;
        static DatabaseControl *s_DBCinstance;
        DatabaseControl();

    public:
        virtual ~DatabaseControl();
        static DatabaseControl* Instance();
        map<string, Command* > getCommands();
**SNIPPED**

----- Original Message ----- 
From: "Joel Fielder" <joel.fielder@stripped>
To: <plusplus@stripped>
Sent: Thursday, November 16, 2006 2:46 AM
Subject: RE: Compile Error/Code Issue


> I'm sure these are just c++ errors as opposed to anything mysql++
> related - if so you should follow this up on a c++ list somewhere.
>
> Error 1, exactly what it says on the tin, constructors can't return a
> value of any type so just remove the "return -1;".  Personally, I'd let
> whatever instanciates DatabaseControl handle the exception (or at least
> re-throw it), but otherwise making that change will correct the error.
>
> I think error 2 is because "con" is a pointer, probably you need to use
> con->query().  I think error 3 you're missing the header file for
> mysqlpp::Connection.
>
> Also, because you're shadowing the "con" member variable in the
> constructor it is probably not allocated anywhere.  Result: app will
> probably crash when you call getCommands or DatabaseControl goes out of
> scope :)  Enjoy more, and turn on -Wshadow to have the compiler let you
> know about it.  Turn on -Wall for that matter :)
>
> Joel
>
>
> -- 
> MySQL++ Mailing List
> For list archives: http://lists.mysql.com/plusplus
> To unsubscribe:
http://lists.mysql.com/plusplus?unsub=1
>
>

Thread
Problems with mysql and mysql++ examplesgary clark14 Nov
  • Compile Error/Code IssueFreyja16 Nov
    • RE: Compile Error/Code IssueJoel Fielder16 Nov
      • Re: Compile Error/Code IssueFreyja17 Nov
        • Re: Compile Error/Code IssueJoel Fielder17 Nov
  • Re: Problems with mysql and mysql++ examplesWarren Young16 Nov
    • Re: Problems with mysql and mysql++ examplesgary clark16 Nov
Re: Problems with mysql and mysql++ examplesgary clark16 Nov