I am using XQuery 3.0 for exist-db, and am trying to make the string $value a dateTime object. This is what I've got, but it's not working:
let $value := '"2001-10-18T08:47:00"'
if ($key = 'start_time')
then
element { $key } { xs:dateTime(string(replace($value, '"', ''))) }
It's saying: illegal lexical form for date-time-like value ''. Any ideas?
I'm unable to reproduce the error you're getting with that code - which is incomplete (lacks return and else clauses, doesn't define $key). But paring those issues away, your code runs fine for me, as follows:
let $value := '"2001-10-18T08:47:00"'
return
xs:dateTime(replace($value, '"', ''))
The result:
2001-10-18T08:47:00
Related
This question is based on my previous one where my entire TYPO3 website didn't work.
Now, after adjusting the php-version (5.6.17) the website itself works, but one fe-plugin of my extbase extension doesn't work - even though it's identical to the one on a copy of the website where everything works. The other fe-plugin from the same extension directly worked out of the box.
I get the following error in the frontend whenever I call a page that contains this plugin and I don't know where to start searching for the cause.
(I changed my domain to <mydomain> and my plugin name to tx_myfeplugin_nameexte in the following error snippet):
#1: PHP Warning: rawurlencode() expects parameter 1 to be string, object given in /var/www/vhosts/<my-domain>/typo3/sysext/core/Classes/Utility/GeneralUtility.php line 1641 (More information)
TYPO3\CMS\Core\Error\Exception thrown in file
/var/www/vhosts/<my-domain>/typo3/sysext/core/Classes/Error/ErrorHandler.php in line 101.
49 TYPO3\CMS\Core\Error\ErrorHandler::handleError(2, "rawurlencode() expects parameter 1 to be string, object given", "/var/www/vhosts/<my-domain>…po3/sysext/core/Classes/Utility/GeneralUtility.php", 1641, array)
48 rawurlencode(TYPO3\CMS\Extbase\Persistence\Generic\QueryResult)
/var/www/vhosts/<my-domain>/typo3/sysext/core/Classes/Utility/GeneralUtility.php:
01639: } else {
01640: if (!$skipBlank || (string)$AVal !== '') {
01641: $str .= '&' . ($rawurlencodeParamName ? rawurlencode($thisKeyName) : $thisKeyName) . '=' . rawurlencode($AVal);
01642: }
01643: }
47 TYPO3\CMS\Core\Utility\GeneralUtility::implodeArrayForUrl("tx_myfeplugin_nameexte", array, "", boolean, boolean)
/var/www/vhosts/<my-domain>/typo3/sysext/core/Classes/Utility/GeneralUtility.php:
01636: $thisKeyName = $name ? $name . '[' . $Akey . ']' : $Akey;
01637: if (is_array($AVal)) {
01638: $str = self::implodeArrayForUrl($thisKeyName, $AVal, $str, $skipBlank, $rawurlencodeParamName);
01639: } else {
01640: if (!$skipBlank || (string)$AVal !== '') {
Did someone have the same error before or has an idea what I should try to do to fix this?
Thanks to the answer I guess I fixed it, because the error is not appearing any longer, by adding the following lines at line 1707 in file GeneralUtility.php:
if ($AVal instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult) {
$AVal = $AVal->toArray();
}
lets have a look to the source:
foreach ($theArray as $Akey => $AVal) {
$thisKeyName = $name ? $name . '[' . $Akey . ']' : $Akey;
if (is_array($AVal)) {
$str = self::implodeArrayForUrl($thisKeyName, $AVal, $str, $skipBlank, $rawurlencodeParamName);
} else {
if (!$skipBlank || (string)$AVal !== '') {
$str .= '&' . ($rawurlencodeParamName ? rawurlencode($thisKeyName) : $thisKeyName . '=' . rawurlencode($AVal);
}
}
}
The array you give has to be a multidimensional array as it represents the parts of the url. Every element is testet being an array, so you could debug $AVal being an object but an array.
I guess that there could be an stdObject from any conversion you made before. Debugging will help you.
Second, what is the reporting you set in the install tool. Set it to production, will ist work then?
I need create multiply search by years. From request I get string like 2017,2018 and then I want get Questions which createdAt, between from start year and end year. I have query builder with part, and I'am not understand why I have this error
if ($paramFetcher->get('years')) {
$orXSearch = $qb->expr()->orX();
$yearData = trim($paramFetcher->get('years'));
foreach (explode(',', $yearData) as $key => $id) {
if (!$id) {
continue;
}
$orXSearch
->add($qb->expr()->between('q.createdAt', ':'.$key.'dateFrom', ':'.$key.'dateTo'));
$date = $this->additionalFunction->validateDateTime($id, 'Y');
$first = clone $date;
$first->setDate($date->format('Y'), 1, 1);
$first->setTime(0, 0, 0);
$last = clone $date;
$last->setDate($date->format('Y'), 12, 31);
$last->setTime(23, 59 , 59);
$qb
->setParameter($key.'dateFrom', $first->format('Y-m-d H:i:s'))
->setParameter($key.'dateTo', $last->format('Y-m-d H:i:s'));
}
$qb->andWhere($orXSearch);
}
error:
symfony Invalid parameter format, : given, but :<name> or ?<num> expected.
In your foreach loop, you’re looping over the result of an explode operation which yields a numeric array, i.e. $key will always have a numeric value.
Hence, your parameter placeholder is colon + number + string, i.e. :1dateFrom. This is not allowed. Either you reference a string value with a colon + string placeholder (:foo), or you reference a numeric value with a question mark + number value (?1).
Your problem is easy to solve: Simply add any letter between the colon and the number, and you’re good:
->add($qb->expr()->between(
'q.createdAt',
':x'.$key.'dateFrom',
':x'.$key.'dateTo'
));
I'm new to Symfony, and I got an error while running a query :
public function getFilteredArticles($page, $nbPerPage, $data) {
$query = $this->createQueryBuilder('a')
->leftJoin('a.images', 'i')
->addSelect('i')
->leftJoin('a.type_stockage', 't')
->addSelect('t')
->leftJoin('a.famille', 'f')
->addSelect('f');
if ($data['famille'] != '') {
$query->where('f.id = :famille')
->setParameter('famille', $data['famille']);
}
if ($data['rds'] == false) {
$query->where('a.stock_actuel > 0');
}
if ($data['recherche'] != '' && $data['recherche'] != null) {
$query->where('a.ref_article LIKE :recherche')
->setParameter('recherche', '%' . $data['recherche'] . '%');
}
$query->leftJoin('a.sousfamille', 's')
->orderBy('a.ref_article', 'ASC')
->getQuery();
$query->setFirstResult(($page - 1) * $nbPerPage)
->setMaxResults($nbPerPage);
return new Paginator($query, true);
}
This query have conditionnals parameters as you can see, that returns the list of articles I need for a table. But when I run this query to fill my table, I got the error :
An exception has been thrown during the rendering of a template ("Too
many parameters: the query defines 0 parameters and you bound 1").
I don't know why he is expecting 0 parameters. I tried using setParameters instead, but the result is the same.
Does anyone has an idea?
You should use andWhere() methods instead of where().
where() method removes all previous where, but setParameter() does not. That's why he found more parameters than where clauses.
I personally never use where if the condition has no sense to be the first condition, to avoid this kinds of errors.
if ($data['famille'] != '') {
$query->andWhere('f.id = :famille')
->setParameter('famille', $data['famille']);
}
if ($data['rds'] == false) {
$query->andWhere('a.stock_actuel > 0');
}
if ($data['recherche'] != '' && $data['recherche'] != null) {
$query->andWhere('a.ref_article LIKE :recherche')
->setParameter('recherche', '%' . $data['recherche'] . '%');
}
where() php doc
Specifies one or more restrictions to the query result.
Replaces any previously specified restrictions, if any.
andWhere() php doc
Adds one or more restrictions to the query results, forming a logical
conjunction with any previously specified restrictions.
My error, in Symfony 4, using Doctrine 2.6 was
Too many parameters: the query defines 0 parameters and you bound 2
The problem was that I wasn't defining the parameters in andWhere method as
$this->createQueryBuilder('q')
...
->andWhere('q.propertyDate IS NOT NULL') //this also couldn't find anywhere
->andWhere('q.parameterName = :parameterName')
->setParameters(['q.parameterName' => $parameterName, ...2nd parameter])
As I couldn't find any answer to my problem, but was similar to this one, I thought to maybe help someone who is struggling like I was.
also in symfony 5 and 6 you should use andWhere() methods instead of where().
where() method removes all previous where, but setParameter() does not. That's why he found more parameters than where clauses.
I have a csv file. I've managed import these data into MarkLogic using mlcp which then created a xml file in MarkLogic.
Now in csv I have this format "6/29/2013 5:00:00 PM" random in one of the column. How do I use xquery and probably node-replace as a transform function to convert this date into a different format such as "2013-06-29" as MarkLogic default date format?
Any help is appreciated...
I have created transform.xqy and install it on Modules in MLogic. I'm
thinking about using "xdmp:node-replace" to replace the date with expected
format. Or should I go thorugh the csv column by column (How to do?) and
use "castable as xs:dateTime" to determine date value or not. Yet, even
just printing out the content value/uri, always giving me error.
xquery version "1.0-ml";
module namespace example = "http://test.com/example";
(: If the input document is XML, insert #NEWATTR, with the value
: specified in the input parameter. If the input document is not
: XML, leave it as-is.
:)
declare function example:transform(
$content as map:map,
$context as map:map
) as map:map*
{
let $the-doc-uri := map:get($content, "uri")
let $the-doc := map:get($content, "value")
return
trace($the-doc, 'The value of doc is: ')
};
The MarkLogic documentation contains a full example of an MLCP transform:
https://docs.marklogic.com/guide/mlcp/import#id_65640
It shows this example, which adds an attribute to the XML content:
declare function example:transform(
$content as map:map,
$context as map:map
) as map:map*
{
let $attr-value :=
(map:get($context, "transform_param"), "UNDEFINED")[1]
let $the-doc := map:get($content, "value")
return
if (fn:empty($the-doc/element()))
then $content
else
let $root := $the-doc/*
return (
map:put($content, "value",
document {
$root/preceding-sibling::node(),
element {fn:name($root)} {
attribute { fn:QName("", "NEWATTR") } {$attr-value},
$root/#*,
$root/node()
},
$root/following-sibling::node()
}
), $content
)
};
Keep in mind you are supposed to update the "value" property of the $content map:map, and return $content to get your transformation result added to the database. I suggest using a (potentially recursive) typeswitch to identify element nodes, and then adjusting their value accordingly..
HTH!
finally did it.
The thing is I must use mem:node-replace because it is on the fly, on memory. While xdmp:node-replace is when the data is already on MarkLogic.
The rest is as expected I must use format-date and xdmp:parse-dateTime to get date format as required.
Here is some snippets
xquery version "1.0-ml";
module namespace ns_transform = "this_is_my_namespace";
import module namespace mem = "http://xqdev.com/in-mem-update" at "/MarkLogic/appservices/utils/in-mem-update.xqy";
declare variable $ns := "this_is_my_namespace";
declare function ns_transform:transform(
$content as map:map,
$context as map:map
) as map:map*
{
let $doc := map:get($content, "value")
let $format_in := "[M]/[D]/[Y0001] [h01]:[m01]:[s01] [P]"
let $format_out := "[Y0001]-[M01]-[D01]"
let $old_date := $doc/*:root_doc/*:date/text()
let $new_date := format-date(xs:date(xdmp:parse-dateTime($format_in, $old_date)), $format_out)
let $new_doc := mem:node-replace($doc/*:root_doc/*:date,element {fn:QName($ns, "date")}{$new_date})
let $_ := map:put($content, "value", $new_doc)
return $content
};
I have been trying to set a value containing a percentage sign in PHPExcel.
I couldn't find how to escape it at all and all searches point me to how to format a percentage, but that's not what I need.
My current problem is:
$cell = 'Z12';
$value = '=Y12-(Y12*20%)';
$excel->setActiveSheetIndex(0)->setCellValue($cell, $value);
This problem is specific to the Excel5 Writer, the percentage operator works correctly in other writers.
I'm about to push a fix to github, but in the meanwhile you can edit the Classes/PHPExcel/Writer/Excel5/Parser.php file.
Lines 1431-1437 currently read:
if($this->_lookahead == '%'){
$result = $this->_createTree('ptgPercent', $this->_current_token, '');
} else {
$result = $this->_createTree($this->_current_token, '', '');
}
$this->_advance();
return $result;
Modify these with an extra call to $this->_advance(); for the % operator lookahead branch:
if($this->_lookahead == '%'){
$result = $this->_createTree('ptgPercent', $this->_current_token, '');
$this->_advance(); // Skip the percentage operator once we've pre-built that tree
} else {
$result = $this->_createTree($this->_current_token, '', '');
}
$this->_advance();
return $result;