首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sqflite插入返回零

sqflite插入返回零
EN

Stack Overflow用户
提问于 2022-05-05 08:46:02
回答 1查看 188关注 0票数 0

在其他地方,数据库操作工作得很好,但是在一个特定的表中,insert操作返回0,不插入任何行,也不会产生错误。

我使用的是sqflite: ^2.0.2+1版本。sale.serial = await db.insert(tableSale, sale.toMap());

表创建代码是:

代码语言:javascript
复制
db.execute('''
          create table $tableSale ( 
            $columnSerial integer primary key autoincrement, 
            $columnFbId integer not null,
            $columnBillID integer not null,
            $columnAmount real not null,
            $columnBalance real DEFAULT 0,
            $columnDiscount real DEFAULT 0,
            $columnFreight real DEFAULT 0,
            $columnAddedBy text not null,
            $columnDate text not null,
            $columnDateApproved integer,
            $columnFromPhone text not null,
            $columnToPhone text not null,
            $columnNote text,
            $columnDetail text,
            $columnItems text,
            UNIQUE($columnBillID) ON CONFLICT IGNORE)
          ''');
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-05 17:54:38

我发现了问题。表创建代码中有UNIQUE($columnFbId) ON CONFLICT IGNORE),在冲突情况下,插入操作被忽略,没有颤振或数据库错误。

我通过添加ConflictAlgorithm发现了这一点。代码是:sale.serial = await db.insert(tableSale, sale.toMap(), conflictAlgorithm: ConflictAlgorithm.fail)

谢谢@nitishk72 72的提示。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72124378

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档