Skip to content

Commit 42130ec

Browse files
committed
Fix invalid getVOcable SQL template conversion
Signed-off-by: Aron Heinecke <aron.heinecke@t-online.de>
1 parent d930b5b commit 42130ec

File tree

1 file changed

+18
-19
lines changed
  • app/src/main/java/vocabletrainer/heinecke/aron/vocabletrainer/lib

1 file changed

+18
-19
lines changed

app/src/main/java/vocabletrainer/heinecke/aron/vocabletrainer/lib/Database.kt

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,13 @@ class Database {
6565
*/
6666
fun getVocable(vocID: Int, listID: Int): VEntry? {
6767
db!!.rawQuery(
68-
"SELECT $KEY_TIP,$KEY_ADDITION,$KEY_LAST_USED"
69-
+ ",tVoc.$KEY_CREATED,$KEY_CORRECT,$KEY_WRONG"
70-
+ ",tVoc.$KEY_TABLE,$KEY_NAME_A,$KEY_NAME_B,$KEY_NAME_TBL"
71-
+ ",tList.$KEY_CREATED;$KEY_POINTS"
72-
+ " FROM $TBL_VOCABLE tVoc"
73-
+ " JOIN $TBL_TABLES tList ON tVoc.$KEY_TABLE = tList.$KEY_TABLE"
74-
+ " LEFT JOIN $TBL_SESSION ses ON tVoc.$KEY_TABLE = ses.$KEY_TABLE"
75-
+ " AND tVoc.$KEY_VOC = ses.$KEY_VOC"
76-
+ " WHERE tVoc.$KEY_TABLE = ? AND tVoc.$KEY_VOC = ?", arrayOf(listID.toString(), vocID.toString())).use { cV ->
68+
"SELECT $KEY_TIP,$KEY_ADDITION,$KEY_LAST_USED,tVoc.$KEY_CREATED,$KEY_CORRECT,"
69+
+"$KEY_WRONG,tVoc.$KEY_TABLE,$KEY_NAME_A,$KEY_NAME_B,$KEY_NAME_TBL,tList.$KEY_CREATED,"
70+
+"$KEY_POINTS "
71+
+"FROM $TBL_VOCABLE tVoc "
72+
+"JOIN $TBL_TABLES tList ON tVoc.$KEY_TABLE = tList.$KEY_TABLE "
73+
+"LEFT JOIN $TBL_SESSION ses ON tVoc.$KEY_TABLE = ses.$KEY_TABLE AND tVoc.$KEY_VOC = ses.$KEY_VOC"
74+
+"WHERE tVoc.$KEY_TABLE = ? AND tVoc.$KEY_VOC = ?", arrayOf(listID.toString(), vocID.toString())).use { cV ->
7775
return if (cV.moveToNext()) {
7876
val list = VList(listID, cV.getString(7), cV.getString(8),
7977
cV.getString(9), Date(cV.getLong(10)))
@@ -195,7 +193,8 @@ class Database {
195193
@Deprecated("")
196194
fun getEntryPoints(ent: VEntry): Int {
197195
db!!.rawQuery("SELECT $KEY_POINTS "
198-
+ "FROM $TBL_SESSION WHERE $KEY_TABLE = ? AND $KEY_VOC = ?", arrayOf(ent.list.id.toString(), ent.id.toString())).use { cursor -> return if (cursor.moveToNext()) cursor.getInt(0) else -1 }
196+
+ "FROM $TBL_SESSION WHERE $KEY_TABLE = ? AND $KEY_VOC = ?",
197+
arrayOf(ent.list.id.toString(), ent.id.toString())).use { cursor -> return if (cursor.moveToNext()) cursor.getInt(0) else -1 }
199198
}
200199

201200
/**
@@ -412,7 +411,7 @@ class Database {
412411
val args = arrayOf(tbl.name, tbl.nameA, tbl.nameB)
413412
try {
414413
db!!.rawQuery("SELECT $KEY_TABLE FROM $TBL_TABLES "
415-
+"WHERE $KEY_NAME_TBL = ? AND $KEY_NAME_A = ? AND $KEY_NAME_B = ? LIMIT 1", args).use { cursor ->
414+
+ "WHERE $KEY_NAME_TBL = ? AND $KEY_NAME_A = ? AND $KEY_NAME_B = ? LIMIT 1", args).use { cursor ->
416415
var id = -1
417416
if (cursor.moveToNext()) {
418417
id = cursor.getInt(0)
@@ -618,7 +617,7 @@ class Database {
618617
val lst = ArrayList<VList>(10)
619618
try {
620619
db!!.rawQuery("SELECT ses.$KEY_TABLE tbl,$KEY_NAME_A,$KEY_NAME_B,$KEY_NAME_TBL,$KEY_CREATED "
621-
+"FROM $TBL_SESSION_TABLES ses JOIN $TBL_TABLES tbls ON tbls.$KEY_TABLE == ses.$KEY_TABLE", null).use { cursor ->
620+
+ "FROM $TBL_SESSION_TABLES ses JOIN $TBL_TABLES tbls ON tbls.$KEY_TABLE == ses.$KEY_TABLE", null).use { cursor ->
622621
while (cursor.moveToNext()) {
623622
lst.add(VList(cursor.getInt(0), cursor.getString(1),
624623
cursor.getString(2), cursor.getString(3),
@@ -699,10 +698,10 @@ class Database {
699698
try {
700699
db!!.rawQuery(
701700
"SELECT $KEY_TIP,$KEY_ADDITION,$KEY_LAST_USED,tbl.$KEY_CREATED,$KEY_CORRECT,$KEY_WRONG,tbl.$KEY_VOC,$KEY_POINTS "
702-
+"FROM $TBL_VOCABLE tbl "
703-
+"LEFT JOIN $TBL_SESSION ses ON tbl.$KEY_VOC = ses.$KEY_VOC AND tbl.$KEY_TABLE = ses.$KEY_TABLE "
704-
+"WHERE tbl.$KEY_TABLE = ? AND tbl.$KEY_VOC != ? AND ( $KEY_POINTS IS NULL OR $KEY_POINTS < ? ) "
705-
+"ORDER BY RANDOM() LIMIT 1", arg).use { cV ->
701+
+ "FROM $TBL_VOCABLE tbl "
702+
+ "LEFT JOIN $TBL_SESSION ses ON tbl.$KEY_VOC = ses.$KEY_VOC AND tbl.$KEY_TABLE = ses.$KEY_TABLE "
703+
+ "WHERE tbl.$KEY_TABLE = ? AND tbl.$KEY_VOC != ? AND ( $KEY_POINTS IS NULL OR $KEY_POINTS < ? ) "
704+
+ "ORDER BY RANDOM() LIMIT 1", arg).use { cV ->
706705
return if (cV.moveToNext()) {
707706
val meaningA: MutableList<String> = LinkedList()
708707
val meaningB: MutableList<String> = LinkedList()
@@ -933,8 +932,8 @@ class Database {
933932
db.execSQL("ALTER TABLE $TBL_VOCABLE_V1 ADD COLUMN $KEY_CORRECT INTEGER NOT NULL DEFAULT 0")
934933
db.execSQL("ALTER TABLE $TBL_VOCABLE_V1 ADD COLUMN $KEY_WRONG INTEGER NOT NULL DEFAULT 0")
935934
db.execSQL("ALTER TABLE $TBL_VOCABLE_V1 ADD COLUMN $KEY_CREATED INTEGER NOT NULL DEFAULT $time")
936-
val args = arrayOf(KEY_TABLE, KEY_VOC,KEY_TIP, KEY_ADDITION, KEY_LAST_USED,
937-
KEY_CREATED, KEY_CORRECT,KEY_WRONG).joinToString(separator = ",")
935+
val args = arrayOf(KEY_TABLE, KEY_VOC, KEY_TIP, KEY_ADDITION, KEY_LAST_USED,
936+
KEY_CREATED, KEY_CORRECT, KEY_WRONG).joinToString(separator = ",")
938937
val sqlCpy = "INSERT INTO $TBL_VOCABLE ($args) SELECT $args FROM $TBL_VOCABLE_V1"
939938
db.execSQL(sqlCpy)
940939
val colMA = arrayOf(KEY_TABLE, KEY_VOC, KEY_MEANING).joinToString(separator = ",")
@@ -948,7 +947,7 @@ class Database {
948947
}
949948
run {
950949
db.execSQL("ALTER TABLE $TBL_TABLES_V1 ADD COLUMN $KEY_CREATED INTEGER NOT NULL DEFAULT $time")
951-
val args = arrayOf(KEY_NAME_TBL, KEY_TABLE,KEY_NAME_A, KEY_NAME_B, KEY_CREATED).joinToString(separator = ",")
950+
val args = arrayOf(KEY_NAME_TBL, KEY_TABLE, KEY_NAME_A, KEY_NAME_B, KEY_CREATED).joinToString(separator = ",")
952951
val sqlCpy = "INSERT INTO $TBL_TABLES ($args) SELECT $args FROM $TBL_TABLES_V1"
953952
db.execSQL(sqlCpy)
954953
db.execSQL("DROP TABLE $TBL_TABLES_V1")

0 commit comments

Comments
 (0)