/[projects]/android/People/src/com/grundfos/android/people/PeopleDatabase.java
ViewVC logotype

Diff of /android/People/src/com/grundfos/android/people/PeopleDatabase.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 233 by torben, Wed Aug 5 08:53:33 2009 UTC revision 234 by torben, Wed Aug 5 19:28:08 2009 UTC
# Line 24  public class PeopleDatabase  { Line 24  public class PeopleDatabase  {
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                  {                  {
# Line 35  public class PeopleDatabase  { Line 35  public class PeopleDatabase  {
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());
# Line 67  public class PeopleDatabase  { Line 67  public class PeopleDatabase  {
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 {
# Line 170  public class PeopleDatabase  { Line 170  public class PeopleDatabase  {
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);
# Line 191  public class PeopleDatabase  { Line 193  public class PeopleDatabase  {
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    
# Line 221  public class PeopleDatabase  { Line 223  public class PeopleDatabase  {
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();

Legend:
Removed from v.233  
changed lines
  Added in v.234

  ViewVC Help
Powered by ViewVC 1.1.20