How to avoid SOCI Error: Null value fetched and no indicator defined

How to avoid SOCI Error: Null value fetched and no indicator defined

当我的应用程序使用 SOCI 从 Oracle 获取数据时,我得到 "Error: Null value fetched and no indicator defined"。

如何避免?

try
    {
        statement st = (sql.prepare <<
            "SELECT COLUMN1, COLUMN2, COLUMN3, COLUMN4, COLUMN5, COLUMN6 FROM MY_TABLE"
                into(column_value1),
                into(column_value2),
                into(column_value3),
                into(column_value4),
                into(column_value5),
                into(column_value6)
                );
        st.execute();
        while (st.fetch())
        {
            cout << column_value1.c_str() << " : " << endl;
        }
    }

根据文档(http://soci.sourceforge.net/doc/3.2/),需要提供一个指示器来检查查询的列是否为空或正确读取。

string phone;
indicator ind;
sql << "select phone from phonebook where name = :name",
    into(phone, ind), use(name);

if (ind == i_ok)
{
    cout << "The phone number is " << phone << '\n';
}
else
{
    cout << "There is no phone for " << name << '\n';
}

指标具有以下值。

// the enum type for indicator variables
enum indicator { i_ok, i_null, i_truncated };