0 Replies Latest reply: Jan 18, 2009 11:52 PM by 374696 RSS

    problem of oo4o insert varray data

    374696
      i want to use oracle oo4o to insert the varray type data ,but it occurs error that

      ---------------------------
      OIP-04149: Invalid input object for field and parameters
      ---------------------------
      who will tell me what's wrong for this programm
      the table is created by the follow sql:


      drop table Varr_test;
      CREATE TYPE varrayf_9 AS VARRAY(9) OF float;
      CREATE TABLE Varr_test
      (
      NUM_INDEX number NOT NULL,
      TEXT varchar2(128),
      NUMBER_OPT varrayf_9
      );


      programme as follows:


      OStartup();
      oresult oRes ; // oRes is oresult
      OSession m_o_Session; //
      ODatabase m_o_db; //

      oRes = m_o_Session.Open();
      oRes = m_o_db.Open(m_o_Session,"oraDemet","system","myora"); // m_o_db is ODatabase
      oRes = m_o_db.BeginTrans();
      // the insert proccess
      // Add Params
      OParameterCollection oParamCol = m_o_db.GetParameters();
      OParamArray o_NUM_INDEX_Ary = oParamCol.AddTable("B_NUM_INDEX",OPARAMETER_INVAR,OTYPE_NUMBER,10);
      OParamArray o_TEXT_Ary = oParamCol.AddTable("B_TEXT",OPARAMETER_INVAR,OTYPE_VARCHAR2,10,250);
      OParamArray o_NUMBER_OPT_Ary = oParamCol.AddTable("B_NUMBER_OPT",OPARAMETER_INVAR,OTYPE_VARRAY,10);
      OCollection otest;
      for(int i =0;i<10;i++){
      o_NUM_INDEX_Ary.SetValue(i,i);
      o_TEXT_Ary.SetValue("test",i);
      otest.Open(m_o_db,"varrayf_9");
      for(int j=0;j<9;j++)
      {
      otest.SetValue(j+1,j+1);
      if (oRes != OSUCCESS)
      {   // couldn’t create the table
      AfxMessageBox(m_o_db.GetErrorText());
      }

      }

      o_NUMBER_OPT_Ary.SetValue(otest,i);
      }

      oRes = m_o_db.ExecuteSQL("INSERT INTO Varr_test (NUM_INDEX,TEXT,NUMBER_OPT) VALUES (:B_NUM_INDEX,:B_TEXT,:B_NUMBER_OPT)");
      if (oRes != OSUCCESS)
      {   // couldn’t create the table
      AfxMessageBox(m_o_db.GetErrorText());
      }

      oParamCol.Remove("B_NUM_INDEX");
      oParamCol.Remove("B_TEXT");
      oParamCol.Remove("B_NUMBER_OPT");

      oRes = m_o_db.CommitTrans();
      oRes = m_o_db.Close();
      m_o_Session.Close();
      OShutdown();