I'm using soci to write code to interact with a MySQL db.  I'm trying to
select from a table using a where clause that contains a reference to column
that might be NULL.   I'm trying to use a boost::optional in a use() to
avoid having to write two separate statements:

 

What I want to do:

 

int function(session sql, optional<int> col2Val)

{

    int col1Val;

    sql << "select col1 from table1 where col2 = :col2Val", into (col1Val),
use(col2Val);

    return col1Val;

}

 

What I have to do instead:

 

int function(session sql, optional<int> col2Val)

{

    int col1Val;

    if (col2Val)

        sql << "select col1 from table1 where col2 = :col2Val", into
(col1Val), use(col2Val);

    else

        sql << "select col1 from table1 where col2 is null", into (col1Val);

    return col1Val;

}

 

Is there a way to achieve this more concisely using the optional type?
Thanks.

 

Steve

 

 

Steven L. Elam

Software Engineer

Guided Wave Incorporated

3033 Gold Canal Drive

Rancho Cordova, CA 95670

USA

Tel: +1-916-638 4944 ext 1301

Fax: +1-916-635 8458

Cell: +1-916-365 3148

Email: [email protected]

Web:  <http://www.guided-wave.com/> www.guided-wave.com

cid:[email protected]

An Advanced Company

 

Logo 1 -without Wording <http://www.AdvancedHoldings.com>
www.AdvancedHoldings.com

DISCLAIMER
The information contained in this email, including any attachments, is
confidential and proprietary information of the Advanced Group and intended
solely for use by the addressee.  If you are not the intended recipient, you
are hereby notified that any dissemination, distribution or copying of the
information contained in this email is prohibited.  If you have received
this email in error, please notify the sender immediately by return email
and delete this email from your system.  Any conclusions or opinions
contained in this email are those of the author and do not necessarily
represent those of the Advanced Group. It is the responsibility of the
recipient of this email and its attachments to check for the presence of
viruses.  Advanced Group is not responsible for any damage caused by any
virus transmitted by this email or its attachments.

 

<<image001.png>>

<<image002.jpg>>

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to