# get\_values\_from\_table

## Function: `get_values_from_table`

The `get_values_from_table` function retrieves all records (rows) stored in memory for a specified table. These records are returned as a vector of key-value pairs, where the keys represent column names and the values are stored using `std::any`.

{% hint style="info" %}
WARNING: use the load\_table function before getting the values from the table as that function loads into memory all the values, without running this function the vector will be empty
{% endhint %}

***

### Declaration

```cpp
std::vector<std::unordered_map<std::string, std::any>>* get_values_from_table(std::string table);
```

### Parameters

* `table` (`std::string`) The name of the table from which values should be retrieved. The table must already exist and be loaded in memory.

### Return Value

* `std::vector<std::unordered_map<std::string, std::any>>*` A pointer to the in-memory vector containing all records for the specified table:
  * Each element in the vector represents a single record (or row).
  * Each record is a map where:
    * The key is the column name.
    * The value is the data stored in that column, wrapped in `std::any`.

### Functionality

1. **Database Validation** The function does not explicitly validate whether the database is open or whether the table exists. It directly accesses the `tables` attribute of the `data_base` class, relying on the integrity of this map.
2. **Access Records in Memory** It retrieves the vector of records associated with the specified table from the `tables` map.
3. **Pointer Return** The function returns a pointer to the in-memory vector, allowing efficient access to the data for further processing.

### Example

Here’s an example demonstrating how to use the `get_values_from_table` function:

```cpp
#include "qic.h"
#include <iostream>
#include <unordered_map>

int main() {
  data_base db;
  db.open_database("mydatabase.db");
  db.load_table("COMPANY"); // loads the table in memory

  auto table =
      db.get_values_from_table("COMPANY"); // if we run this function without
                                           // the load table function before it
                                           // wont have all the tables in memory
  table->clear(); // by clearing this list and saving the db we can clear the
                  // table

  db.save();
  std::cin >> new char;
  db.close();
  return 0;
}

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hrodebert.gitbook.io/qic-database-ver-1.0.0/database/data_base/get_values_from_table.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
