Closed
Bug 1226461
Opened 9 years ago
Closed 9 years ago
Use IN when checking for tables
Categories
(Firefox for iOS :: Data Storage, defect)
Tracking
()
RESOLVED
FIXED
People
(Reporter: rnewman, Assigned: roliusz, Mentored)
Details
(Whiteboard: [good first bug][lang=swift])
Attachments
(1 file)
extension SQLiteDBConnection {
func tablesExist(names: Args) -> Bool {
let count = names.count
let orClause = Array(count: count, repeatedValue: "name = ?").joinWithSeparator(" OR ")
let tablesSQL = "SELECT name FROM sqlite_master WHERE type = 'table' AND (\(orClause))"
let res = self.executeQuery(tablesSQL, factory: StringFactory, withArgs: names)
log.debug("\(res.count) tables exist. Expected \(count)")
return res.count > 0
}
}
Running query "SELECT name FROM sqlite_master WHERE type = 'table' AND (name = ? OR name = ? OR name = ? OR name = ? OR name = ? OR name = ? OR name = ? OR name = ? OR name = ? OR name = ? OR name = ? OR name = ? OR name = ?);
This is what SQL 'IN' is for. There are great examples elsewhere in the codebase:
https://github.com/mozilla/firefox-ios/blob/1e57eac39b9488c3747a76dc63f8b0c58f74c007/Storage/SQL/SQLiteHistory.swift#L903
| Assignee | ||
Comment 1•9 years ago
|
||
I was not sure if the same "BrowserDB" will be used in this case. I hope it helps.
extension SQLiteDBConnection {
func tablesExist(names: Args) -> Bool {
let count = names.count
let orClause = BrowserDB.varlist(names.count)
let tablesSQL = "SELECT name FROM sqlite_master WHERE type = 'table' AND name IN (\(orClause))"
let res = self.executeQuery(tablesSQL, factory: StringFactory, withArgs: names)
log.debug("\(res.count) tables exist. Expected \(count)")
return res.count > 0
}
}
| Assignee | ||
Comment 2•9 years ago
|
||
These orClauses could be also written as inClauses in this case to keep it clean, which I forgot.
extension SQLiteDBConnection {
func tablesExist(names: Args) -> Bool {
let count = names.count
let inClause = BrowserDB.varlist(names.count)
let tablesSQL = "SELECT name FROM sqlite_master WHERE type = 'table' AND name IN (\(inClause))"
let res = self.executeQuery(tablesSQL, factory: StringFactory, withArgs: names)
log.debug("\(res.count) tables exist. Expected \(count)")
return res.count > 0
}
}
| Reporter | ||
Comment 3•9 years ago
|
||
Roland, please take a look at <https://github.com/mozilla/firefox-ios#creating-a-pull-request> and submit a pull request with your changes.
You should also take that opportunity to make sure the project still builds and tests still pass. Thanks!
| Assignee | ||
Comment 4•9 years ago
|
||
Hello Richard! I am not sure how to proceed with the pull request. I am not sure what the base and compare option is under "Compare changes".
| Reporter | ||
Comment 5•9 years ago
|
||
One side is 'master' in the main repo.
The other is your feature branch in your fork. So you take the usual GitHub approach of:
* Fork the repo.
* Clone it.
* Check out a branch to work in: `git checkout -b roland/bug-1226461`
* Make your changes and commit your work: `git commit -m "Bug 1226461 - Use IN when checking for tables."`
* Push your branch to GitHub: `git push origin roland/bug-1226461`
* Create the PR back to our `master` branch from your feature branch.
The GitHub docs cover this in more detail:
https://help.github.com/articles/fork-a-repo/
| Assignee | ||
Comment 6•9 years ago
|
||
Thank you Richard.
I have made the changes and created a PR.
https://github.com/roliusz/firefox-ios/pull/1
Thanks!
| Reporter | ||
Comment 7•9 years ago
|
||
Attachment #8697591 -
Flags: review?(sleroux)
| Reporter | ||
Comment 8•9 years ago
|
||
(Throwing this at Steph to review so he has an opportunity to get more familiar with this code.)
Assignee: nobody → roliusz
Comment 9•9 years ago
|
||
Comment on attachment 8697591 [details] [review]
Pull req.
Looks good - thanks for the patch!
Attachment #8697591 -
Flags: review?(sleroux) → review+
| Reporter | ||
Comment 10•9 years ago
|
||
Steph, could you rebase and land this?
Status: NEW → ASSIGNED
Flags: needinfo?(sleroux)
Comment 11•9 years ago
|
||
master 83e21f15a3784253715d6acaa7d64ee241a84137
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Flags: needinfo?(sleroux)
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•