Comments (9)
WCDB插入默认是使用不自增的,如需自增需设置isAutoIncrement,参考sample中的WCTSampleConvenient
WCTSampleConvenient *object = [[WCTSampleConvenient alloc] init];
object.isAutoIncrement = YES;
object.stringValue = @"Insert auto increment";
from wcdb.
@alexlee002 这是两种不同的用法
第一种对应WCDB内的:
/*
INSERT INTO myTable(intValue, stringValue) VALUES(1, "aaa");
*/
WCTSampleConvenient *object = [[WCTSampleConvenient alloc] init];
object.intValue = 1;
object.stringValue = @"aaa";
[database insertObject:object into:@"myTable"];
第二种对应:
/*
INSERT INTO myTable(intValue, stringValue) VALUES(NULL, "aaa");
*/
WCTSampleConvenient *object = [[WCTSampleConvenient alloc] init];
object.isAutoIncrement = YES;
object.stringValue = @"aaa";
[database insertObject:object into:@"myTable"];
两种都是WCDB和sqlite正确的用法,不是bug
from wcdb.
这里应该是个bug, 如果某个字段是int类型, 并且设置成primary key, 那么, 按照sqlite的文档, 它其实就是rowid的别名。 在生成insert语句的时候, 不应该把这个字段放到插入字段列表里边。(之前在做patchwork 实现ActiveRecord的时候就踩过这个坑)
另外, 想请问一下@RingoD , WCDB是不是已经在微信上广泛使用了?
from wcdb.
@alexlee002 int类型的主键是rowid的别名,但没有“ 不应该把这个字段放到插入字段列表里边”这个说法。
from wcdb.
@RingoD 可能我的表述不够清楚。 我的意思是, 如果字段 col_a是一个自增int主键字段, 那么如果执行下边的sql:
INSERT INTO table (col_a, col_b) VALUES(1, 'aaa');
那么, sqlite不会忽略自增设置, 直接用sql中指定的值。
所以, 如果需要让sqlite按照自增来自动设值, 那么sql应该是这样:
INSERT INTO table (col_b) VALUES('aaa');
from wcdb.
@RingoD 恩, 我之前没仔细看代码, 没有注意isAutoIncrement
这个属性。
from wcdb.
我也看到了。亲测 可用。 @RingoD @alexlee002
from wcdb.
测了下 将一个int型的数据用WCDB_PRIMARY_ASC_AUTO_INCREMENT 设置为主键后, 只要是insert数据 该字段就会一直增长,删除掉之前的数据 插入新数据时仍然是从之前最大的 rowID开始增长,这样的话如果这个id值达到了最大值根据sqlite的文档就没办法再插入新数据了?
from wcdb.
@zedzhao Don't reply here. Open your own issue.
from wcdb.
Related Issues (20)
- 我这边测试WCDB比FMDB慢了很多,请帮我看下是不是什么优化项没有设置 HOT 3
- 如何查看WCDB依赖的WCDBOptimizedSQLCipher版本对应的tag / 分支 / commit id HOT 2
- 运行在 iOS 17 真机上,Core.cpp 库 Crash HOT 4
- 为什么要设置SQLITE_MAX_VARIABLE_NUMBER为99 HOT 3
- 安卓的全文检索什么时候更新? HOT 1
- 'WCDB.swift', '~> 2.0.3' 真机运行12.5.5创建database时崩溃 HOT 2
- iOS 扩展应用,在APP Group共享文件夹,无法创建数据库 HOT 8
- WCDBSwift2.0.4无法创建虚拟表 HOT 2
- Xcode 15 crash HOT 3
- Cocoapods导入后 死活找不到头文件。 HOT 1
- Swift WCDB Debug模式下初始化crash HOT 3
- Build failed HOT 2
- how two write sql join on expression with winQ HOT 1
- WCDBOptimizedSQLCipher 无法下载 HOT 1
- 数据model可以同时遵循Codable和TableCodable么? HOT 1
- > ![image](https://user-images.githubusercontent.com/5007022/270093463-56885d67-5d82-4d58-84ac-b3d5d49f08b6.png)
- Database close HOT 1
- 关键字查找 HOT 4
- iOS12系列机型,app启动就carsh HOT 2
- new java version... HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wcdb.