Exemple #1
0
__int64 Decimal::getInt64() const
{
    unsigned __int64 value = getUInt64();
    if (negative)
        return -(__int64)value;
    return (__int64)value;
}
Exemple #2
0
document_attachment_ptr Document::getAttachment(const char* name, bool includeBody) {    
    document_attachment_ptr attachment;
    
    auto attachmentsObj = obj_->getObject("_attachments", false);
    if (!!attachmentsObj) {        
        auto attachmentObj = attachmentsObj->getObject(name, false);
        if (!!attachmentObj) {
            auto contentType = attachmentObj->getString("content_type");
            auto digest = attachmentObj->getString("digest");

            if (includeBody) {
                auto encodedData = attachmentObj->getString("data");
                auto encodedDataSize = attachmentObj->getStringLength("data");
                auto data = Base64Helper::Decode(encodedData, encodedDataSize);
                attachment = DocumentAttachment::Create(name, contentType, digest, std::move(data));
            } else {
                int lengthIndex = -1;
                auto size = attachmentObj->getType("length", lengthIndex) == rs::scriptobject::ScriptObjectType::UInt32 ? 
                    attachmentObj->getUInt32(lengthIndex) : attachmentObj->getUInt64(lengthIndex);

                attachment = DocumentAttachment::Create(name, contentType, digest, Base64Helper::buffer_type{}, size);
            }
        }
    }
    
    return attachment;
}
UInt64List* MtpDataPacket::getAUInt64() {
    UInt64List* result = new UInt64List;
    int count = getUInt32();
    for (int i = 0; i < count; i++)
        result->push_back(getUInt64());
    return result;
}
Exemple #4
0
bool create_guest_account_req(std::shared_ptr<cd_user> user, Json payload) {
  //static int guest_id = 100;
  std::random_device rd;
  std::mt19937 mt(rd());
  std::uniform_real_distribution<double> dist(1.0, 100000.0);
  auto rand_id = static_cast<long>(dist(mt));
  std::string name = "guest" + std::to_string(rand_id);
  std::string password = name;
  auto result = true;

  // query
  std::shared_ptr<MySQLConnection> conn = db_md::get().mysql_pool->borrow();

 try {
   std::unique_ptr<sql::Statement> stmt_ptr2(conn->sql_connection->createStatement());
   std::string query = "call join_guest_user('" +  name + "','" + password + "')";

   if(stmt_ptr2) {
     auto res_ptr = std::shared_ptr<sql::ResultSet>(stmt_ptr2->executeQuery(query));
     stmt_ptr2->getMoreResults();
     //auto res_ptr = std::shared_ptr<sql::ResultSet>(stmt_ptr2->execute(query));

     while(res_ptr->next()) {
       auto uid = res_ptr->getUInt64("uid");

       if(uid < 0) result = false;

       json11::Json res = json11::Json::object {
	 { "type", "create_guest_account_res" },
	 { "result", result },
	 { "uid", std::to_string(uid) },
	 { "name", name },
	 { "password", password }
       };
       user->send2(res);
     }
   }

   db_md::get().mysql_pool->unborrow(conn);
 } catch (sql::SQLException& e) {
   std::cout << "ec: " << e.getErrorCode() << std::endl;
   std::cout << "Invalid Argument: " << e.what() << std::endl;
   std::cout << "SQLState: " << e.getSQLState() << std::endl;
   json11::Json res = json11::Json::object {
     { "type", "create_guest_account_res" },
     { "result", false }
   };
   user->send2(res);
   db_md::get().mysql_pool->unborrow(conn);
 }

  return true;
}
Exemple #5
0
UInt64List* MtpDataPacket::getAUInt64() {
    uint32_t count;
    if (!getUInt32(count))
        return NULL;
    UInt64List* result = new UInt64List;
    for (uint32_t i = 0; i < count; i++) {
        uint64_t value;
        if (!getUInt64(value)) {
            delete result;
            return NULL;
        }
        result->push(value);
    }
    return result;
}
Exemple #6
0
int Hdf::compare(uint64_t v2) const {
  uint64_t v1 = getUInt64();
  if (v1 == v2) return 0;
  return v1 > v2 ? 1 : -1;
}
 /* {{{ MySQL_ArtResultSet::getUInt64() -I- */
 uint64_t
 MySQL_ArtResultSet::getUInt64(const sql::SQLString& columnLabel) const
 {
     CPP_ENTER("MySQL_ArtResultSet::getUInt64(string)");
     return getUInt64(findColumn(columnLabel));
 }
 /* {{{ MySQL_ArtResultSet::getUInt() -I- */
 uint32_t
 MySQL_ArtResultSet::getUInt(uint32_t columnIndex) const
 {
     CPP_ENTER("MySQL_ArtResultSet::getUInt(int)");
     return static_cast<uint32_t>(getUInt64(columnIndex));
 }