学而不思则罔,思而不学则殆

有其事必有其理, 有其理必有其事

  IT博客 :: 首页 :: 联系 :: 聚合  :: 管理
  85 Posts :: 12 Stories :: 47 Comments :: 0 Trackbacks

bool T_Oracl::Init()
{
 try
 {
//  m_env = Environment::createEnvironment(Environment::DEFAULT);
  m_env = Environment::createEnvironment("ZHS16GBK","UTF8");
  if (NULL == m_env)
   return false ;


     /* 
  string userName = "SYSTEM";
  string password = "songck";
  string connectString = "//192.168.1.102:1521/ORCL";
  */

  m_con = m_env->createConnection(m_str_user, m_str_pass, m_str_con);
  m_smt = m_con->createStatement() ;

 }
 catch(SQLException excp)
 {
  string str_ex = excp.what() ;
  int  id  = excp.getErrorCode() ;

  Environment::terminateEnvironment(m_env); 
  m_env = NULL ;

  return false ;
 }


  return true ;
}


bool  T_Oracl::isCheckTMP(MIR_TEMPLATE *p_left, MIR_TEMPLATE *p_right, DB_ACK_Result& o_ACK)
{
 bool is_Exist = false ;
 ResultSet* rset = NULL ;

 FLOAT32 min_cmp =5.0 ;
 try
 {
  string  str_sql = "SELECT id ,name ,LBIN ,RBIN FROM tb_eyesmart" ; 
  m_smt->setSQL(str_sql) ;

  ResultSet* rset = m_smt->executeQuery();

  while (  rset->next ())
  { 
   if(is_Exist)
    break ;

   FLOAT32  L_CMP , R_CMP ;
   
   Blob l__blob = rset->getBlob (3);
   L_CMP = __CmpIrisTMP(p_left , p_right , l__blob );
   l__blob.close();

   Blob r__blob = rset->getBlob (4);
   R_CMP = __CmpIrisTMP(p_left , p_right , r__blob );
   r__blob.close();

   if (L_CMP < __g_CMP_THREAD ||  R_CMP < __g_CMP_THREAD)
   {
    string id = rset->getString(1) ;
    string name = rset->getString(2) ;

    strncpy(&o_ACK.str_ID[0]   , id.c_str() ,  id.length());
    strncpy(&o_ACK.str_Name[0] , name.c_str(), name.length());

    o_ACK.f_cmpValue =  L_CMP < R_CMP ? L_CMP : R_CMP ;

    is_Exist = true ;
   }
   else
   {
    min_cmp = min_cmp<  R_CMP ? min_cmp : R_CMP ;
    min_cmp = min_cmp<  L_CMP ? min_cmp : L_CMP ;
   }
   
  }
 }
 catch(SQLException excp)
 {
  string str_ex = excp.what() ;
  int  id  = excp.getErrorCode() ;
  is_Exist = false ;
 }
 
 if (rset) 
  m_smt->closeResultSet (rset);

 if ( ! is_Exist)
 {
  o_ACK.f_cmpValue =  min_cmp ;
 }

 return is_Exist ;
}


FLOAT32 T_Oracl::__CmpIrisTMP(MIR_TEMPLATE * pTemplateA, MIR_TEMPLATE * pTemplateB, Blob& a_blob)
{
 a_blob.open (OCCI_LOB_READONLY); 
 
 FLOAT32  tmp_cmp =1.0 ;
 int compareOk  ;
 MIR_RESULTS results;

 Stream *instream = a_blob.getStream ();       
 long    tmp_size = a_blob.length() ; 
 if ( tmp_size !=579 )
 {
  return  tmp_cmp ;
 }

 instream->readBuffer((char*)p_cmp_l_CaptureTemplate->pfullTemplate  ,tmp_size) ;     

 if (pTemplateA)
 {  
  compareOk = MIR_CompareTemplates(p_cmp_l_CaptureTemplate, pTemplateA, &results);
  if ( (!compareOk) && ( ! _isnan(results.Distance_Hamming1) ))
  {
   if (tmp_cmp > results.Distance_Hamming1)
   {
    tmp_cmp = results.Distance_Hamming1 ;
   }
  }
 }
 
 if (pTemplateB)
 { compareOk = MIR_CompareTemplates(p_cmp_l_CaptureTemplate, pTemplateB, &results);
  if ( (!compareOk) && ( ! _isnan(results.Distance_Hamming1) ))
  {
   if (tmp_cmp > results.Distance_Hamming1)
   {
    tmp_cmp = results.Distance_Hamming1 ;
   }
  }
 }


 return  tmp_cmp ;
}


bool T_Oracl::InsertIrisTMP(MIR_TEMPLATE *p_left, MIR_TEMPLATE *p_right, DB_ACK_Result &o_ACK)
{
 try
 {
  string  str_sql = "INSERT INTO tb_eyesmart(ID, NAME, GENDER, BIRTHDAY, LBIN, RBIN, OPTIME) VALUES (:v1, :v2, :v3, TO_DATE(:v4, 'YYYY-MM-DD'), EMPTY_BLOB(), EMPTY_BLOB() ,sysdate)" ;
  
  m_smt->setSQL(str_sql) ;
  m_smt->setString(1, o_ACK.str_ID);
  m_smt->setString(2, o_ACK.str_Name) ;
  m_smt->setString(3, o_ACK.str_Age) ;
  m_smt->setString(4, o_ACK.str_Birthday) ;

  m_smt->executeUpdate();
  m_con->commit();


  str_sql= "SELECT LBIN ,RBIN FROM tb_eyesmart WHERE ID=:v1  FOR UPDATE" ;
  m_smt->setSQL(str_sql) ;
  m_smt->setString(1, o_ACK.str_ID) ;

  ResultSet *rset  =  m_smt->executeQuery() ;
  while( rset->next())
  {
   char* c=(char*)"";
   Blob l_blob  = rset->getBlob(1) ;
   Stream* l_strm= l_blob.getStream() ;
   l_strm->writeBuffer((char*) p_left->pfullTemplate,__g_LEN_ENROLL_TMP);
   l_strm->writeLastBuffer(c,0);
   l_blob.closeStream(l_strm) ;


   Blob r_blob  = rset->getBlob(2) ;
   Stream* r_strm= r_blob.getStream() ;
   r_strm->writeBuffer((char*) p_right->pfullTemplate,__g_LEN_ENROLL_TMP);
   r_strm->writeLastBuffer(c,0);
   r_blob.closeStream(r_strm);
  }

  m_smt->closeResultSet (rset);
  m_con->commit();

  return true ;
 }
 catch(SQLException excp)
 {
  string str_ex = excp.what() ;
  int  id  = excp.getErrorCode() ;

  return false ;
 }

 return  false ;
}

 

posted on 2011-08-02 09:48 易道 阅读(471) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。