Giter Club home page Giter Club logo

Comments (11)

rbock avatar rbock commented on July 22, 2024

Ooops! Thanks for the hint! The documentation is outdated (I'll update asap).

Please try

s.where.add(true).

See also tests/Select.cpp

from sqlpp11.

rbock avatar rbock commented on July 22, 2024

Updated the documentation.

from sqlpp11.

slepasteur avatar slepasteur commented on July 22, 2024

I just found the test/Select.cpp and the solution you just pointed out. :)
I also had problems with dynamic_offset and dynamic_limit but solved them using the new syntax:

s.offset.set(start)
s.limit.set(count)

However I still have problems with the order_by statement. My query looks like this:

auto s = dynamic_select(m_db, all_of(sql_entry))
    .from(entry)
    .order_by(entry.time.desc())
    .dynamic_where().dynamic_offset().dynamic_limit();

Any idea on what I've done wrong?

from sqlpp11.

slepasteur avatar slepasteur commented on July 22, 2024

Hum it compiles with the dynamic_order_by, I suppose it is not possible to use static order_by on a dynamic_select?

from sqlpp11.

rbock avatar rbock commented on July 22, 2024

Thanks for the report. That's a bug, it also affects several other clauses.

Fixed in develop.

from sqlpp11.

slepasteur avatar slepasteur commented on July 22, 2024

Oh great thanks. BTW it would be great to have a simple doc on dynamic insert. I managed to use them but had some trouble to find that I needed to use insert_list.add.

from sqlpp11.

rbock avatar rbock commented on July 22, 2024

Good point :-)

In that context: It would be great if you could send a short description of how and why you use the dynamic versions of the queries.

from sqlpp11.

slepasteur avatar slepasteur commented on July 22, 2024

Well it's pretty simple. I have a class Entry with some boost::optional data in it. I insert the Entry instances in a table but I want to insert the optional data only if they are present. It looks like that:

class Entry
{
    //...
    int64_t time;
    boost::optional<std::string> data;
}

void insert(const Entry& entry)
{
    auto i = dynamic_insert_into(m_db, sql_entry).dynamic_set(
        sql_entry.time = entry.time
    );
    if (entry.data())
    {
        i.insert_list.add(sql_entry.data = entry.data().get());
    }
    m_db(i);
}

from sqlpp11.

slepasteur avatar slepasteur commented on July 22, 2024

I also wanted to limit the number of entries in the table. Therefore I wanted to execute a request looking like that:

delete from entry
where id in (
    select id from entry
    order by entry.time asc
    limit ( 
        select case when count(*) - 800 > 0 then count(*) - 800 else 0 end from entry 
    )
);

However I did not find any IN operator. Is is possible to do something like that with sqlpp11?

(maybe I should have opened a new issue for that...)

from sqlpp11.

rbock avatar rbock commented on July 22, 2024

Yes, please open an new issue about missing documentation. In short, you can do

tab.x.in(1,2,3)
tab.x.in(select(whatever))
tab.x.in(sqlpp::value_list(a_vector_of_values))

from sqlpp11.

rbock avatar rbock commented on July 22, 2024

Fixed dynamic statement issues in release 0.35

from sqlpp11.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.