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 @file:JvmName("RoomMasterTable")
17 
18 package androidx.room
19 
20 import androidx.annotation.RestrictTo
21 import kotlin.jvm.JvmName
22 import kotlin.jvm.JvmStatic
23 
24 /** Schema information about Room's master table. */
25 @Suppress("WeakerAccess")
26 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
27 public object RoomMasterTable {
28     /** The master table where room keeps its metadata information. */
29     public const val TABLE_NAME: String = "room_master_table"
30 
31     // must match the runtime property Room#MASTER_TABLE_NAME
32     public const val NAME: String = "room_master_table"
33     private const val COLUMN_ID: String = "id"
34     private const val COLUMN_IDENTITY_HASH: String = "identity_hash"
35     public const val DEFAULT_ID: String = "42"
36 
37     public const val CREATE_QUERY: String =
38         "CREATE TABLE IF NOT EXISTS " +
39             TABLE_NAME +
40             " (" +
41             COLUMN_ID +
42             " INTEGER PRIMARY KEY," +
43             COLUMN_IDENTITY_HASH +
44             " TEXT)"
45 
46     public const val READ_QUERY: String =
47         "SELECT " +
48             COLUMN_IDENTITY_HASH +
49             " FROM " +
50             TABLE_NAME +
51             " WHERE " +
52             COLUMN_ID +
53             " = " +
54             DEFAULT_ID +
55             " LIMIT 1"
56 
57     /** We don't escape here since we know what we are passing. */
58     @JvmStatic
createInsertQuerynull59     public fun createInsertQuery(hash: String): String {
60         return "INSERT OR REPLACE INTO " +
61             TABLE_NAME +
62             " (" +
63             COLUMN_ID +
64             "," +
65             COLUMN_IDENTITY_HASH +
66             ")" +
67             " VALUES(" +
68             DEFAULT_ID +
69             ", '" +
70             hash +
71             "')"
72     }
73 }
74