--- android/People/src/com/grundfos/android/people/PeopleDatabase.java 2009/08/05 11:14:04 233 +++ android/People/src/com/grundfos/android/people/PeopleDatabase.java 2009/08/05 19:28:08 234 @@ -24,7 +24,7 @@ /** The name of the database file on the file system */ private static final String DATABASE_NAME = "People"; /** The version of the database that this class understands. */ - private static final int DATABASE_VERSION = 5; + private static final int DATABASE_VERSION = 6; public PeopleDatabaseHelper(Context context) { @@ -35,7 +35,7 @@ public void onCreate(SQLiteDatabase db) { db.beginTransaction(); try { - db.execSQL("CREATE TABLE people (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, inits TEXT, title TEXT, dept TEXT, company TEXT, phone TEXT, cell TEXT, email TEXT)"); + db.execSQL("CREATE TABLE people (id INTEGER PRIMARY KEY AUTOINCREMENT, lowername TEXT, name TEXT, inits TEXT, title TEXT, dept TEXT, company TEXT, phone TEXT, cell TEXT, email TEXT)"); db.setTransactionSuccessful(); } catch (SQLException e) { Log.e("Error creating tables and debug data", e.toString()); @@ -67,10 +67,10 @@ public Cursor getPeopleList(String search) { - search = search.replace(' ', '%'); + search = search.replace(' ', '%').toLowerCase(); search = "%" + search + "%"; - String sql = "SELECT id AS _id, name, inits, company FROM people WHERE name LIKE ? ORDER BY name LIMIT 200"; + String sql = "SELECT id AS _id, name, inits, company FROM people WHERE lowername LIKE ? ORDER BY name LIMIT 200"; SQLiteDatabase d = dbHelper.getReadableDatabase(); try { @@ -170,14 +170,16 @@ try { StringTokenizer fields = new StringTokenizer(line, ";"); - stmt.bindString(1, fields.nextToken().trim() ); - stmt.bindString(2, fields.nextToken().trim() ); + String name = fields.nextToken().trim(); + stmt.bindString(1, name.toLowerCase() ); + stmt.bindString(2, name ); stmt.bindString(3, fields.nextToken().trim() ); stmt.bindString(4, fields.nextToken().trim() ); stmt.bindString(5, fields.nextToken().trim() ); stmt.bindString(6, fields.nextToken().trim() ); stmt.bindString(7, fields.nextToken().trim() ); stmt.bindString(8, fields.nextToken().trim() ); + stmt.bindString(8, fields.nextToken().trim() ); stmt.execute(); } catch (Exception e) { Log.e("PeopleDataBase", "Token error: " + line, e); @@ -191,7 +193,7 @@ db = dbHelper.getWritableDatabase(); db.beginTransaction(); db.execSQL("DELETE FROM people"); - stmt = db.compileStatement("INSERT INTO people (name,inits,title,dept,company,phone,cell,email) VALUES (?,?,?,?,?,?,?,?);"); + stmt = db.compileStatement("INSERT INTO people (lowername,name,inits,title,dept,company,phone,cell,email) VALUES (?,?,?,?,?,?,?,?,?);"); URL url = new URL("http://t-hoerup.dk/peopledata.txt"); @@ -221,6 +223,7 @@ } is.close(); db.setTransactionSuccessful(); + } finally { stmt.close(); db.endTransaction();