Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

769
Views
Cómo saber si ya existe un registro en una base de datos de habitaciones

Me mudé de sql db a room. No puedo averiguar cómo verificar si el elemento existe en la base de datos. ¿Cómo escribir este código usando Room?

 fun existsCheck(place: Places): Boolean { val db= this.readableDatabase val query = "SELECT * FROM $TABLE_PLACES WHERE $COLUMN_LAT = ${place.lat} AND $COLUMN_LNG = ${place.lng}" val cursor = db.rawQuery(query, null) if(cursor.count > 0){ cursor.close() db.close() return true } cursor.close() db.close() return false }

He intentado lograr esto con este código, pero siempre obtengo FALSO

 @Query("SELECT name FROM place WHERE lat = :lat AND lng = :lng") fun exist(lat: Double?, lng: Double?): Flowable<String> override fun save() { Observable.just(dao) .subscribeOn(Schedulers.io()) .subscribe { dao.insert(place) } } override fun itemExists(lat: Double?, lng: Double?): Single<Boolean> = dao.exist(lat, lng) .flatMapSingle { Single.just(it.isNotEmpty()) } .onErrorReturn { false } .first(false) override fun delete() { dao.deleteByLat(place.lat) } override fun saveClicked() { var boolean = false itemExists(place.lat, place.lng) .subscribeOn(Schedulers.io()) .map { it -> boolean = it } if (boolean){ delete() v.setImageNotSaved() } else { save() v.setImageSaved() } }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

esto funciona bien

 override fun itemExists() { Observable.just(dao) .subscribeOn(Schedulers.io()) .subscribeOn(AndroidSchedulers.mainThread()) .map { it -> it.exist(place.lat, place.lng) } .subscribe( { it -> saveClicked(true) }, {error -> saveClicked(false)}) }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!