You can simply change the SQL statement to

SELECT * FROM edition AS _id, magazine WHERE
edition.magazine_id = magazine.magazineId

provided that edition is what you want to use as the key

On Mar 30, 1:59 am, marceo <[email protected]> wrote:
> Hey,
>
> I got an ListActivity which gets its Data from a SQLite database. The
> Database has 3 tables:
>
> db.execSQL("CREATE TABLE " + TABLE_MAGAZINE + " (magazineId INTEGER
> PRIMARY KEY, " +
>                                                                               
>                           "magazineName TEXT);");
>
>             /** Tabelle "Edition" erstellen **/
>             db.execSQL("CREATE TABLE " + TABLE_EDITION + " ( editionId
> INTEGER PRIMARY KEY, " +
>                                                                               
>                           "editionName TEXT, " +
>                                                                               
>                           "editionContent TEXT, " +
>                                                                               
>                           "magazine_id INTEGER NOT NULL, " +
>                                                                               
>                           "FOREIGN KEY (magazine_id) REFERENCES " +
> TABLE_MAGAZINE + "(magazineId));");
>
>             /** Tabelle "Article" erstellen **/
>             db.execSQL("CREATE TABLE " + TABLE_ARTICLE + " ( articleId
> INTEGER PRIMARY KEY, " +
>                                                                               
>                           "articleName TEXT, " +
>                                                                               
>                           "articleContent TEXT, " +
>                                                                               
>                           "edition_id INTEGER NOT NULL, " +
>                                                                               
>                           "FOREIGN KEY (edition_id) REFERENCES " +
> TABLE_EDITION + "(editionId));");
>
> For the foreign Keys there are 2 Trigger:
>
>  db.execSQL("CREATE TRIGGER fki_edition_magazine_id " +
>                                 " BEFORE INSERT ON "+ TABLE_EDITION +
>                                 " FOR EACH ROW BEGIN"+
>                                 " SELECT CASE WHEN ((SELECT magazineId FROM 
> "+ TABLE_MAGAZINE +"
> WHERE magazineId = new.magazine_id ) IS NULL)"+
>                                 " THEN RAISE (ABORT,'Foreign Key Violation') 
> END;"+
>                                 "  END;");
>
>             db.execSQL("CREATE TRIGGER fki_article_edition_id " +
>                                 " BEFORE INSERT "+
>                                 " ON "+ TABLE_ARTICLE +
>                                 " FOR EACH ROW BEGIN"+
>                                 " SELECT CASE WHEN ((SELECT editionId FROM "+ 
> TABLE_EDITION +"
> WHERE editionId = new.edition_id ) IS NULL)"+
>                                 " THEN RAISE (ABORT,'Foreign Key Violation') 
> END;"+
>                                 "  END;");
>
> Now I want to get the magazineName and the editionName and show them
> in the ListView.
>
>         Cursor getAllMagazines() {
>                 SQLiteDatabase db=this.getWritableDatabase();
>                 Cursor cur= db.rawQuery("SELECT * FROM edition, magazine WHERE
> edition.magazine_id = magazine.magazineId", new String [] {});
>
>                 return cur;
>         }
>
> At the Moment I got 1 database-entry in every table in my DB. The
> Cursor also got an Count by 1.
> So i create a SimpleCursorAdapter to show the content in the ListView.
>
>                         /** Adapter erstellen**/
>                 SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
>                         android.R.layout.simple_list_item_2, c,
>                         new String[] {"editionName", "magazineName"},
>                         new int[] {android.R.id.text1, android.R.id.text2});
>
>                         /** Adapter setzen**/
>                     this.setListAdapter(adapter);
>
>         this.setListAdapter(adapter);
>
> The count of the cursor is 1, and the column names are editionName and
> magazineName (LogCat). But it wont show any data.
>
> If i use an extra attribute id INTEGER PRIMARY KEY AUTO_INCREMENT and
> i only want Data from 1 Tabel, everything works fine.
>
> Any ideas?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to