bool table::is_column(const std::string& column_name, const std::type_info& type) const { assert(has_column(column_name)); const auto& c = m_columns.at(column_name); assert(c->type_hash()); return (*c->type_hash()) == type.hash_code(); }
void table::add_const_column(const std::string& column_name, const boost::any& value) { // You can't add a const column which already exists. assert(!has_column(column_name)); m_columns.insert( std::pair<std::string, column_ptr>(column_name, column_ptr(new const_column(value, m_rows)))); }
void table::set_default_value(const std::string& column_name, const boost::any& value) { // You must create the column before you set the default value assert(has_column(column_name)); // You cannot set the default value on a constant column assert(!is_constant(column_name)); auto& c = m_columns.at(column_name); c->set_default_value(value); assert(value.empty() || c->type_hash() == value.type().hash_code()); }
void table::set_value(const std::string& column_name, const boost::any& value) { // You can not insert a value without a row to put it in. assert(m_rows > 0); // You must create the column before you insert values assert(has_column(column_name)); // You cannot insert values into a constant column assert(!is_constant(column_name)); auto& c = m_columns.at(column_name); c->set_value(value); assert(value.empty() || c->type_hash() == value.type().hash_code()); }
std::vector<T> values_as(const std::string& column_name) const { assert(has_column(column_name)); assert(is_column<T>(column_name)); std::vector<T> values; const auto& column = m_columns.at(column_name); for (const auto& value : column->values()) { // You can't get the values of a column with empty values. assert(!value.empty()); values.push_back(boost::any_cast<T>(value)); } return values; }
void table::merge(const table& src) { // if two tables are merged, the const of a const_column no longer // applies. std::map<std::string, column_ptr> converted_columns; for(auto& my_kv : m_columns) { if(my_kv.second->is_constant()) { converted_columns.insert( std::pair<std::string, column_ptr>(my_kv.first, column_ptr(new nonconst_column(my_kv.second)))); } } for(auto& converted_column : converted_columns) { m_columns.erase(converted_column.first); m_columns.insert(std::pair<std::string, column_ptr>( converted_column.first, converted_column.second)); } for(uint32_t i = 0; i < src.rows(); ++i) { add_row(); for(const auto& kv : src.m_columns) { auto name = kv.first; if (!has_column(name)) add_column(name); auto column = kv.second; set_value(name, column->value(i)); } } }
bool read (int column, std::string &value) { bool readable = context && has_column (column) && !has_error (); if (readable) value = (const char *) sqlite3_column_text (context, column); return readable; }
bool read (int column, double &value) { bool readable = context && has_column (column) && !has_error (); if (readable) value = sqlite3_column_double (context, column); return readable; }
bool read (int column, uint64_t &value) { bool readable = context && has_column (column) && !has_error (); if (readable) value = sqlite3_column_int64 (context, column); return readable; }
void table::drop_column(const std::string& column_name) { assert(has_column(column_name)); m_columns.erase(column_name); }
uint32_t table::empty_rows(const std::string& column_name) const { assert(has_column(column_name)); return m_columns.at(column_name)->empty_rows(); }
bool table::is_constant(const std::string& column_name) const { assert(has_column(column_name)); return m_columns.at(column_name)->is_constant(); }
boost::any table::default_value(const std::string& column_name) const { assert(has_column(column_name)); return m_columns.at(column_name)->default_value(); }
std::vector<boost::any> table::values(const std::string& column_name) const { assert(has_column(column_name)); return m_columns.at(column_name)->values(); }
boost::any table::value(const std::string& column_name, uint32_t row_index) const { assert(has_column(column_name)); return m_columns.at(column_name)->value(row_index); }
bool HeapSnapshot::saveStackFrame(const protobuf::StackFrame& frame, StackFrameId& outFrameId) { if (frame.has_ref()) { // We should only get a reference to the previous frame if we have already // seen the previous frame. if (!frames.has(frame.ref())) return false; outFrameId = frame.ref(); return true; } // Incomplete message. if (!frame.has_data()) return false; auto data = frame.data(); if (!data.has_id()) return false; StackFrameId id = data.id(); // This should be the first and only time we see this frame. if (frames.has(id)) return false; Maybe<StackFrameId> parent; if (data.has_parent()) { StackFrameId parentId = 0; if (!saveStackFrame(data.parent(), parentId)) return false; parent = Some(parentId); } if (!data.has_line()) return false; uint32_t line = data.line(); if (!data.has_column()) return false; uint32_t column = data.column(); auto duplicatedSource = reinterpret_cast<const char16_t*>( data.source().data()); size_t sourceLength = data.source().length() / sizeof(char16_t); const char16_t* source = borrowUniqueString(duplicatedSource, sourceLength); if (!source) return false; const char16_t* functionDisplayName = nullptr; if (data.has_functiondisplayname() && data.functiondisplayname().length() > 0) { auto duplicatedName = reinterpret_cast<const char16_t*>( data.functiondisplayname().data()); size_t nameLength = data.functiondisplayname().length() / sizeof(char16_t); functionDisplayName = borrowUniqueString(duplicatedName, nameLength); if (!functionDisplayName) return false; } MOZ_ASSERT(!!functionDisplayName == (data.has_functiondisplayname() && data.functiondisplayname().length() > 0)); if (!data.has_issystem()) return false; bool isSystem = data.issystem(); if (!data.has_isselfhosted()) return false; bool isSelfHosted = data.isselfhosted(); if (!frames.putNew(id, DeserializedStackFrame(id, parent, line, column, source, functionDisplayName, isSystem, isSelfHosted, *this))) { return false; } outFrameId = id; return true; }
bool HeapSnapshot::saveStackFrame(const protobuf::StackFrame& frame, StackFrameId& outFrameId) { // NB: de-duplicated string properties must be read in the same order here as // they are written in `CoreDumpWriter::getProtobufStackFrame` or else indices // in references to already serialized strings will be off. if (frame.has_ref()) { // We should only get a reference to the previous frame if we have already // seen the previous frame. if (!frames.has(frame.ref())) return false; outFrameId = frame.ref(); return true; } // Incomplete message. if (!frame.has_data()) return false; auto data = frame.data(); if (!data.has_id()) return false; StackFrameId id = data.id(); // This should be the first and only time we see this frame. if (frames.has(id)) return false; if (!data.has_line()) return false; uint32_t line = data.line(); if (!data.has_column()) return false; uint32_t column = data.column(); if (!data.has_issystem()) return false; bool isSystem = data.issystem(); if (!data.has_isselfhosted()) return false; bool isSelfHosted = data.isselfhosted(); Maybe<StringOrRef> sourceOrRef = GET_STRING_OR_REF(data, source); auto source = getOrInternString<char16_t>(internedTwoByteStrings, sourceOrRef); if (!source) return false; const char16_t* functionDisplayName = nullptr; if (data.FunctionDisplayNameOrRef_case() != protobuf::StackFrame_Data::FUNCTIONDISPLAYNAMEORREF_NOT_SET) { Maybe<StringOrRef> nameOrRef = GET_STRING_OR_REF(data, functiondisplayname); functionDisplayName = getOrInternString<char16_t>(internedTwoByteStrings, nameOrRef); if (!functionDisplayName) return false; } Maybe<StackFrameId> parent; if (data.has_parent()) { StackFrameId parentId = 0; if (!saveStackFrame(data.parent(), parentId)) return false; parent = Some(parentId); } if (!frames.putNew(id, DeserializedStackFrame(id, parent, line, column, source, functionDisplayName, isSystem, isSelfHosted, *this))) { return false; } outFrameId = id; return true; }
void table::add_column(const std::string& column_name) { assert(!has_column(column_name)); m_columns.insert(std::pair<std::string, column_ptr>( column_name, column_ptr(new nonconst_column(m_rows)))); }