Auto-detect database version
Originally reported on Google Code with ID 6 ``` Currently you must specify the version of SQLite to use, it would be a nice addition to have that auto-detected by phpLiteAdmin (if not specified).
The SQLite file does specify the file format (the version), so this would certainly be doable. ```
Reported by `ian.aldrighetti` on 2011-03-07 22:32:39
Comments (4)
-
-
Account Deleted ``` http://sqlite.org/fileformat2.html
Take a look at "1.2.1 Magic Header String" -- SQLite v3 files will start out with "SQLite format 3" and SQLite v2 *should* start with "SQLite format 2"
So you would just need to open the file and check out the first 15 bytes or so to check the version number. ```
Reported by `ian.aldrighetti` on 2011-03-08 03:38:11
-
``` Just implemented this in v1.5 - checked into SVN.
Here is the code:
$content = strtolower(file_get_contents($this->data['path'], NULL, NULL, 0, 40)); $p = strpos($content, " this file contains an sqlite 2"); if($p!==false) return 2; else return 3; ```
Reported by `diracleo` on 2011-03-09 08:59:13 - Status changed: `Fixed`
-
Account Deleted ``` It might be a wiser idea to do:
$fp = fopen($this->data['path'], 'r');
$content = strtolower(fread($fp, 40));
fclose($fp);
Otherwise file_get_contents will cause a memory limit exceeded error when the SQLite database is huge. ```
Reported by `ian.aldrighetti` on 2011-03-09 15:57:07
- Log in to comment
``` This is something I was trying to do for a few hours but couldn't figure out how. If you think of a way, you should implement it or tell me your idea. ```
Reported by `diracleo` on 2011-03-08 03:31:22 - Status changed: `Started`