SQLite where integer not returning
There are numerous other questions with similar problems and after going through them I've been unsuccessful in getting/understanding why when I try to query on an integer column it is not doing any filtering.
The query is:
String selectRoadsSQL = "SELECT ID, Lat, Lng, Active, DateCreated, DateLastUsed FROM roads WHERE Active = ?"
This is executed by this piece of code
Cursor cursor = db.rawQuery(selectRoadsSQL, new String { Integer.toString(status)});
while (cursor.moveToNext()) {
String active = cursor.getString(cursor.getColumnIndex(DataTables.Roads.Active));
Log.e("Test", active);
}
status is an integer that is passed and it is either 0 or 1. In this scenario I am passing a 1.
Regardless if I pass a 0 or 1 I always get back all rows. The actual DB itself shows some rows with a 0 and others with a 1.
Even if I change the ? to a 1 so the query contains the actual integer value it still returns all rows.
I would expect to only get back the results with a "1" in the Active column.
I'm totally stumped. Thank you.
android
|
show 5 more comments
There are numerous other questions with similar problems and after going through them I've been unsuccessful in getting/understanding why when I try to query on an integer column it is not doing any filtering.
The query is:
String selectRoadsSQL = "SELECT ID, Lat, Lng, Active, DateCreated, DateLastUsed FROM roads WHERE Active = ?"
This is executed by this piece of code
Cursor cursor = db.rawQuery(selectRoadsSQL, new String { Integer.toString(status)});
while (cursor.moveToNext()) {
String active = cursor.getString(cursor.getColumnIndex(DataTables.Roads.Active));
Log.e("Test", active);
}
status is an integer that is passed and it is either 0 or 1. In this scenario I am passing a 1.
Regardless if I pass a 0 or 1 I always get back all rows. The actual DB itself shows some rows with a 0 and others with a 1.
Even if I change the ? to a 1 so the query contains the actual integer value it still returns all rows.
I would expect to only get back the results with a "1" in the Active column.
I'm totally stumped. Thank you.
android
can you post the create table string you used please? is there a chance you used a text instead of an integer in Active field?
– Fabio
Nov 15 '18 at 16:31
There isn't a create table string. This is file that is brought in and copied over. The screen shot of the table content is from Stetho.
– Micah Montoya
Nov 15 '18 at 16:34
This is file that is brought in and copied over where is it copied over?
– forpas
Nov 15 '18 at 16:37
@forpas .db file put into assets folder and then code copies it to the package data location upon apk installation.
– Micah Montoya
Nov 15 '18 at 16:40
Are you totally sure that theActive
column is actually defined as an integer and not as a string?
– Fantômas
Nov 15 '18 at 16:42
|
show 5 more comments
There are numerous other questions with similar problems and after going through them I've been unsuccessful in getting/understanding why when I try to query on an integer column it is not doing any filtering.
The query is:
String selectRoadsSQL = "SELECT ID, Lat, Lng, Active, DateCreated, DateLastUsed FROM roads WHERE Active = ?"
This is executed by this piece of code
Cursor cursor = db.rawQuery(selectRoadsSQL, new String { Integer.toString(status)});
while (cursor.moveToNext()) {
String active = cursor.getString(cursor.getColumnIndex(DataTables.Roads.Active));
Log.e("Test", active);
}
status is an integer that is passed and it is either 0 or 1. In this scenario I am passing a 1.
Regardless if I pass a 0 or 1 I always get back all rows. The actual DB itself shows some rows with a 0 and others with a 1.
Even if I change the ? to a 1 so the query contains the actual integer value it still returns all rows.
I would expect to only get back the results with a "1" in the Active column.
I'm totally stumped. Thank you.
android
There are numerous other questions with similar problems and after going through them I've been unsuccessful in getting/understanding why when I try to query on an integer column it is not doing any filtering.
The query is:
String selectRoadsSQL = "SELECT ID, Lat, Lng, Active, DateCreated, DateLastUsed FROM roads WHERE Active = ?"
This is executed by this piece of code
Cursor cursor = db.rawQuery(selectRoadsSQL, new String { Integer.toString(status)});
while (cursor.moveToNext()) {
String active = cursor.getString(cursor.getColumnIndex(DataTables.Roads.Active));
Log.e("Test", active);
}
status is an integer that is passed and it is either 0 or 1. In this scenario I am passing a 1.
Regardless if I pass a 0 or 1 I always get back all rows. The actual DB itself shows some rows with a 0 and others with a 1.
Even if I change the ? to a 1 so the query contains the actual integer value it still returns all rows.
I would expect to only get back the results with a "1" in the Active column.
I'm totally stumped. Thank you.
android
android
edited Nov 15 '18 at 16:40
Fantômas
32.8k156390
32.8k156390
asked Nov 15 '18 at 16:18
Micah MontoyaMicah Montoya
3461313
3461313
can you post the create table string you used please? is there a chance you used a text instead of an integer in Active field?
– Fabio
Nov 15 '18 at 16:31
There isn't a create table string. This is file that is brought in and copied over. The screen shot of the table content is from Stetho.
– Micah Montoya
Nov 15 '18 at 16:34
This is file that is brought in and copied over where is it copied over?
– forpas
Nov 15 '18 at 16:37
@forpas .db file put into assets folder and then code copies it to the package data location upon apk installation.
– Micah Montoya
Nov 15 '18 at 16:40
Are you totally sure that theActive
column is actually defined as an integer and not as a string?
– Fantômas
Nov 15 '18 at 16:42
|
show 5 more comments
can you post the create table string you used please? is there a chance you used a text instead of an integer in Active field?
– Fabio
Nov 15 '18 at 16:31
There isn't a create table string. This is file that is brought in and copied over. The screen shot of the table content is from Stetho.
– Micah Montoya
Nov 15 '18 at 16:34
This is file that is brought in and copied over where is it copied over?
– forpas
Nov 15 '18 at 16:37
@forpas .db file put into assets folder and then code copies it to the package data location upon apk installation.
– Micah Montoya
Nov 15 '18 at 16:40
Are you totally sure that theActive
column is actually defined as an integer and not as a string?
– Fantômas
Nov 15 '18 at 16:42
can you post the create table string you used please? is there a chance you used a text instead of an integer in Active field?
– Fabio
Nov 15 '18 at 16:31
can you post the create table string you used please? is there a chance you used a text instead of an integer in Active field?
– Fabio
Nov 15 '18 at 16:31
There isn't a create table string. This is file that is brought in and copied over. The screen shot of the table content is from Stetho.
– Micah Montoya
Nov 15 '18 at 16:34
There isn't a create table string. This is file that is brought in and copied over. The screen shot of the table content is from Stetho.
– Micah Montoya
Nov 15 '18 at 16:34
This is file that is brought in and copied over where is it copied over?
– forpas
Nov 15 '18 at 16:37
This is file that is brought in and copied over where is it copied over?
– forpas
Nov 15 '18 at 16:37
@forpas .db file put into assets folder and then code copies it to the package data location upon apk installation.
– Micah Montoya
Nov 15 '18 at 16:40
@forpas .db file put into assets folder and then code copies it to the package data location upon apk installation.
– Micah Montoya
Nov 15 '18 at 16:40
Are you totally sure that the
Active
column is actually defined as an integer and not as a string?– Fantômas
Nov 15 '18 at 16:42
Are you totally sure that the
Active
column is actually defined as an integer and not as a string?– Fantômas
Nov 15 '18 at 16:42
|
show 5 more comments
0
active
oldest
votes
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%2f53323689%2fsqlite-where-integer-not-returning%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53323689%2fsqlite-where-integer-not-returning%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
can you post the create table string you used please? is there a chance you used a text instead of an integer in Active field?
– Fabio
Nov 15 '18 at 16:31
There isn't a create table string. This is file that is brought in and copied over. The screen shot of the table content is from Stetho.
– Micah Montoya
Nov 15 '18 at 16:34
This is file that is brought in and copied over where is it copied over?
– forpas
Nov 15 '18 at 16:37
@forpas .db file put into assets folder and then code copies it to the package data location upon apk installation.
– Micah Montoya
Nov 15 '18 at 16:40
Are you totally sure that the
Active
column is actually defined as an integer and not as a string?– Fantômas
Nov 15 '18 at 16:42