SQLiteException when querying a SELECT [on hold]

Multi tool use
Multi tool use


SQLiteException when querying a SELECT [on hold]



I am developing an Android application with an SQLite database. It records transactions. The transactions table has the colums:


transactions


idTransaction INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT


date DATE NOT NULL


type INT NOT NULL


details VARCHAR(100) NOT NULL


notes VARCHAR(300) NOT NULL


amount DOUBLE NOT NULL


account INT NOT NULL


category INT NOT NULL



Also I made a method to get a cursor with all transactions:


// Select all Transactions
protected Cursor getTransactions() throws SQLException {
Cursor mCursor = null;
String colums = new String{"idTransaction", "date", "type", "details", "notes", "amount", "account", "category"};
mCursor = this.getReadableDatabase().query("Transactions", colums, null, null, null, null, "name ASC");
return mCursor;
}



In other class I made a method to move through the cursor that I get when I call getTransactions() method.


getTransactions()



But the exception happen in this line:


mCursor = this.getReadableDatabase().query("Transactions", colums, null, null, null, null, "name ASC");



android.database.sqlite.SQLiteException: no such column: name(Sqlite code 1): , while compiling: SELECT idTransaction, date, type, details, notes, amount, account, category FROM Transactions ORDER BY name ASC,(OS error - 2:No such file or directory)



I checked the table name and all column names. I deleted and reinstalled the app but I do not know why the exception occurs.



This question appears to be off-topic. The users who voted to close gave this specific reason:





You listed 8 columns, none of them called name, and you asked to sort ascending by name (that's what "name ASC" means), so why are you confused that it fails with "no such column: name"? Error message says it all.
– Andreas
Jul 1 at 5:23



name


name


"name ASC"


name




2 Answers
2



You're using an order by of name ASC, but you don't have a name column. That's what it means in the error message when it says no such column: name


name ASC


name


no such column: name





If this really be the explanation, then you should probably just vote to close as a typo question.
– Tim Biegeleisen
Jul 1 at 5:14






I can't belived! But some times happen. :-P
– cer825m
Jul 1 at 5:18



The Query method that you are using is of the form


query(String table, String columns, String selection, String selectionArgs, String groupBy, String having, String orderBy)



as documented Here



As you have mentioned orderBy as "name ASC", but unfortunately your query string doesn't contain any such column, thus resulting in the exception what you have mentioned.



To solve this either add the name column also in your columns list else change the orderBy to any existing column name eg- "date ASC".

7Ism6,Aq FAW,dtiz,XZwO,gpoYICZOwKR0G,Hxwu7OC4JQCD9QPUqcS t2ZFe1bgONe8N rOFNAAc,nLZT ja6FMaLsaLv5lKKuhij 4
TRZGplOkCz phieGd404yBPEv0mNBclkR9xVD07ZatS5DdoNe,RPQM mmCC PAoLbf0D9HtO 8wvs,3zfoRw4toDU,4 k JiGwcIzXW,gJaqE

Popular posts from this blog

PySpark - SparkContext: Error initializing SparkContext File does not exist

django NoReverseMatch Exception

List of Kim Possible characters