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

no such column #137

Closed
Jakevin opened this issue Aug 9, 2014 · 7 comments
Closed

no such column #137

Jakevin opened this issue Aug 9, 2014 · 7 comments
Labels

Comments

@Jakevin
Copy link

Jakevin commented Aug 9, 2014

I try to use object Relationships, but always get "no such column: noteTags"

My code:

public class NoteWord extends SugarRecord<NoteTag> {
    public static final String TAG = "Note_Word";
    public String chinese;
    public String nihongo;
    public String pron;
    public int star;
    public NoteTag noteTags;
    public NoteWord(){
    }

    public NoteWord(String chinese,String nihongo,String pron,int star,NoteTag tags){
        this.chinese = chinese;
        this.nihongo = nihongo;
        this.pron = pron;
        this.star = star;
        this.noteTags = tags;
    }
}
public class NoteTag extends SugarRecord<NoteTag> {
    public static final String TAG = "NoteTag";
    String tagName;
    public NoteTag() {
    }
    public NoteTag(String tagName) {
        this.tagName = tagName;
    }
    public void setTagName(String name) {
        tagName = name;
    }
    public String getTagName() {
        return tagName;
    }
}
 NoteWord.find(NoteWord.class, "noteTags = ?", tags.get(i).getId()+"");
@Jakevin
Copy link
Author

Jakevin commented Aug 9, 2014

....Find !!
Sugar ORM with autotrans 「lower camel case」to 「lower camel case+ under Line...」
so

 NoteWord.find(NoteWord.class, "noteTags = ?", tags.get(i).getId()+"");

must use

 NoteWord.find(NoteWord.class, "note_Tags = ?", tags.get(i).getId()+"");

@whoshuu
Copy link
Collaborator

whoshuu commented Aug 15, 2014

Yeah, currently all table names are automatically mapped from camel case to underscored names, as this is conventional when using SQLite databases. We actually do have an option in the current master branch that will allow you to specify the table name. For instance, if you want to save NoteTag as noteTag in the database, you would do:

@Table(name = "noteTag")
public class NoteTag {
...
}

@whoshuu
Copy link
Collaborator

whoshuu commented Aug 21, 2014

Hey @Jakevin, let me know if you're okay with me closing this issue.

@ariedov
Copy link

ariedov commented Nov 24, 2014

Hi guys. I am running into "no such column"

public class MenuItem extends SugarRecord<MenuItem> {

    public int id;
    public String name;
    public String description;
    public int  cost;
    public String currency_code;
    public String icon_src;
    public int category_id;
    public int place_id;
    public long added;
    public long updated;
}

And here is the exception

android.database.sqlite.SQLiteException: no such column: place_id (code 1): , while compiling: SELECT * FROM MENU_ITEM WHERE place_id=?
        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:893)
        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:504)
        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
        at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
        at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
        at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
        at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1322)
        at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1169)
        at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1040)
        at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1246)
        at com.orm.SugarRecord.find(SugarRecord.java:208)
        at com.orm.SugarRecord.find(SugarRecord.java:172)
        at com.togo.togo_android.PlaceActivity.requestMenuFromCache(PlaceActivity.java:126)

@idemax
Copy link

idemax commented Jan 19, 2015

As @Jakevin said, use 'my_field' when you declare a variable as 'myField', works fine!

@whoshuu whoshuu added the closing label Apr 4, 2015
@whoshuu whoshuu closed this as completed Apr 7, 2015
@romangromov
Copy link

This should be added to official documentation...

@andersonbadari
Copy link

hahah thanks for the underline tip...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants