# Querying Data

### Executing Query

The [Lyftrondata](https://www.lyftrondata.com/) driver for [Pipedrive](https://github.com/Lyftrondata/GitBook/blob/SalesAnalytics/sales-analytics/pipedrive/driver-framework/None/README.md) provides query maker functionality for querying data. To execute SQL statements that return data, use the cursor object's execute method. Once a query is executed, the result set is fetched from the API. This result set is converted into the relational format and returned which can then be printed out.

```shell
import Lyftrondata.MyConnector.lib.Lyftrondata_MyConnector_Connector as con
lyft = con.Connect("My Lyftrondata license key")
init = lyft.initialise(username="my username",password="my password")
df = lyft.execute_query("Select * from my table")
print(df)  //my pandas dataframe
```

### Querying with where clause

We can filter our data directly from the API by providing a where clause for the table.

```shell
import Lyftrondata.MyConnector.lib.Lyftrondata_MyConnector_Connector as con
lyft = con.Connect("My Lyftrondata license key")
init = lyft.initialise(username="my username",password="my password")
df = lyft.execute_query("Select * from my table where id=3")
print(df)  //my pandas dataframe
```

### Querying Sys & Data Tables

The connector possesses system table definition that provides information about the connector framework metadata, and data tables that are used to discover the connector business information in the \[ERD Data Model]\(../../../Sales Analytics/pipedrive/data-model/erd.md).

```shell
import Lyftrondata.MyConnector.lib.Lyftrondata_MyConnector_Connector as con
lyft = con.Connect("My Lyftrondata license key")
init = lyft.initialise(username="my username",password="my password")
df = lyft.execute_query("Select * from my sys.tables")
print(df)  //my pandas dataframe
```

### Querying Sys Views

The connector possesses views definition that provides information about how these views are used to discover the connector business information in the \[ERD Data Model]\(../../../Sales Analytics/pipedrive/data-model/erd.md).

```shell
import Lyftrondata.MyConnector.lib.Lyftrondata_MyConnector_Connector as con
lyft = con.Connect("My Lyftrondata license key")
init = lyft.initialise(username="my username",password="my password")
df = lyft.execute_query("Select * from my sys.views")
print(df)  //my pandas dataframe
```

### Usage Logging

You will simply need to set two connection properties to begin capturing provider logging.

* For the usage logging you have to execute a query "select \* from sys.usage", which will return all the usage of the connector from the beginning.
* It shows how much time left, time spent and total allotted time of the connector.

You can also access the timestamp.txt from the current driver directory which contains information, such as when authentication is performed or queries are executed. The specified file will be created by the driver in your working directory.

```shell
import Lyftrondata.MyConnector.lib.Lyftrondata_MyConnector_Connector as con
lyft = con.Connect("My Lyftrondata license key")
init = lyft.initialise(username="my username",password="my password")
df = lyft.execute_query("Select * from my sys.usage")
print(df)  //my pandas dataframe
```

### Quickstart Steps

Do you have questions about how to use the platform? Don't worry; we've got you covered. Simply follow the quickstart instructions [here](https://docs.lyftrondata.com/sales-analytics/readme/pipedrive/driver-framework).

### Questions? <a href="#questions" id="questions"></a>

We're always happy to answer any additional questions you may have! [Set up a meeting with our data experts.](https://www.lyftrondata.com/book-a-meeting/)


---

# 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://docs.lyftrondata.com/sales-analytics/readme/pipedrive/driver-framework/querying-data.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.
