4

当我的应用程序使用 SOCI 从 Oracle 获取数据时,我收到“错误:已获取空值且未定义指示符”。

我怎样才能避免它?

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;
        }
    }
4

1 回答 1

4

从文档(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 };
于 2015-12-17T07:09:38.067 回答