BxDevDb.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <? defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Developer Developer
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolTextDb');
  12. class BxDevDb extends BxDolModuleDb {
  13. function BxDevDb(&$oConfig) {
  14. parent::__construct($oConfig);
  15. }
  16. function getQueryInsert($sTable, $aItems, $mixedComment = false, $aExclude = array('id')) {
  17. $bFirst = true;
  18. $sContent = $sComment = "";
  19. foreach($aItems as $aItem) {
  20. foreach($aExclude as $sKey)
  21. if(isset($aItem[$sKey]))
  22. unset($aItem[$sKey]);
  23. $aKeys = array_keys($aItem);
  24. $aValues = array_values($aItem);
  25. $iValues = count($aValues);
  26. if($bFirst) {
  27. $sContent .= "INSERT INTO `" . $sTable . "`(`" . implode("`, `", $aKeys) . "`) VALUES \n";
  28. $bFirst = false;
  29. }
  30. $sSql = "(" . implode(", ", array_fill(0, $iValues, "?")) . "),\n";
  31. $sContent .= call_user_func_array(array($this, 'prepare'), array_merge(array($sSql), $aValues));
  32. }
  33. $sContent = substr($sContent, 0, -2) . ";\n\n";
  34. if($mixedComment === true || (is_string($mixedComment) && $mixedComment != ''))
  35. $sComment = "--\n-- " . ($mixedComment === true ? "Dumping data for table `" . $sTable . "`" : $mixedComment) . "\n--\n";
  36. return $sComment . $sContent;
  37. }
  38. function getQueryDelete($sTable, $sKey, $aItems, $mixedComment = false) {
  39. $sContent = $sComment = "";
  40. foreach($aItems as $aItem)
  41. if(isset($aItem[$sKey])) {
  42. $sSql = "DELETE FROM `" . $sTable . "` WHERE `" . $sKey . "`=?;\n";
  43. $sContent .= call_user_func_array(array($this, 'prepare'), array($sSql, $aItem[$sKey]));
  44. }
  45. $sContent .= "\n";
  46. if($mixedComment === true || (is_string($mixedComment) && $mixedComment != ''))
  47. $sComment = "--\n-- " . ($mixedComment === true ? "Delete data from table `" . $sTable . "`" : $mixedComment) . "\n--\n";
  48. return $sComment . $sContent;
  49. }
  50. }
  51. /** @} */