Oracle.class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. * Define SQL for Mysql database system
  4. * @author valentin carruesco
  5. * @category Core
  6. * @license copyright
  7. */
  8. class Oracle
  9. {
  10. const label = 'Oracle';
  11. const connection = 'odbc:{{name}}';
  12. const description = 'Base authentifiée necessitant un serveur Oracle Database XE ou Oracle Database Entreprise, creation de source ODBC à prévoir';
  13. const table_escape = '"';
  14. const column_escape = '"';
  15. public static function pdo_attributes(){
  16. return array(
  17. PDO::ATTR_PERSISTENT => true
  18. );
  19. }
  20. public static function fields(){
  21. return array(
  22. array('id'=>'name','label'=>'Nom de la source ODBC','default'=>'','comment'=>''),
  23. array('id'=>'login','label'=>'Identifiant','default'=>'','comment'=>''),
  24. array('id'=>'password','label'=>'Mot de passe','default'=>'','comment'=>'')
  25. );
  26. }
  27. public static function processField(&$field,&$value,&$values,&$i){
  28. if($field['type'] == 'date'){
  29. $field['operator'].= ' to_date( ';
  30. $field['postoperator'].= ',\'YYYY-MM-DD\')';
  31. }
  32. switch($field['operator']){
  33. case 'IN':
  34. $field['tag'] = array();
  35. foreach (explode(',',$value) as $v2) {
  36. $tag = ':'.$i;
  37. $field['tag'][]= $tag;
  38. $values[$tag] = $v2;
  39. $i++;
  40. }
  41. $field['tag'] = implode(',',$field['tag']);
  42. $field['operator'] = 'IN(';
  43. $field['postoperator'] = ')';
  44. break;
  45. default:
  46. $tag = ':'.$i;
  47. $field['tag'] = $tag;
  48. $values[$tag] = $value;
  49. $i++;
  50. break;
  51. }
  52. }
  53. public static function types(){
  54. $types = array();
  55. $types['string'] = 'VARCHAR2(225) CHARACTER SET utf8 COLLATE utf8_general_ci';
  56. $types['longstring'] = 'TEXT CHARACTER SET utf8 COLLATE utf8_general_ci';
  57. $types['key'] = 'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY';
  58. $types['object'] = $types['timestamp'] = $types['datetime'] = $types['date'] = $types['int'] = 'INT(11)';
  59. $types['boolean'] = 'tinyint(1) NOT NULL DEFAULT \'0\'';
  60. $types['blob'] = ' BLOB';
  61. $types['float'] = 'FLOAT';
  62. $types['decimal'] = 'DECIMAL(20,2)';
  63. $types['default'] = 'TEXT CHARACTER SET utf8 COLLATE utf8_general_ci';
  64. return $types;
  65. }
  66. public static function beforeTransaction($pdo){
  67. $pdo->exec("set names utf8");
  68. }
  69. public static function select(){
  70. $sql = 'SELECT {{:selected}}{{value}}{{;}},{{/;}}{{/:selected}} FROM "{{table}}" {{?joins}}{{:joins}}LEFT JOIN "{{jointable2}}" ON "{{jointable1}}".{{field1}}= "{{jointable2}}".{{field2}} {{/:joins}}{{/?joins}} {{?filter}} WHERE {{:filter}} "{{table}}"."{{key}}" {{operator}} {{value}} {{postoperator}} {{;}} AND {{/;}} {{/:filter}} {{/?filter}} {{?orderby}}ORDER BY {{:orderby}}{{value}}{{;}},{{/;}}{{/:orderby}} {{/?orderby}}{{?limit}}FETCH NEXT {{:limit}}{{value}}{{;}}{{/;}} ROWS ONLY{{/:limit}}{{/?limit}}';
  71. return $sql;
  72. }
  73. public static function delete(){
  74. $sql = 'DELETE FROM "{{table}}" {{?filter}}WHERE {{:filter}}"{{key}}"{{operator}}{{value}} {{;}} AND {{/;}} {{/:filter}} {{/?filter}} {{?limit}}LIMIT {{:limit}}{{value}}{{;}},{{/;}}{{/:limit}}{{/?limit}}';
  75. return $sql;
  76. }
  77. public static function count(){
  78. $sql = 'SELECT COUNT({{selected}}) number FROM "{{table}}" {{?filter}}WHERE {{:filter}}"{{key}}"{{operator}}{{value}}{{postoperator}} {{;}} AND {{/;}} {{/:filter}} {{/?filter}}';
  79. return $sql;
  80. }
  81. public static function update(){
  82. $sql = 'UPDATE "{{table}}" SET {{?fields}} {{:fields}}"{{key}}"={{value}} {{;}} , {{/;}} {{/:fields}} {{/?fields}} {{?filters}}WHERE {{:filters}}"{{key}}"{{operator}} {{value}} {{postoperator}} {{;}} AND {{/;}} {{/:filters}} {{/?filters}}';
  83. return $sql;
  84. }
  85. public static function insert(){
  86. $sql = 'INSERT INTO "{{table}}" ({{?fields}} {{:fields}}"{{key}}" {{;}} , {{/;}} {{/:fields}} {{/?fields}})VALUES({{?fields}} {{:fields}}{{value}} {{;}} , {{/;}} {{/:fields}} {{/?fields}})';
  87. return $sql;
  88. }
  89. public static function create(){
  90. $sql = 'CREATE TABLE IF NOT EXISTS "{{table}}" ({{?fields}} {{:fields}}"{{key}}" {{value}}{{;}} , {{/;}} {{/:fields}} {{/?fields}}) DEFAULT CHARSET=utf8;';
  91. return $sql;
  92. }
  93. public static function drop(){
  94. $sql = 'DROP TABLE IF EXISTS "{{table}}";';
  95. return $sql;
  96. }
  97. public static function truncate(){
  98. $sql = 'TRUNCATE TABLE "{{table}}";';
  99. return $sql;
  100. }
  101. public static function create_index(){
  102. $sql = 'CREATE INDEX "{{index_name}}" ON "{{table}}" ({{column}})';
  103. return $sql;
  104. }
  105. public static function drop_index(){
  106. $sql = 'DROP INDEX "{{index_name}}" ON "{{table}}"';
  107. return $sql;
  108. }
  109. public static function count_index(){
  110. $sql = 'SELECT COUNT(1) "exists" FROM INFORMATION_SCHEMA.STATISTICS
  111. WHERE table_schema=DATABASE() AND table_name=\'{{table}}\' AND index_name=\'{{index_name}}\'';
  112. return $sql;
  113. }
  114. public static function show_tables(){
  115. $sql = 'SELECT table_name FROM user_tables ORDER BY table_name;';
  116. return $sql;
  117. }
  118. public static function show_columns(){
  119. $sql = "SELECT COLUMN_NAME \"column\",DATA_TYPE \"type\"
  120. FROM user_tab_cols
  121. WHERE table_name = '{{table}}' AND USER_GENERATED = 'YES'";
  122. return $sql;
  123. }
  124. }
  125. ?>