gpt4 book ai didi

c++ - sqlite 和可能的空值

转载 作者:行者123 更新时间:2023-11-28 00:34:13 24 4
gpt4 key购买 nike

Sqlite3 表有 INT 列,可能有 NULL 值。

我使用以下代码将数据添加到表中:

if ( ptr == NULL )
sqlite3_bind_null(stmt, 5);
else
sqlite3_bind_int64(stmt, 5, ptr->key_session );

然后我用下面的代码取回我的值:

unsigned int key_session = (unsigned int)sqlite3_column_int64(stmt, 0); 

那么,NULL 是什么?表中使用 NULL 的最佳做法是什么?如何检查 NULL?或者在我的 GET 代码中会发生什么 NULL ?

最佳答案

你可以做这个检查:

if (sqlite3_column_type(stmt, 0) == SQLITE_NULL)
...

如果检查成功,则值为NULL;否则,它是一个非空的 int64

关于c++ - sqlite 和可能的空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21604188/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com