ibmi_sql_execute – Executes a SQL non-DQL(Data Query Language) statement
Synopsis
The
ibmi_sql_execute
module takes the SQL non-DQL(Data Query Language) statement as argument.
Parameters
- become_user
The name of the user profile that the IBM i task will run under.
Use this option to set a user with desired privileges to run the task.
required: falsetype: str- become_user_password
Use this option to set the password of the user specified in
become_user
.required: falsetype: str- database
Specified database name, usually, its the iasp name, use WRKRDBDIRE to check Relational Database Directory Entries
Default to use the
*LOCAL
entryrequired: falsetype: strdefault: *SYSBAS- joblog
If set to
true
, output the JOBLOG even success.required: falsetype: bool- sql
The
ibmi_sql_execute
module takes a IBM i SQL non-DQL(Data Query Language) statement to run.required: Truetype: str
Examples
- name: Insert one record to table Persons
ibm.power_ibmi.ibmi_sql_execute:
sql: "INSERT INTO Persons VALUES('919665', 'Le', 'Chang', 'Ring Building', 'Beijing')"
become_user: 'USER1'
become_user_password: 'yourpassword'
Notes
Note
This module can only run one SQL statement at a time.
See Also
Return Values
- start
The sql statement execution start time.returned: alwaystype: strsample: 2019-12-02 11:07:53.757435- end
The sql statement execution end time.returned: alwaystype: strsample: 2019-12-02 11:07:54.064969- delta
The sql statement execution delta time.returned: alwaystype: strsample: 0:00:00.307534- stdout
The sql statement standard output.returned: alwaystype: strsample: +++ success INSERT INTO Persons VALUES(‘919665’, ‘Le’, ‘Chang’, ‘Ring Building’, ‘Beijing’)- stderr
The sql statement standard error.returned: alwaystype: str- sql
The sql statement executed by the task.returned: alwaystype: strsample: INSERT INTO Persons VALUES(‘919665’, ‘Le’, ‘Chang’, ‘Ring Building’, ‘Beijing’)- rc
The sql statement return code (0 means success, non-zero means failure).returned: alwaystype: int- stdout_lines
The sql statement standard output split in lines.returned: When rc as non-zero(failure)type: listsample:["+++ success INSERT INTO Persons VALUES(\u0027919665\u0027, \u0027Le\u0027, \u0027Chang\u0027, \u0027Ring Building\u0027, \u0027Beijing\u0027)"]- stderr_lines
The sql statement standard error split in lines.returned: When rc as non-zero(failure)type: listsample:[""]- job_log
The IBM i job log of the task executed.returned: when rc as non-zero(failure) or rc as success(0) but joblog set to true.type: listsample:[{"FROM_INSTRUCTION": "318F", "FROM_LIBRARY": "QSYS", "FROM_MODULE": "", "FROM_PROCEDURE": "", "FROM_PROGRAM": "QWTCHGJB", "FROM_USER": "CHANGLE", "MESSAGE_FILE": "QCPFMSG", "MESSAGE_ID": "CPD0912", "MESSAGE_LIBRARY": "QSYS", "MESSAGE_SECOND_LEVEL_TEXT": "Cause . . . . . : This message is used by application programs as a general escape message.", "MESSAGE_SUBTYPE": "", "MESSAGE_TEXT": "Printer device PRT01 not found.", "MESSAGE_TIMESTAMP": "2020-05-20-21.41.40.845897", "MESSAGE_TYPE": "DIAGNOSTIC", "ORDINAL_POSITION": "5", "SEVERITY": "20", "TO_INSTRUCTION": "9369", "TO_LIBRARY": "QSYS", "TO_MODULE": "QSQSRVR", "TO_PROCEDURE": "QSQSRVR", "TO_PROGRAM": "QSQSRVR"}]- job_name
The QSQSRVR job information which the SQL statement executed.returned: alwaystype: strsample: 188624/QUSER/QSQSRVR