|
// MBni yaratish uchun SQL- sorov
|
bet | 18/21 | Sana | 20.11.2023 | Hajmi | 1 Mb. | | #101981 |
// MBni yaratish uchun SQL- sorov private static final String DATABASE_CREATE = "create table " + DATABASE_TABLE + " (" + KEY_ID + " integer primary key autoincrement, " + KEY_NAME + " textnotnull);"; // MB obektini saqlash uchun ozgaruvchi private SQLiteDatabasedb; // Dastur konteksti private finalContextcontext; // MBni yangilash va ochish uchun yordamchi klass private myDbHelperdbHelper; // Konstruktor public SampleDBAdapter(Context _context) { context = _context; dbHelper = new myDbHelper(context, DATABASE_NAME, null, DATABASE_VERSION); } // Malumotlar omboriga kirish public SampleDBAdapter open() throws SQLException { try {
db = dbHelper.getWritableDatabase(); } catch (SQLiteException e) { db = dbHelper.getReadableDatabase(); } return this; } // Mbni yopish public void close() { db.close(); } // Malumotlarni qoshish metodi, bu metod malumot indeksini qaytaradi. public long insertEntry(SampleObject _SampleObject) { // Bu erda oz ichida kerakli malumotlar joylashgan va MBga qoyilishi //rejalashtirilgan ContentValues obekti yasaladi returnindex; } // Indeksi boyicha malumotni ochirish public booleanremoveEntry(long _rowIndex) { returndb.delete(DATABASE_TABLE, KEY_ID + "=" + _rowIndex, null) > 0; } // Barcha malumotlarni olish metodi public Cursor getAllEntries() { returndb.query(DATABASE_TABLE, new String[] { KEY_ID, KEY_NAME }, null, null, null, null, null); } // indeksi boyicha obektning ekzemplyarni natija sifatida qaytaradi public SampleObjectgetEntry(long _rowIndex) {
// kursorni qabul qiladi, MBdan kerakli malumotlarni korasatadi returnobjectInstance; } // Indeks boyicha obektni ozgartirish
|
| |