24 |
/** The name of the database file on the file system */ |
/** The name of the database file on the file system */ |
25 |
private static final String DATABASE_NAME = "People"; |
private static final String DATABASE_NAME = "People"; |
26 |
/** The version of the database that this class understands. */ |
/** The version of the database that this class understands. */ |
27 |
private static final int DATABASE_VERSION = 5; |
private static final int DATABASE_VERSION = 6; |
28 |
|
|
29 |
public PeopleDatabaseHelper(Context context) |
public PeopleDatabaseHelper(Context context) |
30 |
{ |
{ |
35 |
public void onCreate(SQLiteDatabase db) { |
public void onCreate(SQLiteDatabase db) { |
36 |
db.beginTransaction(); |
db.beginTransaction(); |
37 |
try { |
try { |
38 |
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)"); |
39 |
db.setTransactionSuccessful(); |
db.setTransactionSuccessful(); |
40 |
} catch (SQLException e) { |
} catch (SQLException e) { |
41 |
Log.e("Error creating tables and debug data", e.toString()); |
Log.e("Error creating tables and debug data", e.toString()); |
67 |
|
|
68 |
|
|
69 |
public Cursor getPeopleList(String search) { |
public Cursor getPeopleList(String search) { |
70 |
search = search.replace(' ', '%'); |
search = search.replace(' ', '%').toLowerCase(); |
71 |
search = "%" + search + "%"; |
search = "%" + search + "%"; |
72 |
|
|
73 |
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"; |
74 |
SQLiteDatabase d = dbHelper.getReadableDatabase(); |
SQLiteDatabase d = dbHelper.getReadableDatabase(); |
75 |
|
|
76 |
try { |
try { |
170 |
try |
try |
171 |
{ |
{ |
172 |
StringTokenizer fields = new StringTokenizer(line, ";"); |
StringTokenizer fields = new StringTokenizer(line, ";"); |
173 |
stmt.bindString(1, fields.nextToken().trim() ); |
String name = fields.nextToken().trim(); |
174 |
stmt.bindString(2, fields.nextToken().trim() ); |
stmt.bindString(1, name.toLowerCase() ); |
175 |
|
stmt.bindString(2, name ); |
176 |
stmt.bindString(3, fields.nextToken().trim() ); |
stmt.bindString(3, fields.nextToken().trim() ); |
177 |
stmt.bindString(4, fields.nextToken().trim() ); |
stmt.bindString(4, fields.nextToken().trim() ); |
178 |
stmt.bindString(5, fields.nextToken().trim() ); |
stmt.bindString(5, fields.nextToken().trim() ); |
179 |
stmt.bindString(6, fields.nextToken().trim() ); |
stmt.bindString(6, fields.nextToken().trim() ); |
180 |
stmt.bindString(7, fields.nextToken().trim() ); |
stmt.bindString(7, fields.nextToken().trim() ); |
181 |
stmt.bindString(8, fields.nextToken().trim() ); |
stmt.bindString(8, fields.nextToken().trim() ); |
182 |
|
stmt.bindString(8, fields.nextToken().trim() ); |
183 |
stmt.execute(); |
stmt.execute(); |
184 |
} catch (Exception e) { |
} catch (Exception e) { |
185 |
Log.e("PeopleDataBase", "Token error: " + line, e); |
Log.e("PeopleDataBase", "Token error: " + line, e); |
193 |
db = dbHelper.getWritableDatabase(); |
db = dbHelper.getWritableDatabase(); |
194 |
db.beginTransaction(); |
db.beginTransaction(); |
195 |
db.execSQL("DELETE FROM people"); |
db.execSQL("DELETE FROM people"); |
196 |
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 (?,?,?,?,?,?,?,?,?);"); |
197 |
|
|
198 |
URL url = new URL("http://t-hoerup.dk/peopledata.txt"); |
URL url = new URL("http://t-hoerup.dk/peopledata.txt"); |
199 |
|
|
223 |
} |
} |
224 |
is.close(); |
is.close(); |
225 |
db.setTransactionSuccessful(); |
db.setTransactionSuccessful(); |
226 |
|
|
227 |
} finally { |
} finally { |
228 |
stmt.close(); |
stmt.close(); |
229 |
db.endTransaction(); |
db.endTransaction(); |