protected function mysqlQueryInner($tableName, $inverted = FALSE) { if (!$this->hasColumn("array", $this->path)) { return "1 /* " . JsonStoreSearch::$INCOMPLETE_TAG . ": can't check array items at {$this->path} */"; } $columnName = "array" . $this->path; $parentConfig = $this->config; $limitParams = (object) $this->values; $arrayConfig = $parentConfig['columns'][$columnName]; $subSearch = new JsonStoreSearch($arrayConfig, new JsonSchema(), ""); $subTable = new JsonStoreQueryConstructor($arrayConfig['table'], $tableName . "_itemlimits"); $joinOn = $subSearch->tableColumn($subTable, "group") . " = " . $this->tableColumn($tableName, $arrayConfig['parentColumn']); $subQuery = "(\n\tSELECT COUNT(*) AS `row_count`\n\t\tFROM " . str_replace("\n", "\n\t", $subTable->selectFrom()) . "\n\tWHERE {$joinOn}\n)"; $condition = NULL; if (!$inverted) { if (isset($limitParams->minItems)) { if (isset($limitParams->maxItems)) { $condition = "BETWEEN " . JsonStore::mysqlQuote($limitParams->minItems) . " AND " . JsonStore::mysqlQuote($limitParams->maxItems); } else { $condition = ">= " . JsonStore::mysqlQuote($limitParams->minItems); } } else { $condition = "<= " . JsonStore::mysqlQuote($limitParams->maxItems); } } else { if (isset($limitParams->minItems)) { if (isset($limitParams->maxItems)) { $condition = "NOT BETWEEN " . JsonStore::mysqlQuote($limitParams->minItems) . " AND " . JsonStore::mysqlQuote($limitParams->maxItems); } else { $condition = "< " . JsonStore::mysqlQuote($limitParams->minItems); } } else { $condition = "> " . JsonStore::mysqlQuote($limitParams->maxItems); } } return "{$subQuery} {$condition}"; }
public static function queryFromSchema($className, $schema, $orderBy = NULL) { $config = self::$mysqlConfigs[$className]; $search = new JsonStoreSearch($config, $schema); $sql = $search->mysqlQuery(NULL, $orderBy); return $sql; }