List:MySQL++« Previous MessageNext Message »
From:Loïc Dardant Date:July 2 2008 9:56am
Subject:Derive a structure and use it with storein
View as plain text  
Hi !

I just want to add some functions to a SSQLS. So I've created a basic
structure that map my sql table. Then I've created
a class that derive from this structure. But when I use my class, I've got
error during compilation (Visual Studio 2005, Xp).
There is a problem in the function storein :

c:\mysql++\include\query.h(752) : error C2440: '<function-style-cast>' :
impossible to convert  'mysqlpp::Row' to 'User'

I guess i've done something wrong, but i read the documentation, examples,
the mailing list and the forums, and I can't find a solution.
You can see the code below.

Thanks

/*****************/
/*File User.h : */
/*****************/
#if !defined(EXPAND_MY_SSQLS_STATICS)
#   define MYSQLPP_SSQLS_NO_STATICS
#endif

#if !defined(_USER_H)
#define _USER_H

#include <mysql++.h>
#include <ssqls.h>

namespace database
{
    sql_create_3(User, 1, 3,
            mysqlpp::sql_varchar, name_user,
            mysqlpp::sql_varchar, threeg_id_user,
            mysqlpp::sql_int, num_user)
}

class User : public database::User
{
public:
    User(mysqlpp::sql_varchar a, mysqlpp::sql_varchar b, mysqlpp::sql_int c
);
    ~User();
    void foo();
};

#endif  //_USER_H



/*******************/
/* File User.cpp */
/*******************/
#define EXPAND_MY_SSQLS_STATICS
#include "User.h"

User::User(mysqlpp::sql_varchar a, mysqlpp::sql_varchar b, mysqlpp::sql_int
c) : database::User(a,b,c)
{}

User::~User()
{}

Uvoid User::foo()
{}


/*******************/
/* File main.cpp */
/*******************/
#include <iostream>
#include "User.h"

using namespace std;

int main(int argc, char*argv[])
{

    //let's go
    try {
        // Establish the connection to the database server.
        mysqlpp::Connection con(DATABASE, SERVER, USER, PASSWD);

        // Retrieve a subset of the stock table's columns, and store
        // the data in a vector of 'stock' SSQLS structures.  See the
        // user manual for the consequences arising from this quiet
        // ability to store a subset of the table in the stock SSQLS.
        mysqlpp::Query query = con.query("select * from user");
        vector<User> res;
        query.storein(res);

        // Display the items
        cout << "We have:" << endl;
        vector<User>::iterator it;
        for (it = res.begin(); it != res.end(); ++it) {
            cout<<it->num_user<<"  "<<it->name_user<<endl;
        }
    }
    catch (const mysqlpp::BadQuery& er) {
        // Handle any query errors
        cerr << "Query error: " << er.what() << endl;
        return -1;
    }
    catch (const mysqlpp::BadConversion& er) {
        // Handle bad conversions; e.g. type mismatch populating 'stock'
        cerr << "Conversion error: " << er.what() << endl <<
                "\tretrieved data size: " << er.retrieved <<
                ", actual size: " << er.actual_size << endl;
        return -1;
    }
    catch (const mysqlpp::Exception& er) {
        // Catch-all for any other MySQL++ exceptions
        cerr << "Error: " << er.what() << endl;
        return -1;
    }
}

-- 
Loïc Dardant

Thread
Derive a structure and use it with storeinLoïc Dardant2 Jul
  • Re: Derive a structure and use it with storeinWarren Young2 Jul
    • Re: Derive a structure and use it with storeinLoïc Dardant2 Jul