Skip to content

primary key not working. Adds duplicate values. #1292

Open

Description

@carper7

I have the following code but it is not working:

alasql("create INDEXEDDB DATABASE if not exists localdb_db");
alasql("ATTACH INDEXEDDB DATABASE localdb_db; \ CREATE TABLE if not exists localdb_db.db_Settings(**setting varchar(50) Primary Key**, `value` varchar(300), storeInSession varchar(1) DEFAULT 'N')", function(res) {
             console.log(res + " :indexedDB");	
 });
		 
alasql("ATTACH INDEXEDDB DATABASE localdb_db; \ INSERT INTO localdb_db.db_Settings (setting,`value` ) values(?,?)", ["domain", "http"], function(res) {
             console.log(res);	
 });
         
alasql("ATTACH INDEXEDDB DATABASE localdb_db; \ INSERT INTO localkics_db.db_Settings (setting, `value` ) values(?,?)", ["domain", "https"], function(res) {
             //console.log(res);	
 });
		 
alasql("ATTACH INDEXEDDB DATABASE localdb_db; \ SELECT * FROM localdb_db.db_Settings", [], function(res) {
             console.log(res);
         });

It does not create the primary key [setting] therefore it allows me to insert duplicates. For some reason it is automatically creating its own key. I even tried by using string instead of varchar.

'#' |Key | Value
0 | 1 | {setting: “domain”, value: ”http”}
1 | 2 | {setting: “domain”, value: ”https”}

Could you please advise me what to do here?

Thank You.

Activity

  1. carper7 commented on Feb 9, 2021

    @carper7
    Author

    Ok. I kind of made it work; but now the issue is I can't see the store nor the data.

    alasql("create INDEXEDDB DATABASE if not exists localdb_db");
    alasql("ATTACH INDEXEDDB DATABASE localdb_db; CREATE TABLE db_Settings(setting varchar(50) Primary Key, `value` 
     varchar(300), storeInSession varchar(1) DEFAULT 'N');");
    		 
     alasql("ATTACH INDEXEDDB DATABASE localdb_db; INSERT INTO db_Settings (setting,`value` ) values(?,?),(?,?);", ["domain", "http","domain", "https"], function(res) {
                 console.log(res);	
     });
    

    Also I noticed that for this to work, I have to pass all the values in on e single insert so it would check for the constrains.

  2. gimnathperera commented on Jul 1, 2023

    @gimnathperera

    Hi @mathiasrw can you assign this to me ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions