/** * Looks if the specified table exists and if not create it with the key- * field (uid). Then it syncs the DB-fields with the fields found in the form * with help of template parser */ protected function createTable() { $fields = $this->getFormFields(); if ($this->settings['excludeFields']) { $excludes = t3lib_div::trimExplode(',', $this->settings['excludeFields']); foreach ($excludes as $exclude) { unset($fields[$exclude]); } } if (Tx_Formhandler_Globals::$settings['debug']) { $this->db->debugOutput = 1; } $res = $this->db->sql_query("SHOW TABLES LIKE '" . $this->table . "'"); if (!$this->db->sql_num_rows($res)) { $query = "CREATE TABLE `" . $this->table . "` (\n\t\t\t\t`" . $this->key . "` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY\n\t\t\t)"; $this->db->sql_query($query); Tx_Formhandler_StaticFuncs::debugMessage('sql_request', array($query)); $dbFields = array($this->key); } else { $dbFields = array_keys($this->db->admin_get_fields($this->table)); } $createFields = array_diff($fields, $dbFields); if (count($createFields)) { $sql = 'ALTER TABLE ' . $this->table . ' ADD `'; $sql .= implode('` ' . $this->newFieldsSqlAttribs . ', ADD `', $createFields); $sql .= '` ' . $this->newFieldsSqlAttribs . ''; $this->db->sql_query($sql); Tx_Formhandler_StaticFuncs::debugMessage('sql_request', array($sql)); if ($this->db->sql_error()) { Tx_Formhandler_StaticFuncs::debugMessage('error', array($this->db->sql_error()), 3); } } }
/** * Check if there are still resources left for the process with the given id * Used to determine timeouts and to ensure a proper cleanup if there's a timeout * * @param string identification string for the process * @return boolean determines if the process is still active / has resources */ function CLI_checkIfProcessIsActive($pid) { $ret = false; $this->db->sql_query('BEGIN'); $res = $this->db->exec_SELECTquery('process_id,active,ttl', 'tx_crawler_process', 'process_id = \'' . $pid . '\' AND deleted=0', '', 'ttl', '0,1'); if ($row = $this->db->sql_fetch_assoc($res)) { $ret = intVal($row['active']) == 1; } $this->db->sql_query('COMMIT'); return $ret; }
/** * Checks if a Value Object equal to the given Object exists in the data base * * @param Tx_Extbase_DomainObject_AbstractValueObject $object The Value Object * @return array The matching uid */ public function getUidOfAlreadyPersistedValueObject(Tx_Extbase_DomainObject_AbstractValueObject $object) { $fields = array(); $parameters = array(); $dataMap = $this->dataMapper->getDataMap(get_class($object)); $properties = $object->_getProperties(); foreach ($properties as $propertyName => $propertyValue) { // FIXME We couple the Backend to the Entity implementation (uid, isClone); changes there breaks this method if ($dataMap->isPersistableProperty($propertyName) && $propertyName !== 'uid' && $propertyName !== 'pid' && $propertyName !== 'isClone') { if ($propertyValue === NULL) { $fields[] = $dataMap->getColumnMap($propertyName)->getColumnName() . ' IS NULL'; } else { $fields[] = $dataMap->getColumnMap($propertyName)->getColumnName() . '=?'; $parameters[] = $this->getPlainValue($propertyValue); } } } $sql = array(); $sql['additionalWhereClause'] = array(); $tableName = $dataMap->getTableName(); $this->addEnableFieldsStatement($tableName, $sql); $statement = 'SELECT * FROM ' . $tableName; $statement .= ' WHERE ' . implode(' AND ', $fields); if (!empty($sql['additionalWhereClause'])) { $statement .= ' AND ' . implode(' AND ', $sql['additionalWhereClause']); } $this->replacePlaceholders($statement, $parameters); // debug($statement,-2); $res = $this->databaseHandle->sql_query($statement); $this->checkSqlErrors($statement); $row = $this->databaseHandle->sql_fetch_assoc($res); if ($row !== FALSE) { return (int) $row['uid']; } else { return FALSE; } }
/** * Directly execute a query on the db and return the result. * * @param string $query The query. * @param mixed $result If set to false, no result is returned. If set to true, an array with the rows is returned. If set to a string, an associated array is returned, where the $row[$result] is used as the key. * @return array The assoc return array. * @internal */ public function _sql($query, $result = true) { $resource = $this->db->sql_query($query); if ($resource === null) { // mysqli 6.2 return; } if ($result === false) { if ($resource !== null) { $this->db->sql_free_result($resource); } return; } if ($resource === null) { return array(); } $output = array(); if ($result === true) { while (($row = $this->db->sql_fetch_assoc($resource)) !== false) { $output[] = $row; } } else { $result = (string) $result; while (($row = $this->db->sql_fetch_assoc($resource)) !== false) { $output[$row[$result]] = $row; } } $this->db->sql_free_result($resource); return $output; }