ARC2_StoreQueryHandler.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * ARC2 RDF Store Query Handler
  4. *
  5. * @author Benjamin Nowack
  6. * @license <http://arc.semsol.org/license>
  7. * @homepage <http://arc.semsol.org/>
  8. * @package ARC2
  9. * @version 2010-11-16
  10. */
  11. ARC2::inc('Class');
  12. class ARC2_StoreQueryHandler extends ARC2_Class {
  13. function __construct($a, &$caller) {
  14. parent::__construct($a, $caller);
  15. }
  16. function __init() {/* db_con */
  17. parent::__init();
  18. $this->xsd = 'http://www.w3.org/2001/XMLSchema#';
  19. $this->allow_extension_functions = $this->v('store_allow_extension_functions', 1, $this->a);
  20. $this->keep_time_limit = $this->v('keep_time_limit', 0, $this->a);
  21. $this->handler_type = '';
  22. }
  23. /* */
  24. function getTermID($val, $term = '') {
  25. return $this->store->getTermID($val, $term);
  26. }
  27. function hasHashColumn($tbl) {
  28. return $this->store->hasHashColumn($tbl);
  29. }
  30. function getValueHash($val) {
  31. return $this->store->getValueHash($val);
  32. }
  33. /* */
  34. function getTripleTable() {
  35. $r = $this->store->getTablePrefix() . 'triple';
  36. return $r;
  37. }
  38. /* */
  39. function createMergeTable() {
  40. $split_ps = $this->store->getSetting('split_predicates', array());
  41. if (!$split_ps) return 1;
  42. $this->mrg_table_id = 'MRG_' . $this->store->getTablePrefix() . crc32(uniqid(rand()));
  43. $con = $this->store->getDBCon();
  44. $this->queryDB("FLUSH TABLES", $con);
  45. $indexes = $this->v('store_indexes', array('sp (s,p)', 'os (o,s)', 'po (p,o)'), $this->a);
  46. $index_code = $indexes ? 'KEY ' . join(', KEY ', $indexes) . ', ' : '';
  47. $prefix = $this->store->getTablePrefix();
  48. $sql = "
  49. CREATE TEMPORARY TABLE IF NOT EXISTS " . $prefix . "triple_all (
  50. t mediumint UNSIGNED NOT NULL,
  51. s mediumint UNSIGNED NOT NULL,
  52. p mediumint UNSIGNED NOT NULL,
  53. o mediumint UNSIGNED NOT NULL,
  54. o_lang_dt mediumint UNSIGNED NOT NULL,
  55. o_comp char(35) NOT NULL, /* normalized value for ORDER BY operations */
  56. s_type tinyint(1) NOT NULL default 0, /* uri/bnode => 0/1 */
  57. o_type tinyint(1) NOT NULL default 0, /* uri/bnode/literal => 0/1/2 */
  58. misc tinyint(1) NOT NULL default 0, /* temporary flags */
  59. UNIQUE KEY (t), " . $index_code . " KEY (misc)
  60. )
  61. ";
  62. $v = $this->store->getDBVersion();
  63. $sql .= (($v < '04-01-00') && ($v >= '04-00-18')) ? 'ENGINE' : (($v >= '04-01-02') ? 'ENGINE' : 'TYPE');
  64. $sql .= "=MERGE UNION=(" . $prefix . "triple" ;
  65. foreach ($split_ps as $pos => $p) {
  66. $sql .= ',' . $prefix . 'triple_' . abs(crc32($p));
  67. }
  68. $sql .= ")";
  69. //$sql .= ($v >= '04-00-00') ? " CHARACTER SET utf8" : "";
  70. //$sql .= ($v >= '04-01-00') ? " COLLATE utf8_unicode_ci" : "";
  71. //echo $sql;
  72. return $this->queryDB($sql, $con);
  73. }
  74. function dropMergeTable() {
  75. return 1;
  76. $sql = "DROP TABLE IF EXISTS " . $this->store->getTablePrefix() . "triple_all";
  77. //echo $sql;
  78. return $this->queryDB($sql, $this->store->getDBCon());
  79. }
  80. }