sql error

Saturday, 5 September 2015 · 4 messages · last reply 7 Sep 2015
M
michele.greco25 Sep 2015 10:13 #
Hi, I wrote this xquery,who want to save the query result in myql.  
declare namespace pkg="http://schemas.microsoft.com/office/2006/xmlPackage";

declare namespace
w="http://schemas.openxmlformats.org/wordprocessingml/2006/main";

sql:init("com.mysql.jdbc.Driver"),

let $conn:=
sql:connect("jdbc:mysql://localhost:3306/DbName","user","password")
return
(let $q:= "insert into person values("","||nome||","","","","","","")"
return sql:execute($conn,$q)),
for $document in collection("curriculum")

let $c:= document-uri($document)
order by $c return <nome> {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()) }</nome>     but this is my error: [XPDY0002] nome: no context value bound. where am i wrong? -- ZE-Light e ZE-Pro: servizi zimbra per caselle con dominio email.it, per tutti i dettagli Clicca qui http://posta.email.it/caselle-di-posta-z-email-it/?utm_campaign=email_Zimbra_102014=main_footer/f Sponsor: Registra i domini che desideri ed inizia a creare il tuo sito web Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=13323&d=5-9
AH
Alexander Holupirek5 Sep 2015 21:49 #
What do you expect 'nome' to be here?
let $q:= "insert into person values("","||nome||","","","","","","")"
Maybe something like
let $nome := 'foo'
let $q := 'insert into person values("",' || '"' || $nome || '"' || ',"","","","","","")'
return $q
is more apt?
Quoted text · michele.greco2 at email.it · 33 lines
> On 05.09.2015, at 10:13, michele.greco2 at email.it wrote: > > Hi, > I wrote this xquery,who want to save the query result in myql. > > declare namespace pkg="http://schemas.microsoft.com/office/2006/xmlPackage"; > declare namespace w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"; > sql:init("com.mysql.jdbc.Driver"), > let $conn:= sql:connect("jdbc:mysql://localhost:3306/DbName","user","password") > return > (let $q:= "insert into person values("","||nome||","","","","","","")" > return sql:execute($conn,$q)), > for $document in collection("curriculum") > let $c:= document-uri($document) > order by $c > return <nome> > {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()) > }</nome> > > > but this is my error: > [XPDY0002] nome: no context value bound. > where am i wrong? > > ---- > 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
DP
Dimitar Popovin reply to michele.greco2, 5 Sep 2015, 10:135 Sep 2015 21:56 #
Quoted text · michele.greco2 at email.it · 2 lines
On Saturday, September 05, 2015 10:13:08 AM michele.greco2 at email.it wrote: > Hi,
Hi!
Quoted text · michele.greco2 · 1 line
> where am i wrong?
1. you have an XQuery syntax error; instead of: let $q:= "insert into person values("","||nome||","","","","","","")" it should be (note the different quotation marks): let $q:= "insert into person values(''," || $nome || ",'','','','','','')" 2. you have SQL injection [1] and performance issue by concatenating the value directly into the SQL statement; prepared statements [2] are in this case your friend:
declare namespace w="http://schemas.openxmlformats.org/wordprocessingml/2006/main";

declare function local:nome() as xs:string* {
  (: I've no idea whatcha doin here pal... :)
  for $document in collection("curriculum")
  let $c:= document-uri($document)
  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())
};

let $init := sql:init("com.mysql.jdbc.Driver"),
    $conn := sql:connect("jdbc:mysql://localhost:3306/DbName","user","password"),
    $stmt := sql:prepare($conn, "INSERT INTO person VALUES('',?,'','','','','')")
for $nome in local:nome()
return sql:execute-prepared($stmt,
    <sql:parameters>
      <sql:parameter type="string">{$nome}</sql:parameter>
    </sql:parameters>)
Check the BaseX docs [3] for more info and come back if you need more help :) Cheers, Dimitar [1] https://en.wikipedia.org/wiki/Sql_injection [2] https://en.wikipedia.org/wiki/Prepared_statement [3] http://docs.basex.org/wiki/SQL_Module
M
michele.greco27 Sep 2015 09:12 #
Hi thanks for help me. Now, i have the following error: [bxerr:BXSQ0003] Number of parameters differs from number of placeholders What can i do to solve it?
Quoted text · Dimitar Popov · 64 lines
--------- Original Message -------- Da: "Dimitar Popov" &lt;dp at basex.org&gt; To: "basex-talk at mailman.uni-konstanz.de" &lt;basex-talk at mailman.uni-konstanz.de&gt; Oggetto: Re: [basex-talk] sql error Data: 05/09/15 21:56 On Saturday, September 05, 2015 10:13:08 AM michele.greco2 at email.it wrote: &gt; Hi, &nbsp; Hi! &nbsp; &gt; where am i wrong? &nbsp; 1. you have an XQuery syntax error; instead of: let $q:= "insert into person values("","||nome||","","","","","","")" it should be (note the different quotation marks): let $q:= "insert into person values(''," || $nome || ",'','','','','','')" &nbsp; 2. you have SQL injection [1] and performance issue by concatenating the value directly into the SQL statement; prepared statements [2] are in this case your friend: &nbsp; declare namespace w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"; &nbsp; declare function local:nome() as xs:string* { (: I've no idea whatcha doin here pal... :) for $document in collection("curriculum") let $c:= document-uri($document) 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()) }; &nbsp; let $init := sql:init("com.mysql.jdbc.Driver"), $conn := sql:connect("jdbc:mysql://localhost:3306/DbName","user","password"), $stmt := sql:prepare($conn, "INSERT INTO person VALUES('',?,'','','','','')") for $nome in local:nome() return sql:execute-prepared($stmt, &lt;sql:parameters&gt; &lt;sql:parameter type="string"&gt;{$nome}&lt;/sql:parameter&gt; &lt;/sql:parameters&gt;) &nbsp; Check the BaseX docs [3] for more info and come back if you need more help :) &nbsp; Cheers, Dimitar &nbsp; &nbsp; [1] https://en.wikipedia.org/wiki/Sql_injection [2] https://en.wikipedia.org/wiki/Prepared_statement [3] http://docs.basex.org/wiki/SQL_Module -- ZE-Light e ZE-Pro: servizi zimbra per caselle con dominio email.it, per tutti i dettagli Clicca qui http://posta.email.it/caselle-di-posta-z-email-it/?utm_campaign=email_Zimbra_102014=main_footer/f 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: http://adv.email.it/cgi-bin/foclick.cgi?mid=13325&d=7-9

⚡Generated with XQuery