-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved the Query class to avoid passing SQL
- Loading branch information
1 parent
67ab372
commit ebb2f39
Showing
8 changed files
with
84 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,26 @@ | ||
package org.odk.collect.db.sqlite | ||
|
||
data class Query( | ||
sealed class Query( | ||
val selection: String, | ||
val selectionArgs: Array<String> | ||
) | ||
) { | ||
class Eq(val column: String, val value: String) : Query( | ||
"$column = ?", | ||
arrayOf(value) | ||
) | ||
|
||
class NotEq(val column: String, val value: String) : Query( | ||
"$column != ?", | ||
arrayOf(value) | ||
) | ||
|
||
class And(val queryA: Query, val queryB: Query) : Query( | ||
"(${queryA.selection} AND ${queryB.selection})", | ||
queryA.selectionArgs + queryB.selectionArgs | ||
) | ||
|
||
class Or(val queryA: Query, val queryB: Query) : Query( | ||
"(${queryA.selection} OR ${queryB.selection})", | ||
queryA.selectionArgs + queryB.selectionArgs | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters