List:MySQL++« Previous MessageNext Message »
From:Joe Hudson Date:December 7 2007 5:51pm
Subject:Re: linking mysql++ 2.3.2
View as plain text  
Hey,

Fair enough, hadn't thought of proposing them as a patch, but I suppose they
could be handy for some people.
It seems to me with the insert, update and replace methods taking an SSQLS
(or iterators of them) they're as
elegant and simple as they are because what they do is limited to
adding/changing whole rows without any user provided conditional logic.
Just a small handy subset of what you would otherwise do with a call to
query << string; query execute/store, etc. and what you have to do for
retrieving data.
SSQLS aren't bound to a table when they are being filled from one (I
believe) so then why need they be when being saved?
Anyway, here's the very simple additions I made.

    template <class T>
    Query& update(const T& o, const T& n, const std::string& table)
    {
        reset();

        // Cast required for VC++ 2003 due to error in overloaded operator
        // lookup logic.  For an explanation of the problem, see:
        //
http://groups-beta.google.com/group/microsoft.public.vc.stl/browse_thread/thread/9a68d84644e64f15
        MYSQLPP_QUERY_THISPTR << std::setprecision(16) <<
                "UPDATE " << table << " SET " << n.equal_list() <<
                " WHERE " << o.equal_list(" AND ", sql_use_compare);
        return *this;
    }

    template <class T>
    Query& insert(const T& v, const std::string& table)
    {
        reset();

        MYSQLPP_QUERY_THISPTR << std::setprecision(16) <<
                "INSERT INTO " << table << " (" <<
                v.field_list() << ") VALUES (" <<
                v.value_list() << ')';
        return *this;
    }

    template <class Iter>
    Query& insert(Iter first, Iter last, const std::string& table)
    {
        reset();
        if (first == last) {
            return *this;    // empty set!
        }

        MYSQLPP_QUERY_THISPTR << std::setprecision(16) <<
                "INSERT INTO " << table << " (" <<
                first->field_list() << ") VALUES (" <<
                first->value_list() << ')';

        Iter it = first + 1;
        while (it != last) {
            MYSQLPP_QUERY_THISPTR << ",(" << it->value_list() << ')';
            ++it;
        }

        return *this;
    }

    template <class T>
    Query& replace(const T& v, const std::string& table)
    {
        reset();

        MYSQLPP_QUERY_THISPTR << std::setprecision(16) <<
                "REPLACE INTO " << table << " (" <<
                v.field_list() << ") VALUES (" << v.value_list() << ')';
        return *this;
    }


also, may be another example of me doing things wrong, but I found I had to
add this

inline int sql_cmp(const mysqlpp::DateTime &a, const mysqlpp::DateTime &b){
    return a.compare(b);
}

to custom.h  (via the perl script) to get the DateTime class to work as a
key field for an SSQLS.


cheers,
Joe


On 04/12/2007, Warren Young <mysqlpp@stripped> wrote:
>
> Joe Hudson wrote:
> >
> > With my template functions, SSQLSes do what I want for now and I've
> written
> > quite a chunk of code that already uses them.
>
> Okay.
>
> I'm still on the fence about whether to accept your patch.  I think my
> problem with it is that it's more of a parallel interface w.r.t existing
> functionality than a true extension to MySQL++.  I think I'm trying to
> find some elegant way in my mind to express the concepts of a default
> table name, per-struct overrides, and per-instance overrides, all in a
> single mechanism.  We've got the first two, but the third seems to
> require a different mechanism, which bugs me.
>
> --
> MySQL++ Mailing List
> For list archives: http://lists.mysql.com/plusplus
> To unsubscribe:
> http://lists.mysql.com/plusplus?unsub=1
>
>


-- 
LIVE MUSIC + OTHER PERFORMANCE ART CHARITY FUNDRAISER
Doors 6.30pm - 1st act 7:30pm,  2nd SUNDAY of EVERY month
@ THE TALKING HEADS, PORTSWOOD Rd, SOUTHAMPTON
£3 entrance: all profits to 2 Local Charities. SCRATCH and HAMPSHIRE
AUTISTIC SOCIETY
-----------------------------------------------------------------------------------------------


Contact joe.hudson@stripped for more info.
-------------------------------------------------------
---------------------------------------
Visit http://www.myspace.com/littlecog  for latest details, to post new
events or volunteer for future community action events.

Thread
linking mysql++ 2.3.2Joe Hudson1 Dec
  • Re: linking mysql++ 2.3.2Warren Young1 Dec
    • Re: linking mysql++ 2.3.2Joe Hudson1 Dec
      • Re: linking mysql++ 2.3.2Warren Young3 Dec
        • Re: linking mysql++ 2.3.2Joe Hudson4 Dec
          • Re: linking mysql++ 2.3.2Warren Young4 Dec
            • Re: linking mysql++ 2.3.2Joe Hudson7 Dec
              • Re: linking mysql++ 2.3.2Warren Young7 Dec