/** * @covers Cart\DBStorage::remove * @todo Implement testRemove(). */ public function testRemove() { /** Sproduct array * */ $data["SProducts_71_82"] = array('instance' => 'SProducts', 'id' => 82, 'quantity' => 5); /** ShopKit array * */ $data['ShopKit_16'] = array('instance' => 'ShopKit', 'id' => 16, 'quantity' => 5); /** Save to storage * */ $this->object->setData($data); $result = $this->object->remove('SProducts', 82); $this->assertTrue($result); $result = $this->object->remove(1); $this->assertFalse($result); $result = $this->object->remove('ShopKit', 16); $this->assertTrue($result); $result = $this->object->remove(2); $this->assertFalse($result); $result = $this->object->remove(); $this->assertFalse($result); }
function makeNewLine2($table, $A) { $fields = PMReflector::getAttributesArray($A); #if(PHYNX_MYSQL_STRICT) # $this->fixTypes($table, $A); $values = "NULL"; if (self::$useAsNextID != null) { $values = self::$useAsNextID; self::$useAsNextID = null; } $sets = "`" . $table . "ID`"; for ($i = 0; $i < count($fields); $i++) { if ($fields[$i] == $table . "ID") { continue; } #if(is_numeric($A->$fields[$i])) $values .= ", ".$A->$fields[$i]."\n"; #else $cf = $fields[$i]; $values .= ", '" . $this->cWrite->real_escape_string($A->{$cf}) . "'\n"; $sets .= ",\n`" . $cf . "`"; } $sql = "INSERT INTO\n {$table}\n ({$sets}) VALUES ({$values})"; $_SESSION["messages"]->addMessage("executing MySQL: {$sql}"); Timer::now("sql start", __FILE__, __LINE__); $this->cWrite->query($sql); Timer::now("sql end", __FILE__, __LINE__); DBStorage::$queryCounter++; if ($this->cWrite->error and $this->cWrite->errno == 1054) { preg_match("/[a-zA-Z0-9 ]*\\'([a-zA-Z0-9\\.]*)\\'[a-zA-Z ]*\\'([a-zA-Z ]*)\\'.*/", $this->cWrite->error, $regs); throw new FieldDoesNotExistException($regs[1], $regs[2]); } if ($this->cWrite->error and $this->cWrite->errno == 1062) { throw new DuplicateEntryException($this->cWrite->error); } if ($this->cWrite->error) { throw new StorageException($this->cWrite->error); } if ($this->cWrite->error and PHYNX_USE_SYSLOG) { syslog(LOG_ERR, "MySQL: " . $this->cWrite->error . "(" . $this->cWrite->errno . ") in {$sql}"); } return $this->cWrite->insert_id; }
if (isset($nextRequest[$B->getID()]) and $nextRequest[$B->getID()] > time()) { continue; } $Bricklet = new $Type($B->A("TinkerforgeBrickletUID"), $connection); $temp = floor($Bricklet->getObjectTemperature() / 10.0); callback($temp, array($B->A("TinkerforgeBrickletUID"), $B->A("TinkerforgeBrickletType"))); #echo date("H:i:s").": ".$temp."\n"; if ($temp < 35) { $counter[$B->getID()]++; } else { $counter[$B->getID()] = 0; } if ($counter[$B->getID()] >= 3) { $nextRequest[$B->getID()] = time() + 60 * 30; } else { $nextRequest[$B->getID()] = time() + 60; } break; } } catch (ClassNotFoundException $ex) { echo "Class not found: "; echo $ex->getClassName(); echo "\n"; } } $connection->disconnect(); } DBStorage::disconnect(); sleep(60); } $e->cleanUp();
/** * Converts given searchString to SQL statements. */ function parseSearchString() { if (count($this->selectStatement->searchString) == 0) { return; } $string = $this->selectStatement->searchString[0]; $fields = $this->selectStatement->searchFields; $s = explode(" UND ", $string); for ($i = 0; $i < count($s); $i++) { foreach ($fields as $j => $name) { #for($j = 0;$j<count($fields);$j++){ $this->addSelectStatement("whereFields", $fields[$j]); $this->addSelectStatement("whereOperators", "LIKE"); $this->addSelectStatement("whereValues", "%" . $s[$i] . "%"); $this->addSelectStatement("whereLogOp", $j == 0 ? "AND" : "OR"); $this->addSelectStatement("whereBracketGroup", "BG" . $i); //Fix by mysqli and utf8 broken umlauts $v = DBStorage::findNonUft8($s[$i]); if ($v != $s[$i]) { $this->addSelectStatement("whereFields", $fields[$j]); $this->addSelectStatement("whereOperators", "LIKE"); $this->addSelectStatement("whereValues", "%" . $v . "%"); $this->addSelectStatement("whereLogOp", "OR"); $this->addSelectStatement("whereBracketGroup", "BG" . $i); } } } if (!isset($this->selectStatement->searchCustom)) { return; } foreach ($this->selectStatement->searchCustom as $v) { $this->addSelectStatement("whereFields", $v[0]); $this->addSelectStatement("whereOperators", $v[1]); $this->addSelectStatement("whereValues", $v[2]); $this->addSelectStatement("whereLogOp", $v[3]); } }
public function restoreBackup($name) { if ($_SESSION["S"]->isUserAdmin() == "0") { throw new AccessDeniedException(); } require Util::getRootPath() . "libraries/PMBP.inc.php"; $DB = new DBStorage(); $con = $DB->getConnection(); if (strpos($name, "_utf8")) { mysqli_set_charset($con, "utf8"); } else { mysqli_set_charset($con, "latin1"); } $file = fopen(Util::getRootPath() . "system/Backup/{$name}", "r"); $return = PMBP_exec_sql($file, $con); $Tab = new HTMLTable(2); $Tab->setColWidth(1, "120px"); $Tab->addLV("Tabellen", $return["insertQueries"]); $Tab->addLV("Datensätze", $return["tableQueries"]); $Tab->addLV("Befehle gesamt", $return["totalqueries"]); $Tab->addLV("Zeilen", $return["linenumber"]); $Tab->addLV("Fehler", $return["error"]); echo $Tab; }