1/* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.arch.persistence.room; 18 19import android.support.annotation.RestrictTo; 20 21/** 22 * Schema information about Room's master table. 23 * 24 * @hide 25 */ 26@SuppressWarnings("WeakerAccess") 27@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) 28public class RoomMasterTable { 29 /** 30 * The master table where room keeps its metadata information. 31 */ 32 public static final String TABLE_NAME = "room_master_table"; 33 // must match the runtime property Room#MASTER_TABLE_NAME 34 public static final String NAME = "room_master_table"; 35 private static final String COLUMN_ID = "id"; 36 private static final String COLUMN_IDENTITY_HASH = "identity_hash"; 37 public static final String DEFAULT_ID = "42"; 38 39 public static final String CREATE_QUERY = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" 40 + COLUMN_ID + " INTEGER PRIMARY KEY," 41 + COLUMN_IDENTITY_HASH + " TEXT)"; 42 43 public static final String READ_QUERY = "SELECT " + COLUMN_IDENTITY_HASH 44 + " FROM " + TABLE_NAME + " WHERE " 45 + COLUMN_ID + " = " + DEFAULT_ID + " LIMIT 1"; 46 47 /** 48 * We don't escape here since we know what we are passing. 49 */ 50 public static String createInsertQuery(String hash) { 51 return "INSERT OR REPLACE INTO " + TABLE_NAME + " (" 52 + COLUMN_ID + "," + COLUMN_IDENTITY_HASH + ")" 53 + " VALUES(" + DEFAULT_ID + ", \"" + hash + "\")"; 54 } 55} 56