MySqlSelect

Execute a MySQL SELECT Statement.

Added in version 1.0.0.

  • Friendly name: MySQL Select

  • Step class: base_steps_syncpack.steps.MySqlSelect.MySqlSelect

  • Step version: 1.1.3

  • Required parameters: database, host, username, password, port

Parameters

Name

Type

Required

Default

Description

table

string

no

–

The database Table Example: Users

database

string

yes

–

The database Example: database1

host

string

yes

–

The host of the database Example: host1

username

string

yes

–

The db username Example: ${db_user_name}

password

string

yes

–

The db password Example: ${db_password}

select_query

string (long)

no

–

A full SELECT statement. Overrides the ‘fields’ statement. Example: SELECT COUNT(*) FROM XYZ

fields

array of strings

no

*

Which fields to select. Example: ['field1', 'field2']

port

number

yes

7706

The port number to use when establishing a connection to the remote mysql server.

Every step also accepts the platform parameters common to all steps – see Platform parameters.

Dependencies

  • Inherits from: MySqlSelect -> BaseStep -> Serializable

  • SyncPack modules: base_steps_syncpack.util

  • External packages: ipaascommon, ipaascore

Behaviour

Connects through util.mysql_utils.util_connect_mysql (pymysql, DictCursor) and runs a SELECT. The query is resolved in this order:

  1. select_query, used verbatim;

  2. SELECT * FROM {table} when fields is left at its default;

  3. SELECT {fields} FROM {table}.

Either table or select_query is required.

Outputs

A list of row dicts — List[Dict[column, value]], courtesy of DictCursor — or [] when the query matches nothing:

[
  {"device_id": 4021, "name": "web-01"},
  {"device_id": 4022, "name": "web-02"}
]

Example

{
  "host": "db.example.com",
  "port": 7706,
  "database": "master_dev",
  "username": "svc_pf",
  "password": "${config.db_password}",
  "select_query": "SELECT id, device FROM legend_device WHERE date_edit > NOW() - INTERVAL 1 DAY"
}

Notes

  • port defaults to 7706, the SL1 MySQL port, not 3306.

  • No row limit is applied. A large table comes back in one list and in one step-runner process — page it in the SQL if that matters.

  • An empty result is [], not an error, so a downstream step must handle it.