Esempio n. 1
0
        public override void OnCreate(SQLiteDatabase paramSQLiteDatabase)
        {
            // Create table "wikinotes"
            paramSQLiteDatabase.ExecSQL("CREATE TABLE " + WikiNote.Notes.TABLE_WIKINOTES + " (" + WikiNote.Notes.Id + " INTEGER PRIMARY KEY,"
                + WikiNote.Notes.TITLE + " TEXT COLLATE LOCALIZED NOT NULL,"
                + WikiNote.Notes.BODY + " TEXT,"
                + WikiNote.Notes.CREATED_DATE + " INTEGER,"
                + WikiNote.Notes.MODIFIED_DATE + " INTEGER" + ");");

            // Initialize database
            ContentValues localContentValues = new ContentValues();
            localContentValues.Put(WikiNote.Notes.TITLE, this._context.Resources.GetString(Resource.String.start_page));
            localContentValues.Put(WikiNote.Notes.BODY, this._context.Resources.GetString(Resource.String.top_note));
            long localLong = DateTime.Now.ToFileTimeUtc();
            localContentValues.Put(WikiNote.Notes.CREATED_DATE, localLong);
            localContentValues.Put(WikiNote.Notes.MODIFIED_DATE, localLong);

            paramSQLiteDatabase.Insert(WikiNote.Notes.TABLE_WIKINOTES, "huh?", localContentValues);

            localContentValues.Put(WikiNote.Notes.TITLE, "PageFormatting");
            localContentValues.Put(WikiNote.Notes.BODY, this._context.Resources.GetString(Resource.String.page_formatting_note));
            localContentValues.Put(WikiNote.Notes.CREATED_DATE, localLong);
            localContentValues.Put(WikiNote.Notes.MODIFIED_DATE, localLong);

            paramSQLiteDatabase.Insert(WikiNote.Notes.TABLE_WIKINOTES, "huh?", localContentValues);
        }
Esempio n. 2
0
 public void initDB(SQLiteDatabase db)
 {
     db.ExecSQL("DROP TABLE IF EXISTS " + "general");
     db.ExecSQL("DROP TABLE IF EXISTS " + "records");
     db.ExecSQL("create table records ("
         + "id integer primary key autoincrement,"
         + "time int,"
         + "difficulty text" + ");");
     db.ExecSQL("create table general ("
         + "difficulty text primary key,"
         + "avgTime int,"
         + "gamesCount int" + ");");
     ContentValues cv = new ContentValues();
     cv.Put("difficulty", "Easy");
     cv.Put("avgTime", 0);
     cv.Put("gamesCount", 0);
     db.Insert("general", null, cv);
     cv.Clear();
     cv.Put("difficulty", "Normal");
     cv.Put("avgTime", 0);
     cv.Put("gamesCount", 0);
     db.Insert("general", null, cv);
     cv.Clear();
     cv.Put("difficulty", "Hard");
     cv.Put("avgTime", 0);
     cv.Put("gamesCount", 0);
     db.Insert("general", null, cv);
 }
Esempio n. 3
0
            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);
                }
            }