본문 바로가기

Android/Database

(3)
문자열 자르기 (kotlin) 출처 : detail.html?no=560 String은 char의 배열이므로 인덱스(index)값을 이용하여 특정 글자 수 이상의 글자는 자르거나 특정 단어만 자르는 등 여러가지 처리를 할 수 있습니다. 이 포스트에서는 substring 과 split 함수를 이용하여 문자열을 자르는 방법에 대해 소개합니다. val testString : String = “abcdefg” //배열의 인덱스는 앞에서부터 0,1,2,3 순서대로 값을 가지기 때문에 //testString의 0번째 값은 a, 1번째 값은 b가 됩니다. //1.substring은 인덱스 값을 기준으로 문자열을 자르는 함수로서, 2가지 방법으로 사용할 수 있습니다. String.substring(startIndex : Int) //2.문자열의 s..
Room 쿼리문 샘플 (kotlin) Entity @Entity(tableName = "memo_db") data class MemoEntity( @PrimaryKey(autoGenerate = true) var id: Long?, var memo: String = "", var cid: Int = 0 ) DAO @Dao interface MemoDAO { @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(memo: MemoEntity) @Query("SELECT * FROM memo_db") fun getALL(): List @Delete fun delete(memo:MemoEntity) @Update fun update(memo:MemoEntity) //memo_db 테이블 중 c..
Android Room 일괄 삽입 또는 업데이트 (Kotlin) interface ItemDao { @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(entity: Item) : Long @Insert(onConflict = OnConflictStrategy.REPLACE) fun insertAll(vararg entity: Item) @Update fun update(entity: Item) @Update fun updateAll(vararg entity: Item) } 여러 개체 삽입 // insert multiple items itemDao.insertAll(item1, item2, item3) 목록을 varargs로 변환 // insert list of items val items = listOf(ite..

반응형