Esempio n. 1
0
int ChargeBusiness::NotifyOrder(TopupInfo *topupInfo){
    int ret = 0;
    Statement *stmt = NULL;
    try{
        string ts;
        get_time_now("%Y/%m/%d %H:%M:%S", ts);
        int notify = 1;
        stmt = conn->createStatement(SQL_UPDATE_NOTIFY);
        stmt->setAutoCommit(false);
        string sysNo = topupInfo->qs_info.coopOrderNo;
        stmt->setInt(1, topupInfo->notify);
        stmt->setString(2, ts);
        stmt->setString(3, sysNo);
        stmt->executeUpdate();
    }catch(SQLException &sqlExcp){
        HandleException(sqlExcp);
        ret = -1;
    }catch(std::exception &e){
        HandleException(e);
    }
    if(stmt)
        conn->terminateStatement(stmt);
    Finish();
    return ret;
}
Esempio n. 2
0
//验证用户微信号
int ChargeBusiness::VerifyWeixin(string userId, string openId){
    Statement *stmt = NULL;
    int ret = 0;
    try{
        stmt = conn->createStatement(QUERY_USER_SQL);
        stmt->setString(1, userId);
        ResultSet *rs = stmt->executeQuery();
        string user_open_id;
        int id = -1;
        while(rs->next())
        {
            id = rs->getInt(1);
            user_open_id = rs->getString(2);
        }
        if(id == -1){
            ret = 1;
        }else if(user_open_id.empty()){
            conn->terminateStatement(stmt);
            stmt = conn->createStatement(VERIFY_SQL);
            stmt->setString(1, openId);
            stmt->setString(2, userId);
            stmt->executeUpdate();
        }else{
            ret = 2;
        }
        
    }catch(SQLException &sqlExcp){
        HandleException(sqlExcp);
    }catch(std::exception &e){
        HandleException(e);
    }   
    if(stmt)
        conn->terminateStatement(stmt);
    return ret;
}
Esempio n. 3
0
int ChargeBusiness::UpdateChannel(TopupInfo *topupInfo){
    int ret = 0;
    Statement *stmt = NULL;
    try{
        stmt = conn->createStatement(SQL_UPDATE_CHANNEL);
        stmt->setAutoCommit(false);
        string tbOrderNo = topupInfo->qs_info.coopOrderNo;
        stmt->setInt(1, topupInfo->channelId);
        int total_value = topupInfo->qs_info.value * topupInfo->qs_info.cardNum;
        stmt->setFloat(2, total_value * topupInfo->channel_discount);
        stmt->setFloat(3, topupInfo->qs_info.sum - total_value * topupInfo->channel_discount);
        stmt->setString(4, tbOrderNo);
        stmt->executeUpdate();
    }catch(SQLException &sqlExcp){
        HandleException(sqlExcp);
        ret = -1;
    }catch(std::exception &e){
        HandleException(e);
        ret = -1;
    }
    Finish();
    if(stmt)
        conn->terminateStatement(stmt);
    return ret;
}
Esempio n. 4
0
	int db_createPlayerInfo(Connection *conn, const PlayerInfo *info)
	{
		boost::format fmter("insert into g_user(user_name,user_pwd,level,gender,role_id,scene_id,x,y) values('%s','%s',%d,%d,%d,%d,%d,%d)");
		fmter % info->user_name;
		fmter % info->user_pwd;
		fmter % info->level;
		fmter % (int)info->gender;
		fmter % info->role_id;
		fmter % info->scene_id;
		fmter % info->x;
		fmter % info->y;
		
		std::string sql = boost::str(fmter);
		int ret = 0;
		
		Statement *stmt = conn->createStatement();
		try
		{
			ret = stmt->executeUpdate(sql.c_str());
		}
		catch (sql::SQLException &e)
		{
			sLog.outError("[db_createPlayerInfo] sql error :%s errorCode: %d", e.what(), e.getErrorCode());
		}
	
		delete stmt;
		return ret;
	}
Esempio n. 5
0
    // Function to call a PL/SQL function
    void callfun ()
    {   cout << "callfun - invoking a PL/SQL function having IN, OUT and IN/OUT ";
        cout << "parameters" << endl;
        Statement *stmt = con->createStatement
                          ("BEGIN :a := demo_fun(:v1, :v2, :v3); END;");
        try {
            cout << "Executing the block :" << stmt->getSQL() << endl;
            stmt->setInt (2, 10);
            stmt->setMaxParamSize (3, 30);
            stmt->setString (3, "IN");
            stmt->registerOutParam (1, OCCISTRING, 30, "");
            stmt->registerOutParam (4, OCCISTRING, 30, "");
            int updateCount = stmt->executeUpdate ();
            cout << "Update Count : " << updateCount << endl;

            string c1 = stmt->getString (1);
            string c2 = stmt->getString (3);
            string c3 = stmt->getString (4);

            cout << "Printing the INOUT & OUT parameters :" << endl;
            cout << "Col2: " << c2 << endl;
            cout << "Col3: " << c3 << endl;
            cout << "Printing the return value of the function: ";
            cout << c1 << endl;

            con->terminateStatement (stmt);
            cout << "occifun - done" << endl;
        }
        catch (SQLException ex) {
            cout << ex.getMessage() << endl;
        }
    } // end of callfun ()
Esempio n. 6
0
int ChargeBusiness::UpdateOrderStatus(TopupInfo *topupInfo){
    int ret = 0;
    Statement *stmt = NULL;
    try{
        int status = 0;
        if(topupInfo->status == SUCCESS){
            status = 1;
        }else if(topupInfo->status == FAILED){
            status = 2;
        }
        string ts;
        get_time_now("%Y/%m/%d %H:%M:%S", ts);
        int notify = topupInfo->notify;
        stmt = conn->createStatement(SQL_UPDATE_STATUS);
        stmt->setAutoCommit(false);
        string tbOrderNo = topupInfo->qs_info.coopOrderNo;
        stmt->setInt(1, status);
        stmt->setInt(2, notify);
        stmt->setString(3, ts);
        stmt->setString(4, tbOrderNo);
        stmt->executeUpdate();
    }catch(SQLException &sqlExcp){
        HandleException(sqlExcp);
        ret = -1;
    }catch(std::exception &e){
        HandleException(e);
        ret = -1;
    }
    Finish();
    if(stmt)
        conn->terminateStatement(stmt);
    return ret;
}
/*
 * @sql_statement SQL语句字符串
 */
bool OraDBOpration::ExecuteNonQuery(string sql_statement)
{
    
    Statement *stmtement = con->createStatement();
    
    try
    {
        stmtement->setSQL(sql_statement);
        stmtement->executeUpdate();
		//con->commit();
    }

    catch (SQLException &ex)
    {
		con->rollback();
        cout << "Exception thrown for NonQuery" << endl;
        cout << "Error number: " << ex.getErrorCode() << endl;
        cout << "Error Msg: "<< ex.getMessage() << endl;
        cout << "SQL: "<<sql_statement << endl;
		con->terminateStatement(stmtement);
		return false;

    }
    con->terminateStatement(stmtement);
	return true;
}
Esempio n. 8
0
void Exporter::warehouse()
{
	::Connection *s = NULL;
	Statement *sth = NULL;
	while(1) {
		if((s=_queue->dequeue()) != NULL) {
			if(_conn == NULL) {
				continue;
			}

			try {
			    if(sth == NULL) {
				sth = _conn->createStatement(_query);
				sth->setAutoCommit(true);
			    }
			    //std::cout << *s << std::endl;
			    sth->setInt(1, s->saddr);
			    sth->setInt(2, s->daddr);
			    sth->setInt(3, s->bytes);
			    sth->setInt(4, s->start);
			    sth->setInt(5, s->ts);
			    sth->setString(6, s->conn_data != NULL? s->conn_data->pack() : "");
			    sth->executeUpdate();
			}
			catch(std::exception &e) {
			    std::cerr << "Error executing query: " << e.what() << std::endl;
			    delete(sth);
			    sth = NULL;
			}
			s->setExported(true);
		} else {
			sleep(1);
		}
	}
}
Esempio n. 9
0
  /**
   * Inserting a row into elements table.
   * Demonstrating the usage of BFloat and BDouble datatypes
   */
  void insertElement (string elm_name, float mvol=0.0, double awt=0.0)
  {
    BFloat mol_vol;
    BDouble at_wt;

    if (!(mvol))
      mol_vol.isNull = TRUE;
    else
      mol_vol.value = mvol;

    if (!(awt))
      at_wt.isNull = TRUE;
    else
      at_wt.value = awt;

    string sqlStmt = "INSERT INTO elements VALUES (:v1, :v2, :v3)";
    stmt = conn->createStatement (sqlStmt);

    try{
    stmt->setString(1, elm_name);
    stmt->setBFloat(2, mol_vol);
    stmt->setBDouble(3, at_wt);
    stmt->executeUpdate ();
    cout << "insertElement - Success" << endl;
    }catch(SQLException ex)
    {
     cout<<"Exception thrown for insertElement"<<endl;
     cout<<"Error number: "<<  ex.getErrorCode() << endl;
     cout<<ex.getMessage() << endl;
    }
    conn->terminateStatement (stmt);
  }
Esempio n. 10
0
 // Function to call a PL/SQL procedure
 void callproc ()
 {
     cout << "callproc - invoking a PL/SQL procedure having IN, OUT and IN/OUT ";
     cout << "parameters" << endl;
     Statement *stmt = con->createStatement
                       ("BEGIN demo_proc(:v1, :v2, :v3); END;");
     try {
         cout << "Executing the block :" << stmt->getSQL() << endl;
         stmt->setInt (1, 10);
         stmt->setMaxParamSize (2, 30);
         stmt->setString (2, "IN");
         stmt->registerOutParam (3, OCCISTRING, 30, "");
         int updateCount = stmt->executeUpdate ();
         cout << "Update Count:" << updateCount << endl;
         string c1 = stmt->getString (2);
         string c2 = stmt->getString (3);
         cout << "Printing the INOUT & OUT parameters:" << endl;
         cout << "Col2: " << c1 << endl;
         cout << "Col3: " << c2 << endl;
         con->terminateStatement (stmt);
         cout << "occiproc - done" << endl;
     }
     catch (SQLException ex) {
         cout << ex.getMessage() << endl;
     }
 } // end of callproc ()
Esempio n. 11
0
	int db_updatePlayerInfo(Connection *conn, const PlayerInfo *info)
	{
		std::string sql = "update g_user set ";
		sql.append("user_name='");
		sql.append(info->user_name);
		sql.append("',user_pwd='");
		sql.append(info->user_pwd);
		sql.append("',level=");
		sql.append(info->level + "");
		sql.append(",gender=");
		sql.append(info->gender + "");
		sql.append(",role_id=");
		sql.append(info->role_id + "");
		sql.append(",scene_id=");
		sql.append(info->scene_id + "");
		sql.append(",x=");
		sql.append(info->x + "");
		sql.append(",y=");
		sql.append(info->y + "");
		sql.append(" where user_id=");
		sql.append(info->user_id + "");

		int ret = 0;
		Statement *stmt = conn->createStatement();
		try
		{
			ret = stmt->executeUpdate(sql.c_str());
		}
		catch (sql::SQLException &e)
		{
			sLog.outError("[db_updatePlayerInfo] sql error :%s errorCode: %d", e.what(), e.getErrorCode());
		}
		delete stmt;
		return ret;
	}
Esempio n. 12
0
/**
 * Generate the new statistics and store in the database
 */
void StatController::GenerateNewStat()
{
	Statement* stmt = conn->createStatement();
	//Get the counts of users, sheets, feeds, items and comments and insert into the database
	stmt->executeUpdate("INSERT INTO stats (users, sheets, feeds, items, comments) VALUES ((SELECT count(*) FROM users), (SELECT count(*) FROM sheets), (SELECT count(*) FROM feeds), (SELECT count(*) FROM items), (SELECT count(*) FROM comments))");

	delete stmt;
}
Esempio n. 13
0
YK_ULLONG YKOracle::Insert(const YKString& sql)
{
	try {
		Statement* stmt = m_connection->createStatement(sql.ToString());
		if (stmt)
		{
			return (YK_ULLONG)stmt->executeUpdate();
		}
	} catch (SQLException& err) {
		YK_ExceptionThrow(YKDSException) << YKDSException::E_Update(GetErrorMessage(err));
	}

	return 0;
}
Esempio n. 14
0
int nuodb_execute(struct nuodb *db, const char *sql,
                  int64_t *rows_affected, int64_t *last_insert_id) {
    Statement *stmt = 0;
    try {
        stmt = db->conn->createStatement();
        stmt->executeUpdate(sql, RETURN_GENERATED_KEYS);
        int rc = fetchExecuteResult(db, stmt, rows_affected, last_insert_id);
        stmt->close();
        return rc;
    } catch (SQLException &e) {
        if (stmt) {
            stmt->close();
        }
        return setError(db, e);
    }
}
Esempio n. 15
0
  /**
   * Inserting a row into the table.
   */
  void insertRow ()
  {
    string sqlStmt = "INSERT INTO author_tab VALUES (111, 'ASHOK')";
    stmt = conn->createStatement (sqlStmt);
    try{
    stmt->executeUpdate ();
    cout << "insert - Success" << endl;
    }catch(SQLException ex)
    {
     cout<<"Exception thrown for insertRow"<<endl;
     cout<<"Error number: "<<  ex.getErrorCode() << endl;
     cout<<ex.getMessage() << endl;
    }

    conn->terminateStatement (stmt);
  }
Esempio n. 16
0
/***
 * get the balance of customer and get the passwd for charge
 */
int ChargeBusiness::CheckAndBalance(TopupInfo *topupInfo){
    int ret = 0;
    Statement *stmt = NULL;
    try{
        stmt = conn->createStatement(SQL_BALANCE_UPDATE);
        stmt->setAutoCommit(false);
        string tbOrderNo = topupInfo->qs_info.coopOrderNo;
        stmt->setString(1, topupInfo->qs_info.coopId);
        ResultSet *rs = stmt->executeQuery();
        double banlance = 0.0;
        bool has_result = false;
        while(rs->next())
        {
            banlance = rs->getDouble(2);
            has_result = true;
        }
        if(!has_result){
            errors.push_back(string("Exception:can't find customer info!"));
            ret = 2;        
        }
        if(topupInfo->qs_info.sum > banlance)
        {
            //余额不足
            ret =  1;
        }
        else
        {
            stmt = conn->createStatement(SQL_UPDATE_CUSTOMER_BALANCE);
            stmt->setAutoCommit(false);
            banlance = banlance - topupInfo->qs_info.sum;
            stmt->setDouble(1, banlance);
            stmt->setString(1, topupInfo->qs_info.coopId);
            stmt->executeUpdate();
        }
    }catch(SQLException &sqlExcp){
        HandleException(sqlExcp);
        ret = -1;
    }catch(std::exception &e){
        HandleException(e);
        ret = -1;
    }
    Finish();
    if(stmt)
        conn->terminateStatement(stmt);
    return ret;    
}
Esempio n. 17
0
  /**
   * Insertion of a row with dynamic binding, PreparedStatement functionality.
   */
  void insertBind (int c1, string c2)
  {
    string sqlStmt = "INSERT INTO author_tab VALUES (:x, :y)";
    stmt=conn->createStatement (sqlStmt);
    try{
    stmt->setInt (1, c1);
    stmt->setString (2, c2);
    stmt->executeUpdate ();
    cout << "insert - Success" << endl;
    }catch(SQLException ex)
    {
     cout<<"Exception thrown for insertBind"<<endl;
     cout<<"Error number: "<<  ex.getErrorCode() << endl;
     cout<<ex.getMessage() << endl;
    }

    conn->terminateStatement (stmt);
  }
Esempio n. 18
0
  /**
   * updating a row
   */
  void updateRow (int c1, string c2)
  {
    string sqlStmt = 
      "UPDATE author_tab SET author_name = :x WHERE author_id = :y";
    stmt = conn->createStatement (sqlStmt);
    try{
    stmt->setString (1, c2);
    stmt->setInt (2, c1);
    stmt->executeUpdate ();
    cout << "update - Success" << endl;
    }catch(SQLException ex)
    {
     cout<<"Exception thrown for updateRow"<<endl;
     cout<<"Error number: "<<  ex.getErrorCode() << endl;
     cout<<ex.getMessage() << endl;
    }

    conn->terminateStatement (stmt);
  }
Esempio n. 19
0
int main()
{
  cout << "***OCCI Globalization Support demo program.***" << endl;
  cout << "***This program loads Unicode data files into a NClob attribute***" << endl;

  char *unicodefiles[4] = {"occiuni2_hindi.txt", "occiuni2_russian.txt", "occiuni2_korean.txt",
                            "occiuni2_japanese.txt"};
  try
  {

     cout << "Initializing OCCI environment in Unicode mode" << endl;
     //initialize in Unicode(UTF16) mode
     Environment *utf16env = Environment::createEnvironment( "OCCIUTF16",
                        "OCCIUTF16", Environment::OBJECT );
     occiuni2m(utf16env);

     //"L" prefix will create a widechar i.e Unicode literal which is equivalent to
     // OCCI's UString datatype
     Connection *conn = utf16env->createConnection( L"hr",L"hr",L"" );

     //load the 4 sample Unicode files
     for (int i = 0; i < 4;i++)
     {
      //convert the filename argument to Unicode. We will be saving the filename
      //as one of the attributes of the object.
      const char *asciifilename = unicodefiles[i];
      wchar_t wcfilename[100];
      MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, (LPCSTR)asciifilename, 
                           strlen(asciifilename)+1, (LPWSTR)wcfilename, 100 );
      wstring docname(wcfilename);

      cout << "Loading " << asciifilename << endl;


      //Create a persistent object, set the NClob to empty and save
      //the object. Use the overloaded new operator that takes UString
      //arugments
      DocObjType *newdoc = new (conn, L"DOCUMENTSTAB",L"DOCOBJTYPE",
                                L"HR",L"HR") DocObjType();

      newdoc->setDocname(docname);

      //first insert a empty clob
      Clob doccontents(conn);
      doccontents.setEmpty();
      newdoc->setDoctext(doccontents);//empty 

      conn->commit();

      //Now, we will select the object again and add the document text
      //to the NClob attribute. 
      Statement *stmt = conn->createStatement(
      L"select ref(a) from documentstab a where docname = :1 for update");

      stmt->setUString(1, docname);//bind wstring
      ResultSet *rs = stmt->executeQuery();

      rs->next();//this will actually fetch the Ref

      Ref<DocObjType> docobjref = rs->getRef(1);
      DocObjType *docobj = docobjref.ptr();//pin the object

      doccontents = docobj->getDoctext();//get the Clob
      doccontents.open();

      doccontents.setCharSetId("OCCIUTF16");
      doccontents.setCharSetForm(OCCI_SQLCS_NCHAR);

      ifstream in( asciifilename, ios::binary );
      int bytesread=0, totalbytesread=0, wcharsread=0;
      wchar_t wbuffer1[50];//50 chars = 100 bytes at a time

      //we have stored the data in a Unicode text file. The first
      //character (2 bytes) is a Unicode Byte-Order-Mark and 
      //indicates whether the data in the file is little-endian or
      //big-endian
      in.read((char *)wbuffer1,2);//read & skip BOM
      int offset = 1;

      while (in.read( (char *)wbuffer1,sizeof(wbuffer1) ))
      {
        bytesread = in.gcount();
        wcharsread = bytesread/2;

        //write to the NClob
        doccontents.writeChunk( wcharsread, (utext *)wbuffer1, sizeof(wbuffer1), offset );

        offset += wcharsread;//offset is in terms of characters
        totalbytesread += bytesread;
      }
      //last chunk
      bytesread = in.gcount();
      wcharsread = bytesread/2;      
      totalbytesread += bytesread;

      doccontents.writeChunk( wcharsread, (utext *)wbuffer1, bytesread, offset );
      doccontents.close();

      //update the object and flush to database
      docobj->setDoctext(doccontents);
      docobj->markModified();
      docobj->flush();
      conn->commit();


      cout << totalbytesread/2 << " characters saved" << endl;

      //Statement & ResultSet objects will be created again
      stmt->closeResultSet(rs);
      conn->terminateStatement(stmt);
     }//for (i = 0; i < 4)


     cout << "Now reading the NClob data back and saving to new files" << endl;

     Statement *selectstmt = conn->createStatement(
     L"select ref(a) from DocumentsTab a" );
     ResultSet *queryrs = selectstmt->executeQuery();
     wstring wfilehdrtxt = L"If you cannot see the text properly, try setting your font to a Unicode font like : - Arial Unicode MS, Lucinda Sans Unicode etc...";
     while (queryrs->next())
     {
        Ref<DocObjType> docobjref = queryrs->getRef(1);

        wstring docname = docobjref->getDocname();

        //create the output file, prepend "fetch_" to the original filename
        docname = L"fetch_" + docname;
        char asciifilenamebuf[100];

        int ret = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)docname.c_str(),
                  docname.length()+1, (LPSTR)asciifilenamebuf, 100, NULL, NULL);

        cout << "Creating Unicode textfile " << asciifilenamebuf << endl;
        ofstream outdoc(asciifilenamebuf, ios_base::binary | ios_base::trunc);

        //first write the BOM
        wchar_t bom = 0xFEFF;//Windows is little-endian
        outdoc.write((char *)&bom, 2);

        outdoc.write((char *)wfilehdrtxt.c_str(), wfilehdrtxt.length()*2);

        Clob doccontents = docobjref->getDoctext();
        doccontents.setCharSetId("OCCIUTF16");
        doccontents.setCharSetForm(OCCI_SQLCS_NCHAR);
        int offset = 1;
        int clobcharsread=0;
        //now read the NClob and write to file
        wchar_t wbuffer2[100];//100 chars at a time
        while ( (clobcharsread = 
                 doccontents.read(100, wbuffer2, sizeof(wbuffer2), offset)) !=0 )
        {
            offset = offset+clobcharsread;
            outdoc.write((char *)wbuffer2,clobcharsread*2);//write takes number of bytes
        }
        outdoc.close();

      }//while (queryrs->next())

      //done
      cout << "You can view the created files in Notepad(or any other editor that displays Unicode)" << endl;
      selectstmt->closeResultSet(queryrs);
      conn->terminateStatement(selectstmt);

      //delete the rows from the table
      //if you want to retain the rows, comment out 
      cout << "Cleaning up table" << endl;
      Statement *deletestmt = conn->createStatement(
      L"delete from DocumentsTab");
      deletestmt->executeUpdate();

      conn->commit();

      utf16env->terminateConnection(conn);
      Environment::terminateEnvironment(utf16env);

      cout << "Done" << endl;

  }
  catch (SQLException &e)
  {
         std::cout << e.getErrorCode() << std::endl;
  }
  return 0;
}
Esempio n. 20
0
int main(int argc, char* argv[])
{
     
  try
    {
	FILE *op = fopen(argv[1], "r");
	google::InitGoogleLogging(argv[0]);
	LOG(INFO) << "hello glog";
        const string userName = "******";
        const string password = "******";
        const string connectString= "//117.121.26.19:1521/zkcl";
 
        unsigned int maxConn=10;
        unsigned int minConn=1;
        unsigned int incrConn=2;
 
        oracle::occi::Environment *env = oracle::occi::Environment::createEnvironment("ZHS16GBK","UTF8");
         
        //建立连接池
        ConnectionPool *connPool=env->createConnectionPool(
            userName,
            password,
            connectString,
            minConn,
            maxConn,
            incrConn);
 
        //从连接池获取连接
		char buf[2048];
		vector<char *> field_vec;
		Statement *stmt;
		Connection *conn=connPool->createConnection(userName,password);
		while(fgets(buf, 2047,op) != NULL){
			printf(buf);
			buf[strlen(buf) -1] = '\0';
			try{
				stmt = conn->createStatement(buf);
				stmt->executeUpdate();
				conn->commit();
			}catch (SQLException &Excp){
				string strinfo=Excp.getMessage();
				cout<<strinfo;
				conn->terminateStatement(stmt);
				continue;	
			}
			conn->terminateStatement(stmt);
		}
		connPool->terminateConnection(conn);
        env->terminateConnectionPool(connPool);
        //env->terminateConnection(conn);
        oracle::occi::Environment::terminateEnvironment(env);
    }
    catch (SQLException &sqlExcp)
    {
        int i=sqlExcp.getErrorCode();
        string strinfo=sqlExcp.getMessage();
        cout<<strinfo;
    }
     
  int i;
  return 0;
}
Esempio n. 21
0
int ChargeBusiness::CreateTmallOrder(TopupInfo *topupInfo, ChannelInfo &channelInfo){
    int ret = 0;
    Statement *stmt = NULL;
    try{
        stmt = conn->createStatement(SQL_CREATE_ORDER);
        stmt->setAutoCommit(false);
        stmt->setString(1, topupInfo->qs_info.customer);
        stmt->setString(2, topupInfo->qs_info.customer);
        stmt->setInt(3, topupInfo->qs_info.province);
        stmt->setInt(4, topupInfo->qs_info.value);
        uint64_t sysNo = encode_orderno(topupInfo->qs_info.customer);
        if(sysNo <= 0){
            conn->terminateStatement(stmt);
            return -2;
        }
        string systemNo = lexical_cast<string>(sysNo);
        topupInfo->qs_info.coopOrderNo = systemNo;
        stmt->setString(5, systemNo);
        stmt->setString(6, systemNo);
        stmt->setString(7, topupInfo->qs_info.tbOrderNo);
        //订单状态
        stmt->setInt(8, 1);
        string time_str;
        int len = get_time_now("%Y/%m/%d %H:%M:%S", time_str);
        if(len < 18){
            conn->terminateStatement(stmt);
            return -3;
        }
        stmt->setString(9, time_str);
        stmt->setString(10, time_str);
        //notify
        stmt->setInt(11, 0);
        //the source of order
        if(topupInfo->userid == "tmall"){
            stmt->setInt(12, 1);
        }else if(topupInfo->userid == "zkcl"){
            //the interface for internal recharge
            stmt->setInt(12, 2);
        }else if(topupInfo->userid == "ybtj"){
            //the interface for ybtj
            stmt->setInt(12, 3);
        }else{
            //customer interface
            //use source field record customer id,the id use for refund
            stmt->setInt(12, topupInfo->qs_info.coopId);
        }
        //operator
        stmt->setInt(13, topupInfo->qs_info.op);
        //price //TODO has question
        stmt->setFloat(14, topupInfo->qs_info.sum / topupInfo->qs_info.cardNum);
        int total_value = topupInfo->qs_info.value * topupInfo->qs_info.cardNum;
        //the sale price
        stmt->setFloat(15, total_value * channelInfo.discount);
        //the profit of this order
        stmt->setFloat(16,topupInfo->qs_info.sum - total_value * channelInfo.discount);
        //the channel used for charge up,this can be change when create order failed
        stmt->setInt(17, channelInfo.channelId);
        stmt->executeUpdate();
        string topup_data;
        //serialize the topup info
        serialize_topupinfo(topupInfo, topup_data);
        //push to underway queue
        shared_ptr<RedisClient> redis(new RedisClient());
        if(redis->connect(GlobalConfig::Instance()->s_redis_ip, GlobalConfig::Instance()->n_redis_port)){
            redis->select(1);
            if(!redis->setex(topupInfo->qs_info.tbOrderNo, topup_data, 3600)){
                 TP_WRITE_ERR(topupInfo, "#%d [CreateTmallOrder] setex %s failed\n", topupInfo->seqid, 
                         topupInfo->qs_info.tbOrderNo.c_str());
                 errors.push_back(string("Exception:cache order failed!"));
                 ret = -4;
            }
            if(!redis->enqueue("underway", topup_data.c_str())){
                TP_WRITE_ERR(topupInfo, "#%d [CreateTmallOrder] enqueue %s failed\n",
                        topupInfo->seqid, topupInfo->qs_info.tbOrderNo.c_str());
                errors.push_back(string("Exception:enqueue underway failed!"));
                ret = -5;
            }
            //internal order can't summit twice in 30 minutes, check phone and charge price
            if(topupInfo->userid == "zkcl"){
                char buf[256] = {0};
                sprintf(buf, "%s_%d", topupInfo->qs_info.customer.c_str(), topupInfo->qs_info.value);
                if(!redis->setex(buf, buf, 60 * 30)){
                    TP_WRITE_ERR(topupInfo, "#%d [CreateTmallOrder] record internat charge info failed %s\t%d\n",
                        topupInfo->seqid, topupInfo->qs_info.customer.c_str(), topupInfo->qs_info.value);
                    errors.push_back(string("REDIS Exception:record internat charge info failed!"));
                }
            }
        }else{
            TP_WRITE_ERR(topupInfo, "#%d [CreateTmallOrder] enqueue can't connect to redis %s:%d\n",
                    topupInfo->seqid, GlobalConfig::Instance()->s_redis_ip.c_str(), GlobalConfig::Instance()->n_redis_port);
            errors.push_back(string("Exception:enqueue can't connect to redis"));
            ret = -6;
        }
    }catch (SQLException &sqlExcp){
        HandleException(sqlExcp);
        ret = -1;
    }catch(std::exception &e){
        HandleException(e);
        ret = -1;
    }
    Finish();
    if(stmt)
        conn->terminateStatement(stmt);
    return ret;    
}