Skip to content

Replace deprecated Sqlite-calls with PDO-calls #746

Merged
thijskh merged 4 commits into
simplesamlphp:masterfrom
tvdijen:patch-sqlite
May 19, 2018
Merged

Replace deprecated Sqlite-calls with PDO-calls #746
thijskh merged 4 commits into
simplesamlphp:masterfrom
tvdijen:patch-sqlite

Conversation

@tvdijen
Copy link
Copy Markdown
Member

@tvdijen tvdijen commented Dec 10, 2017

Attempt to fix #744
I have tested it with the oauth-module (currently the only module using it) and it's working like a charm!
Should be fully backwards compatible too!


$dbfile = 'sqlite:' . $sqllitedir . $name . '.sqlite';
if ($this->db = new \PDO($dbfile)) {
$q = @$this->db->query('SELECT key1 FROM data LIMIT 1');
Copy link
Copy Markdown

@LukeLeber LukeLeber Dec 14, 2017

Choose a reason for hiding this comment

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

Error suppression is hardly ever a desirable thing. I know that the original source code had it as well, but shouldn't failures be loud and obvious?

Or better yet, possibly throw an exception like the enclosing if-else condition -- or configure PDO to throw exceptions.

Just food for thought :) It's good to see deprecated things going away.

Copy link
Copy Markdown
Member Author

@tvdijen tvdijen Dec 15, 2017

Choose a reason for hiding this comment

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

I think I agree with you here, however I'm a bit anxious to break behaviour here..
That would mean we have to wait for the 2.0 release before we can merge this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Now you've made me wonder if I should use the SimpleSAML\Database class here instead of directly calling PDO...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

At this point I see no easy way to do this, so I'd like to stick with this PR 'as is'.
@thijskh could you please review this?

Copy link
Copy Markdown
Member

@thijskh thijskh left a comment

Choose a reason for hiding this comment

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

I think this change improves over the current situation, even though there's indeed more ideas for further improvements.

I'm however a bit anxious to merge it without testcases. It seems to me the kind of class that's well-testable with unit tests. Would be good to confirm that way that before and after refactoring produce the same results, and of course to ensure it remains working in the future.

@tvdijen
Copy link
Copy Markdown
Member Author

tvdijen commented May 2, 2018

I have no clue where to start on that, since I'm totally unfamiliar with writing unit tests.

@tvdijen
Copy link
Copy Markdown
Member Author

tvdijen commented May 12, 2018

How does this look @thijskh?
You think I can add 'writing unit tests' to my resume?

tvdijen added 2 commits May 13, 2018 13:12
This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com
@thijskh
Copy link
Copy Markdown
Member

thijskh commented May 14, 2018

Very nice work! "Coverage increased (+0.7%) to 29.503%" \o/
Hope you now see that especially for rather 'self-contained' classes this is very doable and adds a lot of value.

One comment: I see that you create the sqlite database but do not remove it from disk at teardown. This is of course fine for travis but leaves cruft on the machine for people running the testsuite locally.

@tvdijen
Copy link
Copy Markdown
Member Author

tvdijen commented May 14, 2018

Fixed that!

@thijskh thijskh merged commit 67c29a6 into simplesamlphp:master May 19, 2018
@tvdijen tvdijen deleted the patch-sqlite branch May 19, 2018 16:26
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 20, 2023
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.

Sqlite has been deprecated

3 participants