Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

#302 #388

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

#302 #388

wants to merge 2 commits into from

Conversation

jamshidrostami
Copy link
Contributor

Bray rounds have changed to 10 ends of 3 arrows each

Bray rounds have changed to 10 ends of 3 arrows each
Copy link
Owner

@DreierF DreierF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your PR!

I really appreciate the work you have put into this :)

val db = testHelper.createDatabase(TEST_DB_NAME, 26)
insertTrainingDataForVersion26(db)

val count = db.query("select * from StandardRound").count
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor stylistic issue, but could you please uppercase the SQL keywords select->SELECT from->FROM to be consistent with the rest of the app and to make them easier distinguishable from table and column names?

)


database.query("SELECT `id`, `targetId`, `targetScoringStyleIndex`, `targetDiameter` FROM `Round` WHERE trainingId IN (SELECT t.id FROM Training as t JOIN StandardRound as s WHERE s.name in ('Bray I', 'Bray II'))")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to break this query up into multiple lines so that it's easier to read.

)
database.execSQL(
"UPDATE Round SET shotsPerEnd=3, maxEndCount=10 " +
"WHERE trainingId IN (SELECT t.id FROM Training as t JOIN StandardRound as s WHERE s.name ='Bray I')"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately you cannot use the name here (and in the queries below) to filter for the correct round the the name is language dependent and might be different for other locales. It is save to assume that the round always has the same ID as it is always inserted into the database as first in a specified order.


fun addEnd(database: SupportSQLiteDatabase, target: Target, end: End, fileName: String?, index: Int) {
val shots = mutableListOf<Shot>()
database.query("SELECT `id`, `index`, `scoringRing` FROM Shot WHERE endId = ${end.id} LIMIT 3")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit dangerous as the result of LIMIT is not deterministic if no SORT BY clause is given. (Should be sorted by id)

val cursor = database.query("SELECT `fileName` FROM `EndImage` WHERE `endId` = ${end.id}")
var fileName: String? = null
if (cursor.moveToFirst()) {
fileName = cursor.getString(0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An end can have multiple images not just zero or one. The rest would be lost.

}

private fun deleteEnds(database: SupportSQLiteDatabase, ids: String) {
database.execSQL("delete from end where id in (" + ids + ")")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also use uppercase commands here and camelcase for the table names

multiple EndImages for an End
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants