Rev 117 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 117 | Rev 150 | ||
---|---|---|---|
Line 17... | Line 17... | ||
17 | * limitations under the License. |
17 | * limitations under the License. |
18 | */ |
18 | */ |
19 | 19 | ||
20 | if (!defined('IN_OIDPLUS')) die(); |
20 | if (!defined('IN_OIDPLUS')) die(); |
21 | 21 | ||
22 | interface OIDplusDataBase { |
22 | abstract class OIDplusDataBase { |
- | 23 | protected $connected = false; |
|
- | 24 | ||
- | 25 | public abstract static function name(); |
|
23 | public function query($sql); |
26 | public abstract function query($sql, $prepared_args=null); |
24 | public function num_rows($res); |
27 | public abstract function num_rows($res); |
25 | public function fetch_array($res); |
28 | public abstract function fetch_array($res); |
26 | public function fetch_object($res); |
29 | public abstract function fetch_object($res); |
27 | public function real_escape_string($str); |
30 | public abstract function insert_id(); |
28 | public function insert_id(); |
31 | public abstract function error(); |
29 | public function escape_bool($str); |
32 | public abstract function transaction_begin(); |
30 | public function set_charset($charset); |
33 | public abstract function transaction_commit(); |
31 | public function error(); |
34 | public abstract function transaction_rollback(); |
- | 35 | ||
- | 36 | // TODO: better create some kind of Object-Type-API that does the sorting. But this means, the sorting won't be done with SQL |
|
32 | public function natOrder($fieldname, $maxdepth=100); |
37 | public function natOrder($fieldname, $maxdepth=100) { // TODO: also "desc" and "asc" support? |
- | 38 | /* |
|
- | 39 | CREATE FUNCTION SPLIT_STRING(str VARCHAR(255), delim VARCHAR(12), pos INT) |
|
- | 40 | RETURNS VARCHAR(255) |
|
- | 41 | RETURN REPLACE(SUBSTRING(SUBSTRING_INDEX(str, delim, pos), |
|
- | 42 | LENGTH(SUBSTRING_INDEX(str, delim, pos-1)) + 1), delim, ''); |
|
- | 43 | */ |
|
- | 44 | $out = array(); |
|
- | 45 | $out[] = "(REPLACE(SUBSTRING(SUBSTRING_INDEX($fieldname, ':', 1),LENGTH(SUBSTRING_INDEX($fieldname, ':', 0)) + 1),':', '')) asc"; // first sort by NS (namespace) |
|
- | 46 | for ($i=1; $i<=$maxdepth; $i++) { |
|
- | 47 | // $out[] = "LENGTH(SPLIT_STRING($fieldname, '.', $i) asc"; |
|
- | 48 | // $out[] = "SPLIT_STRING($fieldname, '.', $i) asc"; |
|
- | 49 | ||
- | 50 | $out[] = "LENGTH(REPLACE(SUBSTRING(SUBSTRING_INDEX($fieldname, '.', $i),LENGTH(SUBSTRING_INDEX($fieldname, '.', $i-1)) + 1),'.', '')) asc"; |
|
- | 51 | $out[] = "(REPLACE(SUBSTRING(SUBSTRING_INDEX($fieldname, '.', $i),LENGTH(SUBSTRING_INDEX($fieldname, '.', $i-1)) + 1),'.', '')) asc"; |
|
- | 52 | ||
- | 53 | } |
|
- | 54 | return implode(', ', $out); |
|
- | 55 | } |
|
- | 56 | ||
- | 57 | protected function afterConnect($html) { |
|
- | 58 | // Check if database tables are existing |
|
- | 59 | $table_names = array('objects', 'asn1id', 'iri', 'ra', 'config'); |
|
- | 60 | foreach ($table_names as $tablename) { |
|
- | 61 | if (!$this->query("DESCRIBE `".OIDPLUS_TABLENAME_PREFIX.$tablename."`")) { |
|
- | 62 | if ($html) { |
|
- | 63 | echo '<h1>Error</h1><p>Table <b>'.OIDPLUS_TABLENAME_PREFIX.$tablename.'</b> does not exist.</p>'; |
|
- | 64 | if (is_dir(__DIR__.'/../../../setup')) { |
|
- | 65 | echo '<p>Please run <a href="setup/">setup</a> again.</p>'; |
|
- | 66 | } |
|
- | 67 | } else { |
|
- | 68 | echo 'Error: Table '.OIDPLUS_TABLENAME_PREFIX.$tablename.' does not exist.'; |
|
- | 69 | if (is_dir(__DIR__.'/../../../setup')) { |
|
- | 70 | echo ' Please run setup again.'; |
|
- | 71 | } |
|
- | 72 | } |
|
- | 73 | die(); |
|
- | 74 | } |
|
- | 75 | } |
|
- | 76 | ||
- | 77 | // Do the database table tables need an update? |
|
- | 78 | // Note: The config setting "database_version" is inserted in setup/sql/...sql, not in the OIDplus core init |
|
- | 79 | ||
- | 80 | /* |
|
- | 81 | $res = $this->query("SELECT value FROM `".OIDPLUS_TABLENAME_PREFIX."config` WHERE name = 'database_version'"); |
|
- | 82 | $row = $this->fetch_array($res); |
|
- | 83 | $version = $row['value']; |
|
- | 84 | if ($version == 200) { |
|
- | 85 | // Do stuff to update 200 -> 201 |
|
- | 86 | $version = 201; |
|
- | 87 | $this->query("UPDATE `".OIDPLUS_TABLENAME_PREFIX."config` SET value = '$version' WHERE name = 'database_version'"); |
|
- | 88 | } |
|
- | 89 | if ($version == 201) { |
|
- | 90 | // Do stuff to update 201 -> 202 |
|
- | 91 | $version = 202; |
|
- | 92 | $this->query("UPDATE `".OIDPLUS_TABLENAME_PREFIX."config` SET value = '$version' WHERE name = 'database_version'"); |
|
- | 93 | } |
|
- | 94 | */ |
|
- | 95 | } |
|
- | 96 | ||
- | 97 | public function isConnected() { |
|
- | 98 | return $this->connected; |
|
- | 99 | } |
|
33 | } |
100 | } |
34 | 101 |