chennaione / sugar

Insanely easy way to work with Android Database.
http://satyan.github.com/sugar/
MIT License
2.62k stars 583 forks source link

UPDATE query with many @Unique columns #649

Open kinlhp opened 8 years ago

kinlhp commented 8 years ago

Hi, I am Brazilian and I used a translator to write this text - then I'm sorry for any misspelling. Scenario: an object that has two attributes with @Unique, and the time to do an UPDATE on table records get the following exception: android.database.sqlite.SQLiteException: near "nome_cidade": syntax error (code 1): , while compiling: UPDATE cidade SET sincronizacao=?,ultima_alteracao=?,ativo=?,hash=?,uf=? WHERE ibge = ?nome_cidade = ? I noticed the following detail on this query UPDATE: ... WHERE ibge = ?nome_cidade = ?. Looking well, it notes that should be ... WHERE ibge = ? AND nome_cidade = ?. Scouring the framework for possible solutions, I came on the next line com.orm.SugarRecord.update (SugarRecord.java: 332): whereClause.append(columnName).append(" = ?"); It is not generating the query up correctly - eg WHERE foo = x AND bar = Y -, is despising the clause AND. I do not know if anyone has reported the same situation, but in any case is there.

A curiosity is the issue of non-use of PRIMARY KEY to control the tuple that receive UPDATE - I know it has been said http://stackoverflow.com/a/28119201 - as is standard in SQL.

Already, thank you for the excellent ORM that has helped me a lot.

Big hug.

sibelius commented 8 years ago

which version r u using?

could u try sugar 1.5 or master version? (https://github.com/satyan/sugar#how-to-use-master-version)

kinlhp commented 8 years ago

I'm using version 1.5 for dependency on Gradle in my Android application. compile 'com.github.satyan:sugar:1.5'

I'm new to Git. So I try to make a pull request with a possible solution ;)