api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

SqliteTest.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace Mevdschee\PhpCrudApi\Tests;
  3. class SqliteTest extends Tests
  4. {
  5. /**
  6. * Gets the name of the database engine
  7. *
  8. * @return string Name of the database engine
  9. */
  10. public function getEngineName()
  11. {
  12. return 'SQLite';
  13. }
  14. /**
  15. * Connects to the Database
  16. *
  17. * @return object Database connection
  18. */
  19. public function connect($config)
  20. {
  21. $db = new \SQLite3($config['database']);
  22. if (!$db) {
  23. die("Could not open '$database' SQLite database: ".\SQLite3::lastErrorMsg().' ('.\SQLite3::lastErrorCode().")\n");
  24. }
  25. return $db;
  26. }
  27. /**
  28. * Disconnects from the Database
  29. *
  30. * @return boolean Success
  31. */
  32. public function disconnect($db)
  33. {
  34. return $db->close();
  35. }
  36. /**
  37. * Checks the version of the Database
  38. *
  39. * @return void
  40. */
  41. public function checkVersion($db)
  42. {
  43. $major = 3;
  44. $minor = 0;
  45. $version = \SQLite3::version();
  46. $v = explode('.', $version['versionString']);
  47. if ($v[0]<$major || ($v[0]==$major && $v[1]<$minor)) {
  48. die("Detected SQLite $v[0].$v[1], but only $major.$minor and up are supported\n");
  49. }
  50. }
  51. /**
  52. * Gets the capabilities of the Database
  53. *
  54. * @return int Capabilites
  55. */
  56. public function getCapabilities($db)
  57. {
  58. $capabilities = 0;
  59. return $capabilities;
  60. }
  61. /**
  62. * Seeds the database for this connection
  63. *
  64. * @return void
  65. */
  66. public function seedDatabase($db, $capabilities)
  67. {
  68. $fixture = __DIR__.'/data/blog_sqlite.sql';
  69. $contents = file_get_contents($fixture);
  70. if (!($capabilities & self::GIS)) {
  71. $contents = preg_replace('/GEOMETRY NOT NULL/i', 'text NOT NULL', $contents);
  72. }
  73. if (!($capabilities & self::JSON)) {
  74. $contents = preg_replace('/JSON NOT NULL/i', 'text NOT NULL', $contents);
  75. }
  76. $queries = preg_split('/;\s*\n/', $contents);
  77. array_pop($queries);
  78. foreach ($queries as $i=>$query) {
  79. if (!$db->query($query.';')) {
  80. $i++;
  81. die("Loading '$fixture' failed on statemement #$i with error:\n".$db->lastErrorCode().': '.$db->lastErrorMsg()."\n");
  82. }
  83. }
  84. }
  85. }