oracle - Why does the sequence of parameters matter in SQL -
i think entry-level, haven't googled answer out..
when building queries, have use :1, :2... stuff in absolute sequence? tests, seems yes. doesn't calling stmt->setxxx(n, val) set nth parameter in statement val? how implemented?
please see example below:
if (bnewcontent) //new { sql = "begin packproductmanagement.procaddottcontent(:1, :2, :3, :4, :5, :6, :7); end; "; } else //update { sql = "update ott_content set contentid = :1, contenttype = :2, fingerprint = :3, ishighlevelsafe = :4, "; sql += "outprotection = :5, offlineplayback = :6, modifytime = sysdate "; sql += "where contentid = :1"; } try { openstatement(sql); stmt->setstring(1, ac->contentdesc.contentid); stmt->setuint(2, ac->contentdesc.contenttype); stmt->setuint(3, ac->contentdesc.fingerprint); stmt->setuint(4, ac->contentdesc.highlevelsafe); stmt->setuint(5, ac->contentdesc.outputprotection); stmt->setuint(6, ac->contentdesc.offlineplayback); if (bnewcontent) { stmt->setuint(7, 0); //only used if new } stmt->execute(); closestatement(true); }
in example, bnewcontent
false, we're running update statement. above query works ok. if change update query below (removed contentid = :1,
@ beginning of update statement), i'll ora-01722 invalid_number. why can't :2:3:4:5:6:1? if setxxx implemented queue, why above :1:2:3:4:5:6:1 work??
sql = "update ott_content set contenttype = :2, fingerprint = :3, ishighlevelsafe = :4, "; sql += "outprotection = :5, offlineplayback = :6, modifytime = sysdate "; sql += "where contentid = :1";
thanks in advance!
edited:
test results below: (based on zza's answer)
sql = "update ott_content set contentid = :x contenttype = :x, fingerprint = :x, ishighlevelsafe = :x, "; sql += "outprotection = :x, offlineplayback = :x, modifytime = sysdate "; sql += "where contentid = :x";
above code doesn't work 6 parameters.
sql = "update ott_content set contentid = :1 contenttype = :x, fingerprint = :x, ishighlevelsafe = :x, "; sql += "outprotection = :x, offlineplayback = :x, modifytime = sysdate "; sql += "where contentid = :1";
above code works 6 parameters.
according oracle documentation bind variables used in order placed, not how named. that's why exception. so, need set parameters in order mentioned (the first mentioned contenttype
in case remove first), , doesn't matter how they're named.
your code , still work:
if (bnewcontent) //new { sql = "begin packproductmanagement.procaddottcontent(:x, :x, :x, :x, :x, :x, :x); end; "; } else //update { sql = "update ott_content set contentid = :x, contenttype = :x, fingerprint = :x, ishighlevelsafe = :x, "; sql += "outprotection = :x, offlineplayback = :x, modifytime = sysdate "; sql += "where contentid = :x"; } try { openstatement(sql); stmt->setstring(1, ac->contentdesc.contentid); stmt->setuint(2, ac->contentdesc.contenttype); stmt->setuint(3, ac->contentdesc.fingerprint); stmt->setuint(4, ac->contentdesc.highlevelsafe); stmt->setuint(5, ac->contentdesc.outputprotection); stmt->setuint(6, ac->contentdesc.offlineplayback); if (bnewcontent) { stmt->setuint(7, 0); //only used if new } stmt->execute(); closestatement(true); }
Comments
Post a Comment