Sorry and thanks for the answer.
Michele
--------- Original Message --------
Da: "Dirk Kirsten" <dk@basex.org>
To:
Cc: "Maximilian Gärber" <mgaerber@arcor.de>, basex-talk@mailman.uni-konstanz.de
Oggetto: Re: [basex-talk] problem with prepared
Data: 10/09/15 10:28
Hello Michele,
please always make sure to send us a SSCCEE (see http://sscce.org/). It is very time-consuming to read such a large XQuery and I highly doubt all this is relevant for your actual problem.
Also, I highly doubt that you need 8 (!) for-loops, which are all nested. This takes an execution time of n^8, which is **a lot**, even for small values of n.
Also, all your for loops seem to do basically the same and work on the same data, so I doubt that it is really neccessary.
Based on this and your previous questions I would recommend you to get a better understanding of XQuery before tackling your actual problem. Otherwise, you will always stumble across new problems, which you could self yourself better and faster if you know the core conecpts. I can recommend the XQuery book by Priscilla Walmsley, I also find the wikibook about XQuery (https://en.wikibooks.org/wiki/XQuery) quite useful.
As part of our commercial offering we also offer seminars or on-site training (see http://basexgmbh.de/en/). If you are interested, please contact us in private.
Regards,
Dirk
On 09/10/2015 10:10 AM, michele.greco2@email.it wrote:
Thanks for the help ,Max. I modified my xquery this way: declare namespace pkg="http://schemas.microsoft.com/office/2006/xmlPackage"; declare namespace w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"; declare function local:indice() as xs:integer* { for $i in(1 to count(for $document in collection("curriculum") let $c:= document-uri($document) for $a in doc($c) order by $c return for $e in doc($c)//w:tc[.//text()="Nome"] return $e/./following::text()except (for $x in doc($c)//w:tc[.//text()="Indirizzo"] return $x//following::text()))) return $i }; declare function local:nome() as xs:string* { for $n in (for $document in collection("curriculum") let $c:= document-uri($document) for $a in doc($c) order by $c return for $e in doc($c)//w:tc[.//text()="Nome"] return $e/./following::text()except (for $x in doc($c)//w:tc[.//text()="Indirizzo"] return $x//following::text())) return $n }; declare function local:indirizzo() as xs:string* { for $in in (for $document in collection("curriculum") let $c:= document-uri($document) for $a in doc($c) order by $c return for $e in doc($c)//w:tc[.//text()="Indirizzo"] return $e/./following::text() except (for $x in doc($c)//w:tc[.//text()="Telefono"] return $x//following::text())) return $in }; declare function local:telefono() as xs:string* { for $t in (for $document in collection("curriculum") let $c:= document-uri($document) for $a in doc($c) order by $c return for $e in doc($c)//w:tc[.//text()="Telefono"] return $e/./following::text() except (for $x in doc($c)//w:tc[.//text()="Fax"] return $x//following::text())) return $t }; declare function local:fax() as xs:string* { for $f in (for $document in collection("curriculum") let $c:= document-uri($document) for $a in doc($c) order by $c return for $e in doc($c)//w:tc[.//text()="Fax"] return $e/./following::text() except (for $x in doc($c)//w:tc[.//text()="E-mail"] return $x//following::text())) return $f }; declare function local:email() as xs:string* { for $em in (for $document in collection("curriculum") let $c:= document-uri($document) for $a in doc($c) order by $c return for $e in doc($c)//w:tc[.//text()="E-mail"] return $e/./following::text() except (for $x in doc($c)//w:tc[.//text()="Nazionalità"] return $x//following::text())) return $em }; declare function local:nazionalita() as xs:string* { for $na in (for $document in collection("curriculum") let $c:= document-uri($document) for $a in doc($c) order by $c return for $e in doc($c)//w:tc[.//text()="Nazionalità"] return $e/./following::text() except (for $x in doc($c)//w:tc[.//text() ="D" ] return $x//following::text())) return $na }; declare function local:dataNascita() as xs:string* { for $d in (for $document in collection("curriculum") let $c:= document-uri($document) for $a in doc($c) order by $c return for $e in doc($c)//w:tc[.//text()="Data di nascita"] return $e/./following::text() except (for $x in doc($c)//w:tc[.//text()="Esperienza lavorativa"] return $x//following::text())) return $d }; for $indice at $pos in local:indice() for $nome in local:nome() [$pos] for $indirizzo in local:indirizzo()[$pos] for $telefono in local:telefono()[$pos] for $fax in local:fax()[$pos] for $email in local:email()[$pos] for $nazionalita in local:nazionalita()[$pos] for $datanascita in local:dataNascita()[$pos] let $init := sql:init("com.mysql.jdbc.Driver"), $conn := sql:connect("jdbc:mysql://localhost:3306/DbName","user","password''), $stmt := sql:prepare($conn, "INSERT INTO informazionipersonali(idInformazioniPersonali,nome,indirizzo,telefono,fax,email,nazionalità,dataNascita) VALUES(?,?,?,?,?,?,?,?) ") let $params:= <sql:parameters> <sql:parameter type="int">{$indice}</sql:parameter> <sql:parameter type="string">{$nome}</sql:parameter> <sql:parameter type="string">{$indirizzo}</sql:parameter> <sql:parameter type="string">{$telefono}</sql:parameter> <sql:parameter type="string">{$fax}</sql:parameter> <sql:parameter type="string">{$email}</sql:parameter> <sql:parameter type="string">{$nazionalita}</sql:parameter> <sql:parameter type="string">{$datanascita}</sql:parameter> </sql:parameters> return sql:execute-prepared($stmt,$params) It works,but it returns only the first row in my database, and i want a row for each value (indice,nome,indirizzo,........) How can i do?
--------- Original Message --------
Da: "Maximilian Gärber" <mgaerber@arcor.de>
To: "basex-talk@mailman.uni-konstanz.de" <basex-talk@mailman.uni-konstanz.de>
Oggetto: Re: [basex-talk] problem with prepared
Data: 09/09/15 09:12
or using a where statement
for $indice at $pos in local:indice()
for $nome at $pos2 in local:nome()
let $params:= <sql:parameters>
<sql:parameter type="int">{$indice}</sql:parameter>
<sql:parameter type="string">{$nome}</sql:parameter>
</sql:parameters>
where $pos2 = $pos
return $params
2015-09-09 9:05 GMT+02:00 Maximilian Gärber <mgaerber@arcor.de>:
> Hi,
>
> when you join (by nesting for statements) you will always get the
> combinations unless you provide more constraints.
>
> You might try something like:
>
> declare function local:indice() as xs:integer* {
>
> for $i in (1 to 10)
> return $i
> };
>
> declare function local:nome() as xs:string* {
>
> for $n in ('a', 'b', 'c', 'd')
> return $n
> };
>
> for $indice at $pos in local:indice()
> for $nome in local:nome()[$pos]
>
> let $params:= <sql:parameters>
> <sql:parameter type="int">{$indice}</sql:parameter>
> <sql:parameter type="string">{$nome}</sql:parameter>
> </sql:parameters>
> return $params
>
>
> Regards, Max
>
> 2015-09-08 16:20 GMT+02:00 <michele.greco2@email.it>:
>> Hi i have following xquery:
>> declare function local:indice() as xs:integer* {
>> count(for $document in collection("curriculum")
>> let $c:= document-uri($document)
>> for $a in doc($c)
>> order by $c
>> return
>> for $e in doc($c)//w:tc[.//text()="Nome"]
>> return $e/./following::text()except
>> (for $x in doc($c)//w:tc[.//text()="Indirizzo"]
>> return $x//following::text()))
>> };
>>
>> declare function local:nome() as xs:string* {
>> for $document in collection("curriculum")
>> let $c:= document-uri($document)
>> for $a in doc($c)
>> order by $c
>> return
>> for $e in doc($c)//w:tc[.//text()="Nome"]
>> return $e/./following::text()except
>> (for $x in doc($c)//w:tc[.//text()="Indirizzo"]
>> return $x//following::text())
>> };
>> for $ indice in local:indice()
>> let $init := sql:init("com.mysql.jdbc.Driver"),
>> $conn :=
>> sql:connect("jdbc:mysql://localhost:3306/DBName","user","password''),
>> $stmt := sql:prepare($conn, "INSERT INTO
>> informazionipersonali(idInformazioniPersonali,nome,indirizzo,telefono,fax,email,nazionalità,dataNascita)
>> VALUES(?,?,'null','null','null','null','null','null') ")
>> for $nome in local:nome()
>> let $params:= <sql:parameters>
>> <sql:parameter type="int">{$indice}</sql:parameter>
>> <sql:parameter type="string">{$nome}</sql:parameter>
>> </sql:parameters>
>> return sql:execute-prepared($stmt,$params)
>>
>>
>> which return a combination of index and names, but i want only one row for
>> each index and name.
>> How can i do?
>>
>> ----
>> ZE-Light e ZE-Pro: servizi zimbra per caselle con dominio email.it, per
>> tutti i dettagli clicca qui
>>
>> Sponsor:
>> Registra i domini che desideri ed inizia a creare il tuo sito web
>> Clicca qui
----
ZE-Light e ZE-Pro: servizi zimbra per caselle con dominio email.it, per tutti i dettagli clicca qui
Sponsor:
Soluzioni di email hosting per tutte le esigenze: dalle caselle gratuite a quelle professionali su piattaforma Zimbra, da quelle su proprio dominio a quelle certificate PEC. Confronta le soluzioni
Clicca qui
basex-talk@mailman.uni-konstanz.de