Created
June 30, 2015 11:56
-
-
Save alexfu/aa13a1168a8e13670842 to your computer and use it in GitHub Desktop.
Android database cursor extensions that simplify retrieval of typed values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.database.Cursor | |
/** | |
* CursorExtentions | |
* | |
* Android database cursor extensions that simplify retrieval of typed values | |
* @author alexfu | |
*/ | |
fun Cursor.getInt(colName: String): Int { | |
return this.getInt(this.getColumnIndex(colName)) | |
} | |
fun Cursor.getString(colName: String): String { | |
return this.getString(this.getColumnIndex(colName)) | |
} | |
fun Cursor.getDouble(colName: String): Double { | |
return this.getDouble(this.getColumnIndex(colName)) | |
} | |
fun Cursor.getFloat(colName: String): Float { | |
return this.getFloat(this.getColumnIndex(colName)) | |
} | |
fun Cursor.getBlob(colName: String): ByteArray? { | |
return this.getBlob(this.getColumnIndex(colName)) | |
} | |
fun Cursor.getLong(colName: String): Long { | |
return this.getLong(this.getColumnIndex(colName)) | |
} | |
fun Cursor.getShort(colName: String): Short { | |
return this.getShort(this.getColumnIndex(colName)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment