private void getServer(long serverId) { database = dbhelper.ReadableDatabase; ICursor sc; try { sc = database.Query(YastroidOpenHelper.SERVERS_TABLE_NAME, new string[] { "_id", "name", "scheme", "hostname", "port", "user", "pass", "grp" }, YastroidOpenHelper.SERVERS_ID + "=" + serverId, null, null, null, null); sc.MoveToFirst(); s = new Server(sc.GetInt(0), sc.GetString(1), sc.GetString(2), sc .GetString(3), sc.GetInt(4), sc.GetString(5), sc .GetString(6), sc.GetInt(7)); sc.Close(); database.Close(); } catch (Exception e) { Log.Error("BACKGROUND_PROC", e.Message); } }
public Server getServer(int id) { database = dbhelper.ReadableDatabase; Server s = null; try { ICursor sc = database.Query(YastroidOpenHelper.SERVERS_TABLE_NAME, new string[] { "_id", "name", "scheme", "hostname", "port", "user", "pass", "grp" }, "_id="+id, null, null, null, null); if(sc.Count == 1) { s = new Server(sc.GetInt(0), sc.GetString(1), sc .GetString(2), sc.GetString(3), sc.GetInt(4), sc .GetString(5), sc.GetString(6), sc.GetInt(7)); } sc.Close(); database.Close(); } catch (Exception e) { Log.Error("BACKGROUND_PROC", e.Message); } return s; }
/** * Execute query using the current internal state as {@code WHERE} clause. */ public ICursor Query(SQLiteDatabase db, String[] columns, String groupBy, String having, String orderBy, String limit) { AssertTable(); if (columns != null) MapColumns(columns); if (LOGV) Log.Verbose(TAG, "query(columns=" + string.Join(", ", columns) + ") " + this); return db.Query(mTable, columns, GetSelection(), GetSelectionArgs(), groupBy, having, orderBy, limit); }
void getServers() { database = dbhelper.ReadableDatabase; ICursor sc; try { if (groupId == YastroidOpenHelper.GROUP_DEFAULT_ALL) { sc = database.Query(YastroidOpenHelper.SERVERS_TABLE_NAME, new [] { "_id", "name", "scheme", "hostname", "port", "user", "pass", "grp" }, null, null, null, null, null); } else { sc = database.Query(YastroidOpenHelper.SERVERS_TABLE_NAME, new [] { "_id", "name", "scheme", "hostname", "port", "user", "pass", "grp" }, YastroidOpenHelper.SERVERS_GROUP + "=" + groupId, null, null, null, null); } sc.MoveToFirst(); Server s; serverList.Clear (); if (!sc.IsAfterLast) { do { s = new Server(sc.GetInt(0), sc.GetString(1), sc.GetString(2), sc.GetString(3), sc.GetInt(4), sc.GetString(5), sc.GetString(6), sc.GetInt(7)); serverList.Add(s); } while (sc.MoveToNext()); } sc.Close(); database.Close(); Log.Info("Server Array", "" + serverList.Count); } catch (Exception e) { Log.Error("BACKGROUND_PROC", e.Message); } serverAdapter.Clear(); if (serverList != null && serverList.Count > 0) { for (int i = 0; i < serverList.Count; i++) serverAdapter.Add(serverList[i]); } else { // Add button 'Add new Server' } serverAdapter.NotifyDataSetChanged(); }
public override void OnUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { TLog.d(TAG, "Upgrading database from version {0} to {1}", oldVersion, newVersion); ICursor notesCursor; List<Dictionary<string, string>> db_list = new List<Dictionary<string, string>>(); notesCursor = db.Query(DB_TABLE_NOTES, COLUMNS_VERSION[oldVersion - 1], null, null, null, null, null); notesCursor.MoveToFirst(); if (oldVersion == 1) { // GUID and NOTE_CONTENT are not saved. TLog.d(TAG, "Database version {0} is not supported to update, all old datas will be destroyed", oldVersion); db.ExecSQL("DROP TABLE IF Exists notes"); onCreate(db); return; } // Get old datas from the SQL while(!notesCursor.IsAfterLast) { Dictionary<string, string> row = new Dictionary<string, string>(); for(int i = 0; i < COLUMNS_VERSION[oldVersion - 1].Length; i++) { row.Add (COLUMNS_VERSION[oldVersion - 1][i], notesCursor.GetString(i)); } // create new columns if (oldVersion <= 2) { row.Add(Note.TAGS, ""); } if (oldVersion <= 3) { row.Add(Note.NOTE_CONTENT_PLAIN, stringConverter.encode(Html.FromHtml(row.get(Note.TITLE) + "\n" + row.get(Note.NOTE_CONTENT)).ToString())); } db_list.Add(row); notesCursor.MoveToNext(); } db.ExecSQL("DROP TABLE IF Exists notes"); onCreate(db); // put rows to the database row = new ContentValues(); for(int i = 0; i < db_list.Count; i++) { for(int j = 0; j < COLUMNS_VERSION[newVersion - 1].Length; j++) { row.put(COLUMNS_VERSION[newVersion - 1][j], db_list.get(i).get(COLUMNS_VERSION[newVersion - 1][j])); } db.Insert(DB_TABLE_NOTES, null, row); } }