Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ionic-cordova-SQLite possible to insert a Array as parameter?

I just wrote a simple function, that creates me a INSERT string out of the input the user has made, so I get something like this(working with ionic btw):

    INSERT INTO people(firstname, lastname) VALUES (??)

Now I would like to use a Array that holds the inputvalues as parameter:

let inputvalues = ["value1", "value2"];
    this.database.executeSql(this.createInserString("people",this.userData), [inputvalues]).then((data) => {
        console.log("INSERTED: " + JSON.stringify(data));
    }, (error) => {
        console.log("ERROR-Insert: " + JSON.stringify(error.err));
    });

Is there a way to implement something like this? (because otherwise I have to type out ever single input values and ... there are a lot ;-( )

Thank you!

like image 311
user3793935 Avatar asked Jun 05 '26 11:06

user3793935


1 Answers

i think you should separate parameters with comma:

INSERT INTO people(firstname, lastname) VALUES (?,?)

and then use the array without "[ ]" since its already an array:

this.database.executeSql(this.createInserString("people",this.userData), inputvalues)
like image 133
Javad Avatar answered Jun 08 '26 10:06

Javad