Sqlite.class.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Define SQL for Mysql database system
  4. * @author valentin carruesco
  5. * @category Core
  6. * @license copyright
  7. */
  8. class Sqlite
  9. {
  10. const label = 'SQLite3';
  11. const connection = 'sqlite:{{ROOT}}db/{{BASE_NAME}}.db';
  12. const description = 'Base légere monofichier sans authentification, simple d\'utilisation/installation mais limitée en performances';
  13. public static function fields(){
  14. return array(
  15. array('id'=>'name','label'=>'Nom de la base','default'=>'.database','comment'=>'')
  16. );
  17. }
  18. public static function types(){
  19. $types = array();
  20. $types['string'] = $types['timestamp'] = $types['datetime'] = $types['date'] = 'VARCHAR(255)';
  21. $types['longstring'] = 'TEXT';
  22. $types['key'] = 'INTEGER NOT NULL PRIMARY KEY';
  23. $types['object'] = $types['integer'] = 'bigint(20)';
  24. $types['int'] = 'INTEGER';
  25. $types['boolean'] = 'INTEGER(1)';
  26. $types['blob'] = ' BLOB';
  27. $types['float'] = 'REAL';
  28. $types['decimal'] = 'DECIMAL(20,2)';
  29. $types['default'] = 'TEXT';
  30. return $types;
  31. }
  32. public static function select(){
  33. $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}}LIMIT {{:limit}}{{value}}{{;}},{{/;}}{{/:limit}}{{/?limit}}';
  34. return $sql;
  35. }
  36. public static function delete(){
  37. $sql = 'DELETE FROM {{table}} {{?filter}}WHERE {{:filter}}"{{key}}"{{operator}}{{value}} {{;}} AND {{/;}} {{/:filter}} {{/?filter}} {{?limit}}LIMIT {{:limit}}{{value}}{{;}},{{/;}}{{/:limit}}{{/?limit}}';
  38. return $sql;
  39. }
  40. public static function count(){
  41. $sql = 'SELECT COUNT({{selected}}) number FROM {{table}} {{?filter}}WHERE {{:filter}}"{{key}}"{{operator}}{{value}}{{postoperator}} {{;}} AND {{/;}} {{/:filter}} {{/?filter}}';
  42. return $sql;
  43. }
  44. public static function update(){
  45. $sql = 'UPDATE {{table}} SET {{?fields}} {{:fields}}"{{key}}"={{value}} {{;}}, {{/;}}{{/:fields}} {{/?fields}} {{?filters}}WHERE {{:filters}}{{key}}{{operator}}{{value}} {{;}} AND {{/;}} {{/:filters}} {{/?filters}}';
  46. return $sql;
  47. }
  48. public static function insert(){
  49. $sql = 'INSERT INTO {{table}} ({{?fields}} {{:fields}}"{{key}}" {{;}} , {{/;}} {{/:fields}} {{/?fields}})VALUES({{?fields}} {{:fields}}{{value}} {{;}} , {{/;}} {{/:fields}} {{/?fields}})';
  50. return $sql;
  51. }
  52. public static function create(){
  53. $sql = 'CREATE TABLE IF NOT EXISTS "{{table}}" ({{?fields}} {{:fields}}"{{key}}" {{value}}{{;}} , {{/;}} {{/:fields}} {{/?fields}})';
  54. return $sql;
  55. }
  56. public static function drop(){
  57. $sql = 'DROP TABLE IF EXISTS "{{table}}";';
  58. return $sql;
  59. }
  60. public static function truncate(){
  61. $sql = 'TRUNCATE TABLE "{{table}}";';
  62. return $sql;
  63. }
  64. public static function create_index(){
  65. $sql = 'CREATE INDEX `{{index_name}}` ON `{{table}}` ({{column}})';
  66. return $sql;
  67. }
  68. public static function drop_index(){
  69. $sql = 'DROP INDEX `{{index_name}}` ON `{{table}}`';
  70. return $sql;
  71. }
  72. public static function count_index(){
  73. //On desactive le check sur sqlite, la notion IF NOT EXISTS existant dans ce sgbd
  74. $sql = "SELECT 0 `exists`";
  75. return $sql;
  76. }
  77. }
  78. ?>