void UnitRepoProxy::getUnitLineTable(int repoId, int64_t unitSn, LineTable& lineTable) { RepoStmt stmt(m_repo); stmt.prepare( folly::format( "SELECT data FROM {} WHERE unitSn == @unitSn;", m_repo.table(repoId, "UnitLineTable") ).str()); RepoTxn txn(m_repo); RepoTxnQuery query(txn, stmt); query.bindInt64("@unitSn", unitSn); query.step(); if (query.row()) { BlobDecoder dataBlob = query.getBlob(0); dataBlob.decode(lineTable); } txn.commit(); }
void UnitRepoProxy::GetUnitArrayTypeTableStmt ::get(UnitEmitter& ue) { RepoTxn txn(m_repo); if (!prepared()) { std::stringstream ssSelect; ssSelect << "SELECT unitSn, arrayTypeTable FROM " << m_repo.table(m_repoId, "UnitArrayTypeTable") << " WHERE unitSn == @unitSn;"; txn.prepare(*this, ssSelect.str()); } RepoTxnQuery query(txn, *this); query.bindInt64("@unitSn", ue.m_sn); query.step(); assertx(query.row()); BlobDecoder dataBlob = query.getBlob(1); dataBlob(ue.m_arrayTypeTable); dataBlob.assertDone(); query.step(); assertx(query.done()); txn.commit(); }
void Repo::loadGlobalData(bool allowFailure /* = false */, bool readArrayTable /* = true */) { if (readArrayTable) m_lsrp.load(); if (!RuntimeOption::RepoAuthoritative) return; std::vector<std::string> failures; /* * This should probably just go to the Local repo always, except * that our unit test suite is currently running RepoAuthoritative * tests with the compiled repo as the Central repo. */ for (int repoId = RepoIdCount - 1; repoId >= 0; --repoId) { if (repoName(repoId).empty()) { // The repo wasn't loadable continue; } try { RepoStmt stmt(*this); const auto& tbl = table(repoId, "GlobalData"); stmt.prepare( folly::format( "SELECT count(*), data from {};", tbl ).str() ); RepoTxn txn(*this); RepoTxnQuery query(txn, stmt); query.step(); if (!query.row()) { throw RepoExc("Can't find table %s", tbl.c_str()); }; int val; query.getInt(0, val); if (val == 0) { throw RepoExc("No rows in %s. Did you forget to compile that file with " "this HHVM version?", tbl.c_str()); } BlobDecoder decoder = query.getBlob(1); decoder(s_globalData); if (readArrayTable) { auto& arrayTypeTable = globalArrayTypeTable(); decoder(arrayTypeTable); decoder(s_globalData.APCProfile); decoder(s_globalData.ConstantFunctions); decoder.assertDone(); } txn.commit(); } catch (RepoExc& e) { failures.push_back(repoName(repoId) + ": " + e.msg()); continue; } // TODO: this should probably read out the other elements of the global data // which control Option or RuntimeOption values -- the others are read out // in an inconsistent and ad-hoc manner. But I don't understand their uses // and interactions well enough to feel comfortable fixing now. RuntimeOption::EvalPromoteEmptyObject = s_globalData.PromoteEmptyObject; RuntimeOption::EnableIntrinsicsExtension = s_globalData.EnableIntrinsicsExtension; HHBBC::options.ElideAutoloadInvokes = s_globalData.ElideAutoloadInvokes; RuntimeOption::AutoprimeGenerators = s_globalData.AutoprimeGenerators; RuntimeOption::EnableHipHopSyntax = s_globalData.EnableHipHopSyntax; RuntimeOption::EvalHardTypeHints = s_globalData.HardTypeHints; RuntimeOption::EvalUseHHBBC = s_globalData.UsedHHBBC; RuntimeOption::PHP7_Builtins = s_globalData.PHP7_Builtins; RuntimeOption::PHP7_IntSemantics = s_globalData.PHP7_IntSemantics; RuntimeOption::PHP7_NoHexNumerics = s_globalData.PHP7_NoHexNumerics; RuntimeOption::PHP7_ScalarTypes = s_globalData.PHP7_ScalarTypes; RuntimeOption::PHP7_Substr = s_globalData.PHP7_Substr; RuntimeOption::EvalReffinessInvariance = s_globalData.ReffinessInvariance; RuntimeOption::EvalHackArrDVArrs = s_globalData.HackArrDVArrs; RuntimeOption::DisallowDynamicVarEnvFuncs = s_globalData.DisallowDynamicVarEnvFuncs; if (s_globalData.HardReturnTypeHints) { RuntimeOption::EvalCheckReturnTypeHints = 3; } if (s_globalData.ThisTypeHintLevel == 3) { RuntimeOption::EvalThisTypeHintLevel = s_globalData.ThisTypeHintLevel; } RuntimeOption::ConstantFunctions.clear(); for (auto const& elm : s_globalData.ConstantFunctions) { RuntimeOption::ConstantFunctions.insert(elm); } return; } if (allowFailure) return; if (failures.empty()) { std::fprintf(stderr, "No repo was loadable. Check all the possible repo " "locations (Repo.Central.Path, HHVM_REPO_CENTRAL_PATH, and " "$HOME/.hhvm.hhbc) to make sure one of them is a valid " "sqlite3 HHVM repo built with this exact HHVM version.\n"); } else { // We should always have a global data section in RepoAuthoritative // mode, or the repo is messed up. std::fprintf(stderr, "Failed to load Repo::GlobalData:\n"); for (auto& f : failures) { std::fprintf(stderr, " %s\n", f.c_str()); } } assertx(Process::IsInMainThread()); exit(1); }