-1

I have a Kolin Android Application with a Database. I use the Anko library for the Database Communication. I can insert Data in my Database but I have some troubles when I try to get a data row from my Database.

I try to get the Data Row through the following code

try {
           var result = select("projects").where("rowid = {id}",
                    "id" to 1).parseList(StringParser)

            Toast.makeText(applicationContext,result.toString(),Toast.LENGTH_LONG).show()

        } catch(e: Exception) {
            Toast.makeText(applicationContext,e.toString(),Toast.LENGTH_LONG).show()
        }

How can I get the content of the Row with the given id

At the moment I get this error

Invalid row: row for SingleColumnParser must contain exactly one column

juli0n_
  • 81
  • 2
  • 7
  • Obviously StringParser is for one column query... You should point which column you wana select or use different parser – Selvin Jun 26 '17 at 20:26

2 Answers2

0

example :

data class Controler(val id: Int, var name: String, val ssid: String,val password: String,val serialnumber: String): Serializable {}

and in your activity ->

select("projects", "id", "name", "ssid", "password", "serialnumber")
                .whereArgs("(id = {controlerId}) ", "controlerId" to id)
                .parseOpt(object : MapRowParser<Controler> {
                    override fun parseRow(columns: Map<String, Any?>): Controler {
                        controler = Controler(columns.getValue("id").toString().toInt(),
                                columns.getValue("name").toString(),
                                columns.getValue("ssid").toString(),
                                columns.getValue("password").toString(),
                                columns.getValue("serialnumber").toString())
                        return controler as Controler
                    }

                })
-1

Hi you must share the complete code, and the log, what message show? Try this. Why don't use "_id" ? Sqlite required.

select("projects")
        .where("(_id = {id}),
                "id" to 1)
josedlujan
  • 5,357
  • 2
  • 27
  • 49
  • Hi I've edited a bit my code and tried some solutions by my own but I still can't get any data. I copied the new code snippet to my post and added the error message – juli0n_ Jun 26 '17 at 20:14