/** * @test */ public function itShouldIncreaseTheCounterByAnArbitraryInteger() { $gauge = new Counter($this->adapter, 'test', 'some_metric', 'this is for testing', array('foo', 'bar')); $gauge->inc(array('lalal', 'lululu')); $gauge->incBy(123, array('lalal', 'lululu')); $this->assertThat($this->adapter->collect(), $this->equalTo(array(new MetricFamilySamples(array('type' => Counter::TYPE, 'help' => 'this is for testing', 'name' => 'test_some_metric', 'labelNames' => array('foo', 'bar'), 'samples' => array(array('labelValues' => array('lalal', 'lululu'), 'value' => 124, 'name' => 'test_some_metric', 'labelNames' => array()))))))); }
function codopm_load() { $myadapter = codopm_get_adapter(); $adapter = new Adapter(); $user = $adapter->get_user(); $row_class = 'row'; codopm::$xhash = md5($user->id . codopm::$secret); if ($user->id == 0) { if ($myadapter != 'Codoforum') { require "error.php"; } } else { if (isset($_GET['to'])) { $to = $_GET['to']; } else { $to = ''; } echo ' <script> var codopm={}; codopm.path="' . codopm::$path . '"; codopm.req_path="' . codopm::$req_path . '"; codopm.from="' . $user->id . '"; codopm.xhash="' . codopm::$xhash . '"; codopm.profile_id="' . codopm::$profile_id . '"; codopm.profile_name="' . codopm::$profile_name . '"; </script>'; require "start.php"; } }
public function run() { $adapter = new Adapter(); $adapter->test(); echo "\r\n"; $adapter->doSomeThing('一句话'); echo "\r\n"; }
public static function main() { $adaptee = new Adaptee(); $adapter = new Adapter($adaptee); $adapter->request(); $adaptee = null; $adapter = null; }
public function registerAdapter($name, Adapter $adapter) { if (isset($this->adapters[$name])) { throw new Exception\InvalidArgumentException("Adapter with name " . $name . " already registered!"); } $this->adapters[$name] = $adapter; if ($adapter->getMapping()) { $this->mapper->registerAdapterMapping($name, $adapter->getMapping()); } }
/** * Authenticates against the supplied adapter * * @param Zend\Authentication\Adapter $adapter * @return Zend\Authentication\Result */ public function authenticate(Adapter $adapter) { $result = $adapter->authenticate(); /** * ZF-7546 - prevent multiple succesive calls from storing inconsistent results * Ensure storage has clean state */ if ($this->hasIdentity()) { $this->clearIdentity(); } if ($result->isValid()) { $this->getStorage()->write($result->getIdentity()); } return $result; }
public function test_getWhereFromApiCriteria() { /** === Test Data === */ $crit = $this->_mock(\Magento\Framework\Api\Search\SearchCriteriaInterface::class); $mapper = $this->_mock(\Praxigento\Core\Repo\Query\Criteria\IMapper::class); $field = 'field'; $cond = 'cond type'; $value = 'value'; $where = 'where'; /** === Setup Mocks === */ // $filterGroups = $criteria->getFilterGroups(); $mFilterGroup = $this->_mock(\Magento\Framework\Api\Search\FilterGroup::class); $crit->shouldReceive('getFilterGroups')->once()->andReturn([$mFilterGroup]); // foreach ($filterGroup->getFilters() as $item) {} $mFilter = $this->_mock(\Magento\Framework\Api\Filter::class); $mFilterGroup->shouldReceive('getFilters')->once()->andReturn([$mFilter]); // $field = $item->getField(); $mFilter->shouldReceive('getField')->once()->andReturn($field); // $field = $mapper->get($field); $mapper->shouldReceive('get')->once()->with($field)->andReturn($field); // $cond = $item->getConditionType(); $mFilter->shouldReceive('getConditionType')->once()->andReturn($cond); // $value = $item->getValue(); $mFilter->shouldReceive('getValue')->once()->andReturn($value); // $where = $this->_conn->prepareSqlCondition($field, [$cond => $value]); $this->mConn->shouldReceive('prepareSqlCondition')->once()->andReturn($where); /** === Call and asserts === */ $res = $this->obj->getWhereFromApiCriteria($crit, $mapper); $this->assertEquals("({$where}) AND 1", $res); }
/** * * @return \SplFixedArray */ public function fetchAllByPrimary($keys) { if (empty($keys)) { return new \SplFixedArray(0); } return $this->select()->where($this->_db->quoteIdentifier($this->_primary[0], true) . ' in (' . $this->_db->quoteArray($keys) . ')')->fetchAll(); }
/** * Overload the save method in the db so that we can run validation * * @todo add error messages to some where. * @return boolean * @author Justin Palmer **/ public function save() { self::$db->model = $this; $boolean = $this->validate(); if ($boolean) { return self::$db->saveNow(); } }
/** * Execute a query on the database and logs it * * @throws Exception * * @param string $key * name of the query * @param string $query * @param boolean $disable_foreign_key_checks * @param string $entity * @return void */ public function executeSQL($key, $query, $disable_foreign_key_checks = true, $entity = null) { if ($entity !== null && $entity != $this->last_entity) { $this->log("------------------------------------------------------"); $this->log("Entity: '{$entity}'"); $this->log("------------------------------------------------------"); $this->last_entity = $entity; } $this->log(" * Sync::executeSQL '{$key}'..."); $total_time_start = microtime(true); if ($disable_foreign_key_checks) { $this->adapter->query('set foreign_key_checks=0'); $this->log(" * FK : Foreign key check disabled"); } try { $time_start = microtime(true); $result = $this->adapter->query($query, ZendDb::QUERY_MODE_EXECUTE); $affected_rows = $result->getAffectedRows(); // Log stuffs $time_stop = microtime(true); $time = number_format($time_stop - $time_start, 2); $formatted_query = preg_replace('/(\\n)|(\\r)|(\\t)/', ' ', $query); $formatted_query = preg_replace('/(\\ )+/', ' ', $formatted_query); $this->log(" * SQL: " . substr(trim($formatted_query), 0, 70) . '...'); $this->log(" * SQL: Query time {$time} sec(s))"); } catch (\Exception $e) { $err = $e->getMessage(); $msg = "Error running query ({$err}) : \n--------------------\n{$query}\n------------------\n"; $this->log("[+] {$msg}\n"); if ($disable_foreign_key_checks) { $this->log("[Error] Error restoring foreign key checks"); $this->adapter->query('set foreign_key_checks=1'); } throw new \Exception($msg); } if ($disable_foreign_key_checks) { $time_start = microtime(true); $this->adapter->query('set foreign_key_checks=1'); $time_stop = microtime(true); $time = number_format($time_stop - $time_start, 2); $this->log(" * FK : Foreign keys restored"); } $time_stop = microtime(true); $time = number_format($time_stop - $total_time_start, 2); $this->log(" * Time: {$time} secs, affected rows {$affected_rows}."); }
public function getUserComments($parameters = array()) { $userId = Adapter::getParameter('userId', $parameters); $commentId = Adapter::getParameter('commentId', $parameters); $result = $this->getUserCommentsAction($userId, (int) $commentId); return json_encode(array('result' => $result, 'status' => !empty($result) ? 200 : 204)); exit; }
public function __construct($db = null) { parent::__construct($db); $this->_currentPage = 1; $this->_itemsByPage = 30; $this->_totalItems = 0; $this->_totalPages = 0; $this->_query = ''; $this->_queryCount = ''; }
public function __construct($table = NULL, $params = NULL) { $this->adapter = Adapter::getInstance($params); $this->params = $params; if (is_string($table)) { return $this->setTable(new Table($table)); } elseif (!is_null($table)) { $this->setTable($table); } }
/** * * @throws \mysqli_sql_exception */ public function _query() { $this->_connection->ensureConnected(); //如果已经在结果缓存中,则搜寻结果集 $this->_connection->flushQueue($this); if (isset($this->_result)) { return; } $this->_connection->queryStatement($this); }
public function deleteNews($parameters = array()) { $id = Adapter::getParameter('id', $parameters); if ($this->deleteNewsAction((int) $id)) { return json_encode(array('result' => array('id' => $id), 'status' => 200)); } else { return json_encode(array('result' => array('id' => $id, 'error' => 'wrong ID'), 'status' => 400)); } exit; }
function saveSingle2($forWhat, $A) { parent::saveSingle2($forWhat, $A); if ($A->AuftragID != -1 and $A->type == "lieferAdresse") { $_SESSION["messages"]->addMessage("Updating GRLBM {$A->AuftragID} to use AdresseID {$this->ID}..."); $GRLBM = new GRLBM($A->AuftragID); $GRLBM->changeA("lieferAdresseID", $this->ID); $GRLBM->saveMe(); } }
/** * This method init $this->object */ protected function _prepareTable($data) { $quoteTableName = $this->adapter->platform->quoteIdentifier($this->dbTableName); $deleteStatementStr = "DROP TABLE IF EXISTS " . $quoteTableName; $deleteStatement = $this->adapter->query($deleteStatementStr); $deleteStatement->execute(); $createStr = "CREATE TABLE IF NOT EXISTS " . $quoteTableName; $fields = $this->_getDbTableFields($data); $createStatementStr = $createStr . '(' . $fields . ') ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;'; $createStatement = $this->adapter->query($createStatementStr); $createStatement->execute(); }
/** * Constructs where statement for retrieving row(s). * * @param bool $useDirty * @return array */ protected function _getWhereQuery($useDirty = true) { $where = array(); $primaryKey = $this->_getPrimaryKey($useDirty); //$info = static::info(); //$metadata = $info[self::METADATA]; FIXME 这个暂时无解 // retrieve recently updated row using primary keys $where = array(); foreach ($primaryKey as $column => $value) { $tableName = static::$_db->quoteIdentifier(static::$_name, true); //$type = $metadata[$column]['DATA_TYPE']; $columnName = static::$_db->quoteIdentifier($column, true); $where[] = static::$_db->quoteInto("{$tableName}.{$columnName} = ?", $value); //, $type FIXME 这个暂时无解 } return $where; }
/** * Internal function for creating the where clause * * @param string $condition * @param mixed $value optional * @param string $type optional * @param boolean $bool true = AND, false = OR * @return string clause */ protected function _where($condition, $value = null, $bool = true) { if (count($this->_parts[self::UNION])) { throw new SelectException("Invalid use of where clause with " . self::SQL_UNION); } if ($value !== null) { $condition = $this->_adapter->quoteInto($condition, $value); } $cond = ""; if ($this->_parts[self::WHERE]) { if ($bool === true) { $cond = self::SQL_AND . ' '; } else { $cond = self::SQL_OR . ' '; } } return $cond . "({$condition})"; }
/** * 构造最终查询语句 * * @return string */ public function __toString() { switch ($this->_sqlPreBuild['action']) { case Db::SELECT: return $this->_adapter->parseSelect($this->_sqlPreBuild); case Db::INSERT: return 'INSERT INTO ' . $this->_sqlPreBuild['table'] . '(' . implode(' , ', array_keys($this->_sqlPreBuild['rows'])) . ')' . ' VALUES ' . '(' . implode(' , ', array_values($this->_sqlPreBuild['rows'])) . ')' . $this->_sqlPreBuild['limit']; case Db::DELETE: return 'DELETE FROM ' . $this->_sqlPreBuild['table'] . $this->_sqlPreBuild['where']; case Db::UPDATE: $columns = array(); if (isset($this->_sqlPreBuild['rows'])) { foreach ($this->_sqlPreBuild['rows'] as $key => $val) { $columns[] = "{$key} = {$val}"; } } return 'UPDATE ' . $this->_sqlPreBuild['table'] . ' SET ' . implode(' , ', $columns) . $this->_sqlPreBuild['where']; default: return NULL; } }
/** * Store feeds into the Contacts * @param array $feed */ public static function parseFeed($feed) { $userid = \OCP\User::getUser(); foreach ($feed as $source) { $entry = Adapter::translateContact($source); if (isset($entry[self::CONTACT_GID]) && !empty($entry[self::CONTACT_GID])) { $oldContactId = self::findByGid($userid, $entry[self::CONTACT_GID]); if ($oldContactId) { //If exists and should not be updated - skip if (self::needUpdate($oldContactId)) { $vcard = self::toVcard($entry); \OCA\Contacts\VCard::edit($oldContactId, $vcard); } continue; } } $vcard = self::toVcard($entry); $bookid = self::getBookId($userid); \OCA\Contacts\VCard::add($bookid, $vcard); } \OCA\Contacts\App::getCategories(); }
public static function preparePreregistrationReqData($arOrder, $profileId, $arConfig) { $result = array(); $result["sender"] = array("inn" => $arConfig["INN"]["VALUE"], "city" => static::getFilialAndCity($arConfig["CITY_DELIVERY"]["VALUE"]), "title" => $arConfig["NAME"]["VALUE"], "phone" => $arConfig["PHONE"]["VALUE"]); $inn = ""; $city = ""; $title = ""; $phone = ""; $address = ""; if (isset($extraParams["location"])) { $city = $extraParams["location"]; } $dbOrderProps = \CSaleOrderPropsValue::GetOrderProps($arOrder["ID"]); while ($arOrderProps = $dbOrderProps->Fetch()) { if ($arOrderProps["CODE"] == "COMPANY" || $arOrderProps["CODE"] == "FIO") { $title = $arOrderProps["VALUE"]; } if ($arOrderProps["CODE"] == "INN") { $inn = $arOrderProps["VALUE"]; } if ($arOrderProps["CODE"] == "PHONE") { $phone = $arOrderProps["VALUE"]; } if ($arOrderProps["CODE"] == "LOCATION") { $location = $arOrderProps["VALUE"]; $locDelivery = Adapter::mapLocation($location); // todo: if more than one $city = static::getFilialAndCity(key($locDelivery)); } if ($arOrderProps["CODE"] == "ADDRESS") { $address = $arOrderProps["VALUE"]; } } $arPacks = \CSaleDeliveryHelper::getBoxesFromConfig($profileId, $arConfig); $arPackagesParams = \CSaleDeliveryHelper::getRequiredPacks($arOrder["ITEMS"], $arPacks, 0); $result["cargos"] = array(array("common" => array("positionsCount" => count($arPackagesParams), "decription" => GetMessage("SALE_DH_PECOM_DESCRIPTION_GOODS"), "orderNumber" => $arOrder["ACCOUNT_NUMBER"], "paymentForm" => $arConfig["PAYMENT_FORM"]["VALUE"], "accompanyingDocuments" => false), "receiver" => array("inn" => $inn, "city" => $city, "title" => $title, "phone" => $phone, "addressStock" => $address), "services" => array("transporting" => array("payer" => array("type" => 1)), "hardPacking" => array("enabled" => \CDeliveryPecom::isConfCheckedVal($arConfig, 'SERVICE_OTHER_RIGID_PACKING'), "payer" => array("type" => \CDeliveryPecom::getConfValue($arConfig, 'SERVICE_OTHER_RIGID_PAYER'))), "palletTransporting" => array("enabled" => !\CDeliveryPecom::isConfCheckedVal($arConfig, 'SERVICE_OTHER_RIGID_PACKING') && \CDeliveryPecom::isConfCheckedVal($arConfig, 'SERVICE_OTHER_PALLETE'), "payer" => array("type" => \CDeliveryPecom::getConfValue($arConfig, 'SERVICE_OTHER_PALLETE_PAYER'))), "insurance" => array("enabled" => \CDeliveryPecom::isConfCheckedVal($arConfig, 'SERVICE_OTHER_INSURANCE'), "payer" => array("type" => \CDeliveryPecom::getConfValue($arConfig, 'SERVICE_OTHER_INSURANCE_PAYER')), "cost" => intval($arOrder["PRICE"])), "sealing" => array("enabled" => \CDeliveryPecom::isConfCheckedVal($arConfig, 'SERVICE_OTHER_PLOMBIR_ENABLE'), "payer" => array("type" => \CDeliveryPecom::getConfValue($arConfig, 'SERVICE_OTHER_PLOMBIR_PAYER'))), "strapping" => array("enabled" => false), "documentsReturning" => array("enabled" => false), "delivery" => array("enabled" => \CDeliveryPecom::isConfCheckedVal($arConfig, 'SERVICE_DELIVERY_ENABLED'), "payer" => array("type" => \CDeliveryPecom::getConfValue($arConfig, 'SERVICE_OTHER_DELIVERY_PAYER')))))); return $result; }
/** * Show columns * * @return void * @author Justin Palmer **/ public function showColumns() { $table_name = $this->model->table_name(); return parent::showColumns("SHOW COLUMNS FROM `{$table_name}`"); }
function checkMyTable($CIA) { $Ad = new Adapter(-1, PHYNX_MAIN_STORAGE); $DB = $Ad->getConnection(); return $DB->checkMyTable($CIA); }
/** * Show columns * * @return void * @author Justin Palmer **/ public function showColumns() { $table_name = $this->model->table_name(); return parent::showColumns("PRAGMA table_info(`{$table_name}`)"); }
/** * Método para executar uma query no banco de dados * @param String $sql * @return Result * @throws SQLCommandException */ public static function query($sql) { $query = mysqli_query(Adapter::conectar(), $sql) or die("Não foi possível executar um comando ao banco de dados." . mysqli_error(Adapter::$conexao)); return $query; }
/** * Get the config for the db. * * @return stdClass * @author Justin Palmer **/ public static function getConfig() { $Config = self::$Config; if (self::$Config === null) { self::$Config = $Config = Registry::get('pr-db-config'); } return $Config; }
public function dump() { $adapter = Adapter::getInstance($this->params); return $adapter->directQuery("SHOW CREATE TABLE {$this}"); }
protected function createCalcParams() { if (!isset($this->arOrder["WEIGHT"])) { throw new \Exception(GetMessage("SALE_DH_PECOM_EXCPT_WEIGHT")); } $locationTo = ""; $arLocation = Adapter::mapLocation($this->arOrder["LOCATION_TO"]); if (empty($arLocation)) { throw new \Exception(GetMessage("SALE_DH_PECOM_EXCPT_EMPTY_LOCATION")); } if (count($arLocation) > 1 && isset($this->arOrder["EXTRA_PARAMS"]["location"])) { $locationTo = $this->arOrder["EXTRA_PARAMS"]["location"]; } elseif (count($arLocation) > 1 && !isset($this->arOrder["EXTRA_PARAMS"]["location"])) { throw new \Exception(GetMessage("SALE_DH_PECOM_EXCPT_MANY_LOCATIONS")); } if (count($arLocation) == 1) { $locationTo = key($arLocation); } if (!isset($this->arOrder["ITEMS"]) || !is_array($this->arOrder["ITEMS"]) || empty($this->arOrder["ITEMS"])) { throw new \Exception(GetMessage("SALE_DH_PECOM_EXCPT_EMPTY_ITEMS")); } $measureCoeff = 1000; $itemsStr = ""; $loadingRange = true; $rigidPacking = \CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_OTHER_RIGID_PACKING'); $arPacks = \CSaleDeliveryHelper::getBoxesFromConfig($this->profileId, $this->arConfig); $arPackagesParams = \CSaleDeliveryHelper::getRequiredPacks($this->arOrder["ITEMS"], $arPacks, 0); $this->packsCount = count($arPackagesParams); for ($i = $this->packsCount - 1; $i >= 0; $i--) { $item = $arPackagesParams[$i]; $width = round(floatval($item["DIMENSIONS"]["WIDTH"]) / $measureCoeff, 2); $lenght = round(floatval($item["DIMENSIONS"]["LENGTH"]) / $measureCoeff, 2); $height = round(floatval($item["DIMENSIONS"]["HEIGHT"]) / $measureCoeff, 2); $volume = floatval($item["VOLUME"] / pow($measureCoeff, 3)); if ($width > \CDeliveryPecom::$EXTRA_DIMENSIONS_SIZE || $lenght > \CDeliveryPecom::$EXTRA_DIMENSIONS_SIZE || $height > \CDeliveryPecom::$EXTRA_DIMENSIONS_SIZE || $item["WEIGHT"] > \CDeliveryPecom::$EXTRA_DEMENSIONS_WEIGHT) { $loadingRange = false; } $itemsStr .= 'places[' . $i . '][]=' . strval($width) . '&places[' . $i . '][]=' . strval($lenght) . '&places[' . $i . '][]=' . strval($height) . '&places[' . $i . '][]=' . strval($volume) . '&places[' . $i . '][]=' . strval($item["WEIGHT"] / 1000) . '&places[' . $i . '][]=' . ($loadingRange ? '1' : '0') . '&places[' . $i . '][]=' . ($rigidPacking && \CDeliveryPecom::getConfValue($this->arConfig, 'SERVICE_OTHER_RIGID_PAYER') == \CDeliveryPecom::$PAYER_BUYER ? '1' : '0'); } if (\CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_OTHER_PLOMBIR_ENABLE') && \CDeliveryPecom::getConfValue($this->arConfig, 'SERVICE_OTHER_PLOMBIR_PAYER') == \CDeliveryPecom::$PAYER_BUYER) { $plombir = strval(intval(\CDeliveryPecom::getConfValue($this->arConfig, 'SERVICE_OTHER_PLOMBIR_COUNT'))); } else { $plombir = "0"; } if (\CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_OTHER_INSURANCE') && \CDeliveryPecom::getConfValue($this->arConfig, 'SERVICE_OTHER_INSURANCE_PAYER') == \CDeliveryPecom::$PAYER_BUYER) { $insurance = strval($this->arOrder["PRICE"]); } else { $insurance = "0"; } $result = $itemsStr . '&take[town]=' . $this->arConfig["CITY_DELIVERY"]["VALUE"] . '&take[tent]=' . (\CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_TAKE_ENABLED') && \CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_TAKE_TENT_ENABLED') ? '1' : '0') . '&take[gidro]=' . (\CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_TAKE_ENABLED') && \CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_TAKE_HYDRO_ENABLED') ? '1' : '0') . '&take[speed]=0' . '&take[moscow]=0' . '&deliver[town]=' . $locationTo . '&deliver[tent]=' . (\CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_DELIVERY_ENABLED') && \CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_DELIVERY_TENT_ENABLED') ? '1' : '0') . '&delideliver[gidro]=' . (\CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_DELIVERY_ENABLED') && \CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_DELIVERY_HYDRO_ENABLED') ? '1' : '0') . '&deliver[speed]=0' . '&deliver[moscow]=0' . '&plombir=' . $plombir . '&strah=' . $insurance . '&ashan=0'; return $result; }
public function __construct() { //parent::__construct($this); parent::__construct($this); }