lundi 19 octobre 2015

Using Conditional Statement in SQLite Database Search

I have a database called CAL. It has two colums, MONTH and DAY. Let's say that I have date in there called May 8. May goes in the MONTH column and 8 goes in the DAY column. I know how to search individuals columns, for instance, find the row that has May in the MONTH column:

                    SQLiteDatabase db = sqLiteOpenHelper.getReadableDatabase();

                    Cursor cursor = db.query("CAL",
                            new String[]{"MONTH","DAY"},
                            "MONTH = ?",
                            new String[]{"May"},
                            null,null,null);

                    if (cursor.moveToFirst()){
                        String monthFromCursor = cursor.getString(0);

                        monthOutput.setText(monthFromCursor);

                    }

I'm wondering if there is a way to search for data in multiple columns at the same time? For example, use the cursor to find the row where MONTH is May AND DAY is 8. Is that possible?

                    SQLiteDatabase db = sqLiteOpenHelper.getReadableDatabase();

                    Cursor cursor = db.query("CAL",
                            new String[]{"MONTH","DAY"},
                            "MONTH = ?",//Can I place something here???
                            new String[]{"May", Integer.toString(8)},
                            null,null,null);

                    if (cursor.moveToFirst()){
                        String monthFromCursor = cursor.getString(0);

                        monthOutput.setText(monthFromCursor);

                    }

Aucun commentaire:

Enregistrer un commentaire