tags:

views:

63

answers:

1

Looking for some syntax help for SQLite, a very odd thing is happening. I am running the query on an iPhone.

Here is the query that fails: (Assume that the tables are correct, this runs great in the firefox sqlite plugin)

  select tcodes.DisplayOrder, StatusText, StatusCode  
    from tcodes 
    join tcode_transitions on tcode_transitions.available = tcodes.UNID 
   where StatusCode = 'AAA' 
order by tcodes.DisplayOrder

To get it to run, I have to remove the order by clause, which seems a bit strange.

Here is the call:

// Open the database from the users filessytem
    if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
        // Setup the SQL Statement and compile it for faster access

        int rtn = sqlite3_prepare_v2(database, [sql UTF8String], -1, &compiledStatement, nil);
        if(rtn != SQLITE_OK) {
            NSLog(@"SQL Error: %d",rtn);
            sqlite3_close(database);
        }
    }   

in the above, rtn is == 1, which indicates a SQL error.

Again, the query runs great outside the phone. Is it possible that the SQL libraries on the iPhone have a different syntax for the order by?

+1  A: 
  1. Use sqlite3_errmsg (or sqlite3_errmsg16) to get more information about error.

  2. Try adding DisplayOrder to select clause. Some databases require that all columns in ORDER BY clause are also present in SELECT clause.

Tomek Szpakowicz