Connections

A Connection in SQLPad is a configuration to a specific database instance. Business Intelligence and reporting software may call these “data sources”. A connection may involve a connection string, user credentials, host, port, etc. The data required by a connection depends on the database driver it uses to connect to the target database.

When a user write’s a query, they’ll pick a connection to use to run it. This connection choice will also be saved with the query.

Admins can create connections in the UI, but connections can also be created via environment variables or experimental seed data files.

Multi-Statement Transaction Support

Important: When using Multi-Statement transactions SQLPad becomes a stateful service. HTTP API calls must consistently resolve to same SQLPad instance using sticky sessions or similar.

Multi-statement transaction support adds the ability for a user to use the same underlying connection across query executions. This allows things like opening a transaction, running queries, and rolling the transaction back or committing the transaction across query runs. It also opens up the ability to create and use temp tables that are generally scoped per connection session.

Multi-statement transaction support is opt-in based on connection configuration. If a connection uses a driver and multi-statement transaction support is not enabled, the connection falls back to the legacy SQLPad behavior of opening a new connection for each query execution, then immediately closing it following the query.

Work is under way to add multi-statement transaction support to drivers that benefit from the addition. At this time MySQL, SQLite, Postgres, and ODBC drivers support this approach.

Defining Connections via Configuration

When defining connections via environment variables, connection field values must be provided using an environment variable with the convention SQLPAD_CONNECTIONS__<connectionId>__<fieldName>. Note double underscores between SQLPAD_CONNECTIONS, <connectionId>, and <fieldName>.

Fields and values are case sensitive.

The connection ID value used can be any alphanumeric value. This can be a randomly generated value like SQLPad’s underlying embedded database uses, or it can be a more human-friendly name, or an id used from another source.

The fieldName referenced in the environment variable should correspond with a field key noted in the table below for the driver used.

Boolean values should be the value true or false.

Every connection defined should provide a name and driver value, with driver equaling the value specified in the driver rows below. name will be the label used in the UI to label the connection.

Example for a MySQL connection with id prod123.

SQLPAD_CONNECTIONS__prod123__name="Production 123"
SQLPAD_CONNECTIONS__prod123__driver=mysql
SQLPAD_CONNECTIONS__prod123__host=localhost
SQLPAD_CONNECTIONS__prod123__mysqlInsecureAuth=true

Connection selection

A default connection selection can be set using environment variable SQLPAD_DEFAULT_CONNECTION_ID. It can also be specified as part of the query editor URL, i.e., https://mysqlpad.example.com/queries/new?connectionName=connection1 or https://mysqlpad.example.com/queries/new?connectionId=xxx-xxxxx-xxx-xxx.

CrateDB

keydescriptiondata type
nameName of connectiontext
driverMust be cratetext
hostHost/Server/IP Addresstext
portPort (optional)text
usernameDatabase Usernametext
passwordDatabase Passwordtext
sslUse SSLboolean

Apache Drill

keydescriptiondata type
nameName of connectiontext
driverMust be drilltext
hostHost/Server/IP Addresstext
portPort (optional)text
usernameDatabase Usernametext
passwordDatabase Passwordtext
drillDefaultSchemaDefault Schematext
sslUse SSL to connect to Drillboolean

Apache Pinot

keydescriptiondata type
nameName of connectiontext
driverMust be pinottext
controllerUrlURL containing protocol, host, and port of Pinot contollertext

ClickHouse

keydescriptiondata type
nameName of connectiontext
driverMust be clickhousetext
hostHost/Server/IP Addresstext
portHTTP Port (optional)text
usernameUsername (optional)text
passwordPassword (optional)text
databaseDatabase Name (optional)text

SAP Hana (hdb)

keydescriptiondata type
nameName of connectiontext
driverMust be hdbtext
hostHost/Server/IP Addresstext
hanaportPort (e.g. 39015)text
usernameDatabase Usernametext
passwordDatabase Passwordtext
hanadatabaseTenanttext
hanaSchemaSchema (optional)text

MySQL

keydescriptiondata type
nameName of connectiontext
driverMust be mysqltext
multiStatementTransactionEnabledReuse db connection across query executionsboolean
hostHost/Server/IP Addresstext
portPort (optional)text
databaseDatabasetext
usernameDatabase Usernametext
passwordDatabase Passwordtext
mysqlSslUse SSLboolean
mysqlInsecureAuthUse old/insecure pre 4.1 Auth Systemboolean

MySQL2

keydescriptiondata type
nameName of connectiontext
driverMust be mysql2text
hostHost/Server/IP Addresstext
portPort (optional)text
databaseDatabasetext
usernameDatabase Usernametext
passwordDatabase Passwordtext
mysqlInsecureAuthUse old/insecure pre 4.1 Auth Systemboolean
minTlsVersionMinimum TLS version to allow. One of: TLSv1.3, TLSv1.2, TLSv1.1, or TLSv1.text
maxTlsVersionMaximum TLS version to allow. see above for optionstext
mysqlSkipValidateServerCertDo not validate servier certificate. (Don’t use this for production)boolean

PostgreSQL (postgres)

keydescriptiondata type
nameName of connectiontext
driverMust be postgrestext
multiStatementTransactionEnabledReuse db connection across query executionsboolean
idleTimeoutSecondsSeconds to allow connection to be idle before closingnumber
queryTimeoutSeconds to allow any query to run before cancellingnumber
hostHost/Server/IP Addresstext
portPort (optional)text
databaseDatabasetext
usernameDatabase Usernametext
passwordDatabase Passwordtext
postgresSslUse SSLboolean
postgresSslSelfSignedAllow self-signed SSL certificateboolean
postgresCertDatabase Certificate Pathtext
postgresKeyDatabase Key Pathtext
postgresCADatabase CA Pathtext
useSocksConnect through SOCKS proxyboolean
socksHostProxy hostnametext
socksPortProxy porttext
socksUsernameUsername for socks proxytext
socksPasswordPassword for socks proxytext

PrestoDB

keydescriptiondata type
nameName of connectiontext
driverMust be prestotext
hostHost/Server/IP Addresstext
portPort (optional)text
usernameDatabase Usernametext
prestoCatalogCatalogtext
prestoSchemaSchematext

Redshift

Redshift uses the Postgres driver, using a different query for pulling schema.

keydescriptiondata type
nameName of connectiontext
driverMust be redshifttext
multiStatementTransactionEnabledReuse db connection across query executionsboolean
idleTimeoutSecondsSeconds to allow connection to be idle before closingnumber
hostHost/Server/IP Addresstext
portPort (optional)text
databaseDatabasetext
usernameDatabase Usernametext
passwordDatabase Passwordtext
sslUse SSLboolean
certPathDatabase Certificate Pathtext
keyPathDatabase Key Pathtext
caPathDatabase CA Pathtext

SQL Server

keydescriptiondata type
nameName of connectiontext
driverMust be sqlservertext
hostHost/Server/IP Addresstext
portPort (optional)text
databaseDatabasetext
usernameDatabase Usernametext
passwordDatabase Passwordtext
domainDomaintext
sqlserverEncryptEncrypt (necessary for Azure)boolean
sqlserverMultiSubnetFailoverMultiSubnetFailoverboolean
trustServerCertificateTrust Server Certificateboolean
readOnlyIntentReadOnly Application Intentboolean

Trino

keydescriptiondata type
nameName of connectiontext
driverMust be trinotext
hostHost/Server/IP Addresstext
portPort (optional)text
usernameDatabase Usernametext
catalogCatalogtext
schemaSchematext

Vertica

keydescriptiondata type
nameName of connectiontext
driverMust be verticatext
hostHost/Server/IP Addresstext
portPort (optional)text
databaseDatabasetext
usernameDatabase Usernametext
passwordDatabase Passwordtext

Cassandra

keydescriptiondata type
nameName of connectiontext
driverMust be cassandratext
contactPointsContact points (comma delimited)text
localDataCenterLocal data centertext
keyspaceKeyspacetext

BigQuery

keydescriptiondata type
nameName of connectiontext
driverMust be bigquerytext
projectIdProject IDtext
keyFileJSON keyfile for service accounttext
datasetNameDataset to usetext
datasetLocationLocation for this datasettext

SQLite

keydescriptiondata type
nameName of connectiontext
driverMust be sqlitetext
multiStatementTransactionEnabledReuse db connection across query executionsboolean
idleTimeoutSecondsSeconds to allow connection to be idle before closingnumber
filenamePath to filetext
readonlyOpen file in read only modeboolean

Athena

keydescriptiondata type
nameName of connectiontext
driverMust be athenatext
awsRegionAWS Regiontext
awsAccessKeyIdAWS Access Key IDtext
awsSecretAccessKeyAWS Secret Access Keytext
athenaStagingDirectoryAthena staging directory in S3text
athenaWorkgroupAthena workgroup (`primary’ by default)text

ODBC (unixodbc)

?> Despite the underlying driver being unixodbc, this appears to be functional on Windows.

The ODBC driver by default use the following SQL to try and obtain schema information for the database connected. This may not work for your target database however.

If information schema is not supported by your target database, you may override this query using the schema_sql key.

This query is used for the schema sidebar and autocomplete purposes, and is not required to be able to run queries against the target database.

SELECT
  c.table_schema AS table_schema,
  c.table_name AS table_name,
  c.column_name AS column_name,
  c.data_type AS data_type
FROM
  INFORMATION_SCHEMA.columns c
WHERE
  c.table_schema NOT IN ('INFORMATION_SCHEMA', 'information_schema')
ORDER BY
  c.table_schema,
  c.table_name,
  c.ordinal_position
keydescriptiondata type
nameName of connectiontext
driverMust be unixodbctext
multiStatementTransactionEnabledReuse db connection across query executionsboolean
idleTimeoutSecondsSeconds to allow connection to be idle before closingnumber
connection_stringODBC connection stringtext
schema_sqlDatabase SQL to lookup schema (optional, if omitted default to checking INFORMATION_SCHEMA)text
usernameUsername (optional). Will be added to connect_string as Uid keytext
passwordPassword (optional). Will be added to connect_string as Pwd keytext
limit_strategiesComma separated list of limit strategies used to restrict queries. These strategies will be used to enforce and inject LIMIT and FETCH FIRST use in SELECT queries. Allowed strategies are limit, fetch, first, and top.

Example: limit, fetch
text