Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocompletion on one field #350

Closed
luxsyp opened this issue Mar 19, 2015 · 2 comments
Closed

Autocompletion on one field #350

luxsyp opened this issue Mar 19, 2015 · 2 comments

Comments

@luxsyp
Copy link

luxsyp commented Mar 19, 2015

Hello I would like to be able to create an auto-completion based on my database,

my model look like this :

  @Table(name = "Drug")
  public class Item extends Model {

  @Column(name = "Name")
  public String name;

  @Column(name = "Desc")
  public String desc;

  @Column(name= "Type")
  public Integer type;
 }

I would like to be able to auto-complete on the name only without getting ALL my objects before.

Is there a way to only get a List, where the String is the field name of my object without getting all the object (name+desc+type) ?

@jlhonora
Copy link

I believe you can't get a list of strings directly. Here's a (very insecure) alternative:

List<Item> items = new Select("Name").from(Item.class)
    .where("Name LIKE %" + input + "%").execute();

List<String> strings = new ArrayList<String>();

for (Item item : items) {
    strings.add(item.name);
}

It is insecure because SQL injection could occur. I don't know if ActiveAndroid has any anti-SQL injection utilities.

Edit: It doesn't have a built-in anti SQL injection mechanism, here's the part where arguments are added:

void addArguments(Object[] args) {
    for(Object arg : args) {
        if (arg.getClass() == boolean.class || arg.getClass() == Boolean.class) {
            arg = (arg.equals(true) ? 1 : 0);
        }
        mArguments.add(arg);
    }
}

Edit 2: Multiple statements are not supported in Android's SQLiteDatabase (reference), so injection shouldn't be a problem.

@luxsyp
Copy link
Author

luxsyp commented Mar 19, 2015

sounds like I can start from this thx

@luxsyp luxsyp closed this as completed Mar 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants