int Call::DBwrite(Connection *sqlCon) { if (!sqlCon || !id) return -1; PreparedStatement *pstmt = sqlCon->prepareStatement( "UPDATE calls SET phone=(?), client=(?), translator=(?), client_country=(?), translator_country=(?), lang=(?), price=(?), start_time=(?), accounted=(?), cost=(?), error=(?) WHERE id=(?)"); pstmt->setInt(2, client); pstmt->setInt(3, translator); pstmt->setInt(1, false); pstmt->setString(4, COUNTRY_UNKNOWN); pstmt->setString(5, COUNTRY_UNKNOWN); pstmt->setString(6, translateLang.c_str()); pstmt->setInt(7, price); char *time = asctime(localtime(&start_time)); if (start_time) pstmt->setDateTime(8, time); else pstmt->setNull(8, 0); pstmt->setInt(9, accounted); pstmt->setInt(10, cost); pstmt->setInt(11, getState() == ERROR); pstmt->setInt(12, id); int ret; try { ret = pstmt->executeUpdate(); } catch (SQLException &ex) { log(LOG_ERROR, "[%s] MySQL error(%d): %s", __func__, ex.getErrorCode(), ex.what()); delete pstmt; return 0; } delete pstmt; return ret == 1; }
int PhoneCall::DBwrite(Connection *sqlCon) { if (!sqlCon || !id) return -1; PreparedStatement *pstmt = sqlCon->prepareStatement( "UPDATE calls SET phone=(?), client=(?), translator=(?), client_country=(?), translator_country=(?), lang=(?), price=(?), start_time=(?), accounted=(?), cost=(?), error=(?), request_time=(?), confirm_time=(?), accepted=(?) WHERE id=(?)"); pstmt->setInt(1, true); pstmt->setInt(2, client); pstmt->setInt(3, translator); pstmt->setString(4, ((PhoneCall *)this)->getClientCountry().c_str()); pstmt->setString(5, ((PhoneCall *)this)->getTranslatorCountry().c_str()); pstmt->setString(6, translateLang.c_str()); pstmt->setInt(7, price); char time[512]; strftime(time, 512, SQLTIME_FMT, localtime(&start_time)); if (start_time) pstmt->setDateTime(8, time); else pstmt->setNull(8, 0); pstmt->setInt(9, getAccountedTime()); pstmt->setInt(10, cost); pstmt->setInt(11, getState() == ERROR); strftime(time, 512, SQLTIME_FMT, localtime(&request_time)); if (request_time) pstmt->setString(12, time); else pstmt->setNull(12, 0); strftime(time, 512, SQLTIME_FMT, localtime(&confirm_time)); if (confirm_time) pstmt->setDateTime(13, time); else pstmt->setNull(13, 0); pstmt->setBoolean(14, accepted); pstmt->setInt(15, id); int ret; try { ret = pstmt->executeUpdate(); } catch (SQLException &ex) { log(LOG_ERROR, "[%s] MySQL error(%d): %s", __func__, ex.getErrorCode(), ex.what()); delete pstmt; return 0; } delete pstmt; return ret == 1; }
int nuodb_statement_bind(struct nuodb *db, struct nuodb_statement *st, struct nuodb_value parameters[]) { PreparedStatement *stmt = reinterpret_cast<PreparedStatement *>(st); try { int parameterCount = stmt->getParameterMetaData()->getParameterCount(); for (int i=0; i < parameterCount; ++i) { int parameterIndex = i+1; switch (parameters[i].vt) { case NUODB_TYPE_NULL: stmt->setNull(parameterIndex, NUOSQL_NULL); break; case NUODB_TYPE_INT64: stmt->setLong(parameterIndex, parameters[i].i64); break; case NUODB_TYPE_FLOAT64: { union { int64_t i64; double float64; } value = { parameters[i].i64 }; stmt->setDouble(parameterIndex, value.float64); break; } case NUODB_TYPE_BOOL: stmt->setBoolean(parameterIndex, !!parameters[i].i64); break; case NUODB_TYPE_STRING: { size_t length = parameters[i].i32; const char *s = reinterpret_cast<const char*>(parameters[i].i64); // Extra conversion due to missing length param in the setString API const std::string str(s, length); stmt->setString(parameterIndex, str.c_str()); break; } case NUODB_TYPE_BYTES: { int length = parameters[i].i32; const unsigned char *bytes = reinterpret_cast<const unsigned char*>(parameters[i].i64); stmt->setBytes(parameterIndex, length, bytes); break; } case NUODB_TYPE_TIME: { int64_t seconds = parameters[i].i64; int32_t nanos = parameters[i].i32; SqlTimestamp ts(seconds, nanos); stmt->setTimestamp(parameterIndex, &ts); break; } } } return 0; } catch (SQLException &e) { return setError(db, e); } }
AccountOpResult Battlenet::AccountMgr::UnlinkGameAccount(std::string const& gameAccountName) { uint32 gameAccountId = GameAccountMgr::GetId(gameAccountName); if (!gameAccountId) return AccountOpResult::AOR_NAME_NOT_EXIST; if (!GetIdByGameAccount(gameAccountId)) return AccountOpResult::AOR_ACCOUNT_BAD_LINK; PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_BNET_GAME_ACCOUNT_LINK); stmt->setNull(0); stmt->setNull(1); stmt->setUInt32(2, gameAccountId); LoginDatabase.Execute(stmt); return AccountOpResult::AOR_OK; }
AccountOpResult AccountMgr::CreateAccount(std::string username, std::string password, std::string email /*= ""*/, uint32 bnetAccountId /*= 0*/, uint8 bnetIndex /*= 0*/) { if (utf8length(username) > MAX_ACCOUNT_STR) return AccountOpResult::AOR_NAME_TOO_LONG; // username's too long if (utf8length(password) > MAX_PASS_STR) return AccountOpResult::AOR_PASS_TOO_LONG; // password's too long Utf8ToUpperOnlyLatin(username); Utf8ToUpperOnlyLatin(password); Utf8ToUpperOnlyLatin(email); if (GetId(username)) return AccountOpResult::AOR_NAME_ALREADY_EXIST; // username does already exist PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT); stmt->setString(0, username); stmt->setString(1, CalculateShaPassHash(username, password)); stmt->setString(2, email); stmt->setString(3, email); if (bnetAccountId && bnetIndex) { stmt->setUInt32(4, bnetAccountId); stmt->setUInt8(5, bnetIndex); } else { stmt->setNull(4); stmt->setNull(5); } LoginDatabase.DirectExecute(stmt); // Enforce saving, otherwise AddGroup can fail stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_REALM_CHARACTERS_INIT); LoginDatabase.Execute(stmt); return AccountOpResult::AOR_OK; // everything's fine }