Is it possible to use StringFormat or Constant Variable in android Room Query
I want to query the user associations list with the following room query using public constant variable Association.MEMBER_STATUS_APPROVED.
@Query("SELECT * FROM Association WHERE memberStatus = " + Association.MEMBER_STATUS_APPROVED)
LiveData<List<Association>> loadUserAssociations();
But, room gives me [SQLITE_ERROR] when build.
It is possible to re-write that query by replacing the constant variable with parameter like the following.
@Query("SELECT * FROM Association WHERE memberStatus = :statusApproved")
LiveData<List<Association>> loadUserAssociations(String statusApproved);
I would like to know that does Room support such kind of string concatenation or String Format? (or) May be I missing something?

add a comment |
I want to query the user associations list with the following room query using public constant variable Association.MEMBER_STATUS_APPROVED.
@Query("SELECT * FROM Association WHERE memberStatus = " + Association.MEMBER_STATUS_APPROVED)
LiveData<List<Association>> loadUserAssociations();
But, room gives me [SQLITE_ERROR] when build.
It is possible to re-write that query by replacing the constant variable with parameter like the following.
@Query("SELECT * FROM Association WHERE memberStatus = :statusApproved")
LiveData<List<Association>> loadUserAssociations(String statusApproved);
I would like to know that does Room support such kind of string concatenation or String Format? (or) May be I missing something?

the 2nd one should work.. is there any error?
– DKV
Nov 20 '18 at 5:42
Yes, @DKV. The 2nd one works. But, I prefer the 1st one and I just want to know does Room support such kind of string concatenation or string format.
– Toe Lie
Nov 20 '18 at 5:47
No, it's not possible with first type.
– Jeel Vankhede
Nov 20 '18 at 5:49
Thanks @JeelVankhede. I think Room should support like that :-D How do you think? :-)
– Toe Lie
Nov 20 '18 at 5:56
No, actually it's not fault of ROOM, but you can't pass variables toAnnotations
it must be static final value.
– Jeel Vankhede
Nov 20 '18 at 6:06
add a comment |
I want to query the user associations list with the following room query using public constant variable Association.MEMBER_STATUS_APPROVED.
@Query("SELECT * FROM Association WHERE memberStatus = " + Association.MEMBER_STATUS_APPROVED)
LiveData<List<Association>> loadUserAssociations();
But, room gives me [SQLITE_ERROR] when build.
It is possible to re-write that query by replacing the constant variable with parameter like the following.
@Query("SELECT * FROM Association WHERE memberStatus = :statusApproved")
LiveData<List<Association>> loadUserAssociations(String statusApproved);
I would like to know that does Room support such kind of string concatenation or String Format? (or) May be I missing something?

I want to query the user associations list with the following room query using public constant variable Association.MEMBER_STATUS_APPROVED.
@Query("SELECT * FROM Association WHERE memberStatus = " + Association.MEMBER_STATUS_APPROVED)
LiveData<List<Association>> loadUserAssociations();
But, room gives me [SQLITE_ERROR] when build.
It is possible to re-write that query by replacing the constant variable with parameter like the following.
@Query("SELECT * FROM Association WHERE memberStatus = :statusApproved")
LiveData<List<Association>> loadUserAssociations(String statusApproved);
I would like to know that does Room support such kind of string concatenation or String Format? (or) May be I missing something?


edited Nov 20 '18 at 7:18


Alireza Noorali
1,393634
1,393634
asked Nov 20 '18 at 5:39


Toe LieToe Lie
12
12
the 2nd one should work.. is there any error?
– DKV
Nov 20 '18 at 5:42
Yes, @DKV. The 2nd one works. But, I prefer the 1st one and I just want to know does Room support such kind of string concatenation or string format.
– Toe Lie
Nov 20 '18 at 5:47
No, it's not possible with first type.
– Jeel Vankhede
Nov 20 '18 at 5:49
Thanks @JeelVankhede. I think Room should support like that :-D How do you think? :-)
– Toe Lie
Nov 20 '18 at 5:56
No, actually it's not fault of ROOM, but you can't pass variables toAnnotations
it must be static final value.
– Jeel Vankhede
Nov 20 '18 at 6:06
add a comment |
the 2nd one should work.. is there any error?
– DKV
Nov 20 '18 at 5:42
Yes, @DKV. The 2nd one works. But, I prefer the 1st one and I just want to know does Room support such kind of string concatenation or string format.
– Toe Lie
Nov 20 '18 at 5:47
No, it's not possible with first type.
– Jeel Vankhede
Nov 20 '18 at 5:49
Thanks @JeelVankhede. I think Room should support like that :-D How do you think? :-)
– Toe Lie
Nov 20 '18 at 5:56
No, actually it's not fault of ROOM, but you can't pass variables toAnnotations
it must be static final value.
– Jeel Vankhede
Nov 20 '18 at 6:06
the 2nd one should work.. is there any error?
– DKV
Nov 20 '18 at 5:42
the 2nd one should work.. is there any error?
– DKV
Nov 20 '18 at 5:42
Yes, @DKV. The 2nd one works. But, I prefer the 1st one and I just want to know does Room support such kind of string concatenation or string format.
– Toe Lie
Nov 20 '18 at 5:47
Yes, @DKV. The 2nd one works. But, I prefer the 1st one and I just want to know does Room support such kind of string concatenation or string format.
– Toe Lie
Nov 20 '18 at 5:47
No, it's not possible with first type.
– Jeel Vankhede
Nov 20 '18 at 5:49
No, it's not possible with first type.
– Jeel Vankhede
Nov 20 '18 at 5:49
Thanks @JeelVankhede. I think Room should support like that :-D How do you think? :-)
– Toe Lie
Nov 20 '18 at 5:56
Thanks @JeelVankhede. I think Room should support like that :-D How do you think? :-)
– Toe Lie
Nov 20 '18 at 5:56
No, actually it's not fault of ROOM, but you can't pass variables to
Annotations
it must be static final value.– Jeel Vankhede
Nov 20 '18 at 6:06
No, actually it's not fault of ROOM, but you can't pass variables to
Annotations
it must be static final value.– Jeel Vankhede
Nov 20 '18 at 6:06
add a comment |
1 Answer
1
active
oldest
votes
- problem
if you make a query like this,
"SELECT * FROM Association WHERE memberStatus = " + Association.MEMBER_STATUS_APPROVED
it's just
"SELECT * FROM Association WHERE memberStatus = somevalue"
sql cannot know "somvalue" is a string.
- try this (wrap it with quotation mark)
"SELECT * FROM Association WHERE memberStatus = '" + Association.MEMBER_STATUS_APPROVED + "'"
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%2f53386872%2fis-it-possible-to-use-stringformat-or-constant-variable-in-android-room-query%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
- problem
if you make a query like this,
"SELECT * FROM Association WHERE memberStatus = " + Association.MEMBER_STATUS_APPROVED
it's just
"SELECT * FROM Association WHERE memberStatus = somevalue"
sql cannot know "somvalue" is a string.
- try this (wrap it with quotation mark)
"SELECT * FROM Association WHERE memberStatus = '" + Association.MEMBER_STATUS_APPROVED + "'"
add a comment |
- problem
if you make a query like this,
"SELECT * FROM Association WHERE memberStatus = " + Association.MEMBER_STATUS_APPROVED
it's just
"SELECT * FROM Association WHERE memberStatus = somevalue"
sql cannot know "somvalue" is a string.
- try this (wrap it with quotation mark)
"SELECT * FROM Association WHERE memberStatus = '" + Association.MEMBER_STATUS_APPROVED + "'"
add a comment |
- problem
if you make a query like this,
"SELECT * FROM Association WHERE memberStatus = " + Association.MEMBER_STATUS_APPROVED
it's just
"SELECT * FROM Association WHERE memberStatus = somevalue"
sql cannot know "somvalue" is a string.
- try this (wrap it with quotation mark)
"SELECT * FROM Association WHERE memberStatus = '" + Association.MEMBER_STATUS_APPROVED + "'"
- problem
if you make a query like this,
"SELECT * FROM Association WHERE memberStatus = " + Association.MEMBER_STATUS_APPROVED
it's just
"SELECT * FROM Association WHERE memberStatus = somevalue"
sql cannot know "somvalue" is a string.
- try this (wrap it with quotation mark)
"SELECT * FROM Association WHERE memberStatus = '" + Association.MEMBER_STATUS_APPROVED + "'"
answered Nov 20 '18 at 6:12


yeonseok.seoyeonseok.seo
1,03469
1,03469
add a comment |
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%2f53386872%2fis-it-possible-to-use-stringformat-or-constant-variable-in-android-room-query%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
the 2nd one should work.. is there any error?
– DKV
Nov 20 '18 at 5:42
Yes, @DKV. The 2nd one works. But, I prefer the 1st one and I just want to know does Room support such kind of string concatenation or string format.
– Toe Lie
Nov 20 '18 at 5:47
No, it's not possible with first type.
– Jeel Vankhede
Nov 20 '18 at 5:49
Thanks @JeelVankhede. I think Room should support like that :-D How do you think? :-)
– Toe Lie
Nov 20 '18 at 5:56
No, actually it's not fault of ROOM, but you can't pass variables to
Annotations
it must be static final value.– Jeel Vankhede
Nov 20 '18 at 6:06