I have a little program that writes to a SQLite database with 4
tables. When I do a query (either with rawQuery or
SQLiteQueryBuilder.query) the cursor only has column's from the first
table. Does anybody know how to do a query on 2 tables that have been
joined on a key value?

some code

public void onCreate(final SQLiteDatabase database) {
                        String sqlCreate =
                                "CREATE TABLE IF NOT EXISTS Catch ("
                                        + "ID integer primary key 
autoincrement,"
                                        + "GPSLON          FLOAT, "
                                        + "GPSLAT          FLOAT, "
                                        + "Time            TIMESTAMP, "
                                        + "BaitID          INTEGER, "
                                        + "RigsID          VARCHAR,"
                                        + "FishID          VARCHAR,"
                                        + "SyncStatus      INTEGER"
                                        + ");";
                        database.execSQL(sqlCreate);

                        sqlCreate =
                                        "CREATE TABLE IF NOT EXISTS bait ("
                                        +"BaitID integer primary key 
autoincrement,"
                                        +"SyncStatus      INTEGER,"
                                        +"BaitName        VARCHAR unique);";
                        database.execSQL(sqlCreate);

                        sqlCreate =
                                        "CREATE TABLE IF NOT EXISTS rigs ("
                                        +"RigsID integer primary key 
autoincrement,"
                                        +"SyncStatus      INTEGER,"
                                        +"RigsName        VARCHAR);";

                        database.execSQL(sqlCreate);

                        sqlCreate =
                                        "CREATE TABLE IF NOT EXISTS fishSpecies 
("
                                        +"FishID integer primary key 
autoincrement,"
                                        +"SyncStatus     INTEGER,"
                                        +"FishName       VARCHAR);";
                        database.execSQL(sqlCreate);
                }



        private long addBait(final Catch c) {
                long id=-1;
                Cursor data = db.query("bait",
                                null,
                                "BaitName = '"+c.baitText+"'",
                                null,
                                null,
                                null,
                                "BaitName DESC");

                if (data!=null) {
                        if (data.moveToFirst()){
                                id = data.getInt(0);
                        }
                }
                data.close();
                if (id==-1){
                        final ContentValues initialValues = new ContentValues();
                        initialValues.put("BaitName", c.baitText);
                        initialValues.put("SyncStatus", c.syncStatus);
                        id = db.insertOrThrow("bait", null, initialValues);
                }
                return id;
        }

        public long addCatch(final Catch c) {
                long baitId = addBait(c);

                final ContentValues initialValues = new ContentValues();
                initialValues.put("GPSLON",c.lon);
                initialValues.put("GPSLAT", c.lat);
                initialValues.put("Time", c.time.toString());
                initialValues.put("BaitID", baitId);
                initialValues.put("SyncStatus", c.syncStatus);

                final long addedRow = db.insertOrThrow("Catch", null,
initialValues);
                return addedRow;
        }


       public Cursor getAllMyFish() {
                SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
                builder.setTables("Catch Bait");
                Cursor c = builder.query(db, new String[]{}, null, new 
String[]{},
null, null, null);
                return c;
        }


It is the cursor that is returned from getAllMyFish() that I want to
have fields from both Catch and Bait but I only get fields from Catch
when I look at the values returned from the cursor's getColumnName()

-- 
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