Giter Site home page Giter Site logo

Comments (2)

asmwarrior avatar asmwarrior commented on September 24, 2024

It looks like I can't compare the if (row.timestamp == std::tm()), so I change the code like below:

bool IsTmEmpty(const std::tm& time) {
    return (time.tm_year == 0 &&
            time.tm_mon == 0 &&
            time.tm_mday == 0 &&
            time.tm_hour == 0 &&
            time.tm_min == 0 &&
            time.tm_sec == 0);
}

And later, I use such code:

    static void to_base(const MyClass& row, values& v, indicator& ind)
    {
        v.set("id", row.id);
        
        // check to see whether the row.timestamp is an empty null "std::tm", if true, set the field value as NULL
        if ( IsTmEmpty(row.timestamp) )
        {
            v.set("timestamp", soci::i_null);
        }
        else
        {
            v.set("timestamp", row.timestamp);
        }

        ind = i_ok;
    }

But sadly, the above code still can't be built. The issue happens here: v.set("timestamp", soci::i_null);, I'm currently don't know how to use the null indicator.

Thanks.

from soci.

asmwarrior avatar asmwarrior commented on September 24, 2024

OK, I think I found the solution, it is inside the document:

See here:

https://github.com/SOCI/soci/blob/884808c294e4809064650f3e5aed9102d8a68d56/docs/types.md?plain=1#L303C1-L303C73

So, the final code which works is like below:

    static void to_base(const MyClass& row, values& v, indicator& ind)
    {
        v.set("id", row.id);

        // check to see whether the row.timestamp is an empty null "std::tm", if true, set the field value as NULL
        v.set("timestamp", row.timestamp, IsTmEmpty(row.timestamp) ? i_null : i_ok);

        ind = i_ok;
    }

from soci.

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.