Code Monkey home page Code Monkey logo

Comments (9)

RingoD avatar RingoD commented on May 18, 2024 4

WCDB插入默认是使用不自增的,如需自增需设置isAutoIncrement,参考sample中的WCTSampleConvenient

WCTSampleConvenient *object = [[WCTSampleConvenient alloc] init];
object.isAutoIncrement = YES;
object.stringValue = @"Insert auto increment";

from wcdb.

RingoD avatar RingoD commented on May 18, 2024 2

@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.

alexlee002 avatar alexlee002 commented on May 18, 2024

这里应该是个bug, 如果某个字段是int类型, 并且设置成primary key, 那么, 按照sqlite的文档, 它其实就是rowid的别名。 在生成insert语句的时候, 不应该把这个字段放到插入字段列表里边。(之前在做patchwork 实现ActiveRecord的时候就踩过这个坑)

另外, 想请问一下@RingoD , WCDB是不是已经在微信上广泛使用了?

from wcdb.

RingoD avatar RingoD commented on May 18, 2024

@alexlee002 int类型的主键是rowid的别名,但没有“ 不应该把这个字段放到插入字段列表里边”这个说法。

from wcdb.

alexlee002 avatar alexlee002 commented on May 18, 2024

@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.

alexlee002 avatar alexlee002 commented on May 18, 2024

@RingoD 恩, 我之前没仔细看代码, 没有注意isAutoIncrement这个属性。

from wcdb.

boboxu avatar boboxu commented on May 18, 2024

我也看到了。亲测 可用。 @RingoD @alexlee002

from wcdb.

zedzhao avatar zedzhao commented on May 18, 2024

测了下 将一个int型的数据用WCDB_PRIMARY_ASC_AUTO_INCREMENT 设置为主键后, 只要是insert数据 该字段就会一直增长,删除掉之前的数据 插入新数据时仍然是从之前最大的 rowID开始增长,这样的话如果这个id值达到了最大值根据sqlite的文档就没办法再插入新数据了?

from wcdb.

RingoD avatar RingoD commented on May 18, 2024

@zedzhao Don't reply here. Open your own issue.

from wcdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.