React native SQLite insert statement not working
I am trying to use SQLite with React native to insert some values into a table
In my main page I am creating the table like so...
db.transaction(tx => {
tx.executeSql(
`create table if not exists puzzles (
id primary key not null,
level int not null,
image varchar(512) NOT NULL,
imageSolution varchar(512) NULL,
puzzleAnswer varchar(16) NULL,
type varchar(16) NULL,
availableLetters varchar(16) NULL,
charactersGiven varchar(4) NULL);`
);
});
In my page component I am trying to insert using the following:
db.transaction(tx => {
for (var puz of puzzlesFiltered) {
tx.executeSql(
`insert into
puzzles (id, image, imageSolution, type, puzzleAnswer, level, charactersGiven, availableLetters)
VALUES (?,?,?,?,?,?,?,?) WHERE NOT EXISTS(SELECT 1 FROM puzzles WHERE id = ${
puz.id
})`,
[
puz.id,
puz.image,
puz.imageSolution,
puz.type,
puz.puzzleAnswer,
puz.level,
puz.charactersGiven,
puz.charactersGiven
],
(tx, results) => {
console.log("Results", results.rowsAffected);
},
(err) => {
console.error(err);
}
);
}
});
I am getting the following error message returned, which I have no idea what it means, can anyone help?
Also, is there a better way to insert an array, rather than looping through each row?
[16:07:09] WebSQLTransaction { "_complete": false, "_error": null,
"_running": true, "_runningTimeout": false, "_sqlQueue": Queue {
"first": undefined,
"last": undefined,
"length": 0, }, "_websqlDatabase": WebSQLDatabase {
"_currentTask": TransactionTask {
"errorCallback": [Function anonymous],
"readOnly": false,
"successCallback": [Function anonymous],
"txnCallback": [Function anonymous],
},
"_db": SQLiteDatabase {
"_closed": false,
"_name": "db.db",
},
"_running": true,
"_txnQueue": Queue {
"first": Object {
"item": TransactionTask {
"errorCallback": [Function anonymous],
"readOnly": false,
"successCallback": [Function anonymous],
"txnCallback": [Function anonymous],
},
},
"last": Object {
"item": TransactionTask {
"errorCallback": [Function anonymous],
"readOnly": false,
"successCallback": [Function anonymous],
"txnCallback": [Function anonymous],
},
},
"length": 1,
},
"version": "1.0", }, }
javascript sqlite react-native
add a comment |
I am trying to use SQLite with React native to insert some values into a table
In my main page I am creating the table like so...
db.transaction(tx => {
tx.executeSql(
`create table if not exists puzzles (
id primary key not null,
level int not null,
image varchar(512) NOT NULL,
imageSolution varchar(512) NULL,
puzzleAnswer varchar(16) NULL,
type varchar(16) NULL,
availableLetters varchar(16) NULL,
charactersGiven varchar(4) NULL);`
);
});
In my page component I am trying to insert using the following:
db.transaction(tx => {
for (var puz of puzzlesFiltered) {
tx.executeSql(
`insert into
puzzles (id, image, imageSolution, type, puzzleAnswer, level, charactersGiven, availableLetters)
VALUES (?,?,?,?,?,?,?,?) WHERE NOT EXISTS(SELECT 1 FROM puzzles WHERE id = ${
puz.id
})`,
[
puz.id,
puz.image,
puz.imageSolution,
puz.type,
puz.puzzleAnswer,
puz.level,
puz.charactersGiven,
puz.charactersGiven
],
(tx, results) => {
console.log("Results", results.rowsAffected);
},
(err) => {
console.error(err);
}
);
}
});
I am getting the following error message returned, which I have no idea what it means, can anyone help?
Also, is there a better way to insert an array, rather than looping through each row?
[16:07:09] WebSQLTransaction { "_complete": false, "_error": null,
"_running": true, "_runningTimeout": false, "_sqlQueue": Queue {
"first": undefined,
"last": undefined,
"length": 0, }, "_websqlDatabase": WebSQLDatabase {
"_currentTask": TransactionTask {
"errorCallback": [Function anonymous],
"readOnly": false,
"successCallback": [Function anonymous],
"txnCallback": [Function anonymous],
},
"_db": SQLiteDatabase {
"_closed": false,
"_name": "db.db",
},
"_running": true,
"_txnQueue": Queue {
"first": Object {
"item": TransactionTask {
"errorCallback": [Function anonymous],
"readOnly": false,
"successCallback": [Function anonymous],
"txnCallback": [Function anonymous],
},
},
"last": Object {
"item": TransactionTask {
"errorCallback": [Function anonymous],
"readOnly": false,
"successCallback": [Function anonymous],
"txnCallback": [Function anonymous],
},
},
"length": 1,
},
"version": "1.0", }, }
javascript sqlite react-native
add a comment |
I am trying to use SQLite with React native to insert some values into a table
In my main page I am creating the table like so...
db.transaction(tx => {
tx.executeSql(
`create table if not exists puzzles (
id primary key not null,
level int not null,
image varchar(512) NOT NULL,
imageSolution varchar(512) NULL,
puzzleAnswer varchar(16) NULL,
type varchar(16) NULL,
availableLetters varchar(16) NULL,
charactersGiven varchar(4) NULL);`
);
});
In my page component I am trying to insert using the following:
db.transaction(tx => {
for (var puz of puzzlesFiltered) {
tx.executeSql(
`insert into
puzzles (id, image, imageSolution, type, puzzleAnswer, level, charactersGiven, availableLetters)
VALUES (?,?,?,?,?,?,?,?) WHERE NOT EXISTS(SELECT 1 FROM puzzles WHERE id = ${
puz.id
})`,
[
puz.id,
puz.image,
puz.imageSolution,
puz.type,
puz.puzzleAnswer,
puz.level,
puz.charactersGiven,
puz.charactersGiven
],
(tx, results) => {
console.log("Results", results.rowsAffected);
},
(err) => {
console.error(err);
}
);
}
});
I am getting the following error message returned, which I have no idea what it means, can anyone help?
Also, is there a better way to insert an array, rather than looping through each row?
[16:07:09] WebSQLTransaction { "_complete": false, "_error": null,
"_running": true, "_runningTimeout": false, "_sqlQueue": Queue {
"first": undefined,
"last": undefined,
"length": 0, }, "_websqlDatabase": WebSQLDatabase {
"_currentTask": TransactionTask {
"errorCallback": [Function anonymous],
"readOnly": false,
"successCallback": [Function anonymous],
"txnCallback": [Function anonymous],
},
"_db": SQLiteDatabase {
"_closed": false,
"_name": "db.db",
},
"_running": true,
"_txnQueue": Queue {
"first": Object {
"item": TransactionTask {
"errorCallback": [Function anonymous],
"readOnly": false,
"successCallback": [Function anonymous],
"txnCallback": [Function anonymous],
},
},
"last": Object {
"item": TransactionTask {
"errorCallback": [Function anonymous],
"readOnly": false,
"successCallback": [Function anonymous],
"txnCallback": [Function anonymous],
},
},
"length": 1,
},
"version": "1.0", }, }
javascript sqlite react-native
I am trying to use SQLite with React native to insert some values into a table
In my main page I am creating the table like so...
db.transaction(tx => {
tx.executeSql(
`create table if not exists puzzles (
id primary key not null,
level int not null,
image varchar(512) NOT NULL,
imageSolution varchar(512) NULL,
puzzleAnswer varchar(16) NULL,
type varchar(16) NULL,
availableLetters varchar(16) NULL,
charactersGiven varchar(4) NULL);`
);
});
In my page component I am trying to insert using the following:
db.transaction(tx => {
for (var puz of puzzlesFiltered) {
tx.executeSql(
`insert into
puzzles (id, image, imageSolution, type, puzzleAnswer, level, charactersGiven, availableLetters)
VALUES (?,?,?,?,?,?,?,?) WHERE NOT EXISTS(SELECT 1 FROM puzzles WHERE id = ${
puz.id
})`,
[
puz.id,
puz.image,
puz.imageSolution,
puz.type,
puz.puzzleAnswer,
puz.level,
puz.charactersGiven,
puz.charactersGiven
],
(tx, results) => {
console.log("Results", results.rowsAffected);
},
(err) => {
console.error(err);
}
);
}
});
I am getting the following error message returned, which I have no idea what it means, can anyone help?
Also, is there a better way to insert an array, rather than looping through each row?
[16:07:09] WebSQLTransaction { "_complete": false, "_error": null,
"_running": true, "_runningTimeout": false, "_sqlQueue": Queue {
"first": undefined,
"last": undefined,
"length": 0, }, "_websqlDatabase": WebSQLDatabase {
"_currentTask": TransactionTask {
"errorCallback": [Function anonymous],
"readOnly": false,
"successCallback": [Function anonymous],
"txnCallback": [Function anonymous],
},
"_db": SQLiteDatabase {
"_closed": false,
"_name": "db.db",
},
"_running": true,
"_txnQueue": Queue {
"first": Object {
"item": TransactionTask {
"errorCallback": [Function anonymous],
"readOnly": false,
"successCallback": [Function anonymous],
"txnCallback": [Function anonymous],
},
},
"last": Object {
"item": TransactionTask {
"errorCallback": [Function anonymous],
"readOnly": false,
"successCallback": [Function anonymous],
"txnCallback": [Function anonymous],
},
},
"length": 1,
},
"version": "1.0", }, }
javascript sqlite react-native
javascript sqlite react-native
asked Nov 25 '18 at 16:12
user3284707user3284707
5361616
5361616
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I'm not sure your query is supported by SQLite.
You could try something like:
INSERT INTO puzzles
(id, image, imageSolution, type, puzzleAnswer, level, charactersGiven, availableLetters)
SELECT ?,?,?,?,?,?,?,?
WHERE NOT EXISTS(SELECT 1 FROM puzzles WHERE id = ${puz.id})
1
Fantastic that solved it first attempt!
– user3284707
Nov 25 '18 at 16:32
I'm glad it works. :)
– Pragmateek
Nov 25 '18 at 16:33
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53469376%2freact-native-sqlite-insert-statement-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm not sure your query is supported by SQLite.
You could try something like:
INSERT INTO puzzles
(id, image, imageSolution, type, puzzleAnswer, level, charactersGiven, availableLetters)
SELECT ?,?,?,?,?,?,?,?
WHERE NOT EXISTS(SELECT 1 FROM puzzles WHERE id = ${puz.id})
1
Fantastic that solved it first attempt!
– user3284707
Nov 25 '18 at 16:32
I'm glad it works. :)
– Pragmateek
Nov 25 '18 at 16:33
add a comment |
I'm not sure your query is supported by SQLite.
You could try something like:
INSERT INTO puzzles
(id, image, imageSolution, type, puzzleAnswer, level, charactersGiven, availableLetters)
SELECT ?,?,?,?,?,?,?,?
WHERE NOT EXISTS(SELECT 1 FROM puzzles WHERE id = ${puz.id})
1
Fantastic that solved it first attempt!
– user3284707
Nov 25 '18 at 16:32
I'm glad it works. :)
– Pragmateek
Nov 25 '18 at 16:33
add a comment |
I'm not sure your query is supported by SQLite.
You could try something like:
INSERT INTO puzzles
(id, image, imageSolution, type, puzzleAnswer, level, charactersGiven, availableLetters)
SELECT ?,?,?,?,?,?,?,?
WHERE NOT EXISTS(SELECT 1 FROM puzzles WHERE id = ${puz.id})
I'm not sure your query is supported by SQLite.
You could try something like:
INSERT INTO puzzles
(id, image, imageSolution, type, puzzleAnswer, level, charactersGiven, availableLetters)
SELECT ?,?,?,?,?,?,?,?
WHERE NOT EXISTS(SELECT 1 FROM puzzles WHERE id = ${puz.id})
answered Nov 25 '18 at 16:29
PragmateekPragmateek
9,26685488
9,26685488
1
Fantastic that solved it first attempt!
– user3284707
Nov 25 '18 at 16:32
I'm glad it works. :)
– Pragmateek
Nov 25 '18 at 16:33
add a comment |
1
Fantastic that solved it first attempt!
– user3284707
Nov 25 '18 at 16:32
I'm glad it works. :)
– Pragmateek
Nov 25 '18 at 16:33
1
1
Fantastic that solved it first attempt!
– user3284707
Nov 25 '18 at 16:32
Fantastic that solved it first attempt!
– user3284707
Nov 25 '18 at 16:32
I'm glad it works. :)
– Pragmateek
Nov 25 '18 at 16:33
I'm glad it works. :)
– Pragmateek
Nov 25 '18 at 16:33
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53469376%2freact-native-sqlite-insert-statement-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown