Update sqlite3_prepare() to sqlite3_prepare_v2() in pdo_sqlite.cpp
commitaa428ef7531e1e1249341577f53c032680cd0850
authorJeff Hemphill <jhemphill@fb.com>
Fri, 6 Mar 2020 01:11:50 +0000 (5 17:11 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 6 Mar 2020 01:15:50 +0000 (5 17:15 -0800)
tree728815c4285be95ebb41d04811ab72663af52bf0
parentc9a452c73eca20f45349f816bf4fd96627438d95
Update sqlite3_prepare() to sqlite3_prepare_v2() in pdo_sqlite.cpp

Summary:
D20239885 updates the SQLite schema but doesn't bump the version. In theory this was safe, but Daniel15 [ran into an issue](https://fb.workplace.com/groups/175783763370419/) where an existing request failed with error code [`SQLITE_SCHEMA`](https://sqlite.org/rescode.html#schema) due to executing a stale prepared statement.

From [the SQLite docs](https://sqlite.org/rescode.html#schema):

> The SQLITE_SCHEMA result code indicates that the database schema has changed. This result code can be returned from sqlite3_step() for a prepared statement that was generated using sqlite3_prepare() or sqlite3_prepare16(). If the database schema was changed by some other process in between the time that the statement was prepared and the time the statement was run, this error can result.

> If a prepared statement is generated from sqlite3_prepare_v2() then the statement is automatically re-prepared if the schema changes, up to SQLITE_MAX_SCHEMA_RETRY times (default: 50). The sqlite3_step() interface will only return SQLITE_SCHEMA back to the application if the failure persists after these many retries.

Unfortunately, SQLFacts uses `pdo_sqlite.cpp`, which uses the legacy `sqlite3_prepare()` function. This is a drop-in replacement, and I'm already using `sqlite3_prepare_v2()` in the native autoloader:

https://our.intern.facebook.com/intern/diffusion/FBS/browse/master/fbcode/hphp/util/sqlite-wrapper.cpp?commit=509e9b894abcb258fbba3cd4ce7599c0ce6356b0&lines=302-303

Created from Diffusion's 'Open in Editor' feature.

Reviewed By: ricklavoie

Differential Revision: D20269726

fbshipit-source-id: a5e1046559f719d284cb17d5bcd753b806a141a3
hphp/runtime/ext/pdo_sqlite/pdo_sqlite.cpp