Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. @Override
  2. public void onCreate(SQLiteDatabase db) {
  3. String create_college_table = "CREATE TABLE " + TableName + " (" +
  4. " `"+KEY_ID+"` INTEGER PRIMARY KEY AUTOINCREMENT,n" +
  5. " `"+KEY_DATE+"` DATETIME NOT NULL UNIQUE,n" +
  6. " `"+KEY_JSON+"` longtext NOT NULLn" +
  7. ")";
  8. db.execSQL(create_college_table);
  9. }
  10.  
  11. public void testit() {
  12. // write the row into the database:
  13. SQLiteDatabase db = this.getWritableDatabase();
  14. ContentValues insertValues = new ContentValues();
  15. // DATE IS FOURTH OF AUGUST 2015
  16. insertValues.put(KEY_DATE, "04082015");
  17. insertValues.put(KEY_JSON, "{test}");
  18. db.insert(
  19. TableName,
  20. null,
  21. insertValues
  22. );
  23.  
  24.  
  25. // Now read from the database, select the row that was
  26. // just inserted
  27. String selectQuery = "SELECT * FROM " + TableName + " " +
  28. "WHERE " + KEY_JSON + " = '{test}'";
  29. SQLiteDatabase db_read = this.getWritableDatabase();
  30. Cursor cursor = db_read.rawQuery(selectQuery, null);
  31. // Viewing the log the inserted date (04082015) has been
  32. // outputted as 40082015, this does not occur with dates
  33. // were the day in the month is ten or larger?!
  34. Log.e("testMethod", DatabaseUtils.dumpCursorToString(cursor));
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement