sqlite_orm icon indicating copy to clipboard operation
sqlite_orm copied to clipboard

Inserting primary key value is ignored

Open paulhilbert opened this issue 8 years ago • 2 comments

When inserting values into a simple two-column storage the primary key gets ignored as if set to null:

#include <iostream>
#include "sqlite_orm.h"

struct ipv4 {
    uint64_t ip;
    std::string name;
};

using namespace sqlite_orm;

int main (int argc, char const* argv[]) {
    auto storage = make_storage("db.sqlite",
        make_table("ipv4",
            make_column("ip", &ipv4::ip, primary_key()),
            make_column("name", &ipv4::name)
        )
    );

    ipv4 test_add{18ul, "test"};

    auto test_id = storage.insert(test_add);
    std::cout << "id: " << test_id << "\n";
}

This results in a row "1|test".

paulhilbert avatar Mar 08 '18 15:03 paulhilbert

use replace instead

fnc12 avatar Mar 08 '18 15:03 fnc12

Works as intended. Thank you!

paulhilbert avatar Mar 08 '18 15:03 paulhilbert