Update statements

Signed-off-by: Rahul Rudragoudar <rr83019@gmail.com>
This commit is contained in:
Rahul Rudragoudar 2021-03-02 21:33:46 +05:30
parent 843367007f
commit ed39535039
No known key found for this signature in database
GPG Key ID: 0D2CE231A7287EBC

View File

@ -15,6 +15,8 @@ class Statements(dbConn: DBConn) {
"secret varchar, " + "secret varchar, " +
"provider varchar, " + "provider varchar, " +
"contentType varchar, " + "contentType varchar, " +
"contentLevel varchar, " +
"contentInput varchar, " +
"image blob, " + "image blob, " +
"attempted int default 0, " + "attempted int default 0, " +
"PRIMARY KEY(token))" "PRIMARY KEY(token))"
@ -32,8 +34,8 @@ class Statements(dbConn: DBConn) {
val insertPstmt: PreparedStatement = dbConn.con.prepareStatement( val insertPstmt: PreparedStatement = dbConn.con.prepareStatement(
"INSERT INTO " + "INSERT INTO " +
"challenge(id, secret, provider, contentType, image) " + "challenge(id, secret, provider, contentType, contentLevel, contentInput, image) " +
"VALUES (?, ?, ?, ?, ?)", "VALUES (?, ?, ?, ?, ?, ?, ?)",
Statement.RETURN_GENERATED_KEYS Statement.RETURN_GENERATED_KEYS
) )
@ -48,7 +50,7 @@ class Statements(dbConn: DBConn) {
"SELECT c.secret, c.provider " + "SELECT c.secret, c.provider " +
"FROM challenge c, mapId m " + "FROM challenge c, mapId m " +
"WHERE m.token=c.token AND " + "WHERE m.token=c.token AND " +
"DATEDIFF(MINUTE, CURRENT_TIMESTAMP, DATEADD(MINUTE, 1, m.lastServed)) > 0 AND " + "DATEDIFF(MINUTE, CURRENT_TIMESTAMP, DATEADD(MINUTE, 5, m.lastServed)) > 0 AND " +
"m.uuid = ?" "m.uuid = ?"
) )
@ -71,7 +73,10 @@ class Statements(dbConn: DBConn) {
val tokenPstmt: PreparedStatement = dbConn.con.prepareStatement( val tokenPstmt: PreparedStatement = dbConn.con.prepareStatement(
"SELECT token " + "SELECT token " +
"FROM challenge " + "FROM challenge " +
"WHERE attempted < 10 " + "WHERE attempted < 10 AND " +
"contentLevel = ? AND " +
"contentType = ? AND " +
"contentInput = ? " +
"ORDER BY RAND() LIMIT 1" "ORDER BY RAND() LIMIT 1"
) )
@ -86,7 +91,7 @@ class Statements(dbConn: DBConn) {
) )
val mapIdGCPstmt: PreparedStatement = dbConn.con.prepareStatement( val mapIdGCPstmt: PreparedStatement = dbConn.con.prepareStatement(
"DELETE FROM mapId WHERE DATEDIFF(MINUTE, CURRENT_TIMESTAMP, DATEADD(MINUTE, 1, lastServed)) < 0" "DELETE FROM mapId WHERE DATEDIFF(MINUTE, CURRENT_TIMESTAMP, DATEADD(MINUTE, 5, lastServed)) < 0"
) )
val getCountChallengeTable: PreparedStatement = dbConn.con.prepareStatement( val getCountChallengeTable: PreparedStatement = dbConn.con.prepareStatement(