MCPcopy Index your code
hub / github.com/saltstack/salt / query

Function query

salt/modules/mysql.py:755–884  ·  view source on GitHub ↗

Run an arbitrary SQL query and return the results or the number of affected rows. CLI Example: .. code-block:: bash salt '*' mysql.query mydb "UPDATE mytable set myfield=1 limit 1" Return data: .. code-block:: python {'query time': {'human': '39.0ms', '

(database, query, **connection_args)

Source from the content-addressed store, hash-verified

753
754
755def query(database, query, **connection_args):
756 """
757 Run an arbitrary SQL query and return the results or
758 the number of affected rows.
759
760 CLI Example:
761
762 .. code-block:: bash
763
764 salt '*' mysql.query mydb "UPDATE mytable set myfield=1 limit 1"
765
766 Return data:
767
768 .. code-block:: python
769
770 {'query time': {'human': '39.0ms', 'raw': '0.03899'}, 'rows affected': 1L}
771
772 CLI Example:
773
774 .. code-block:: bash
775
776 salt '*' mysql.query mydb "SELECT id,name,cash from users limit 3"
777
778 Return data:
779
780 .. code-block:: python
781
782 {'columns': ('id', 'name', 'cash'),
783 'query time': {'human': '1.0ms', 'raw': '0.001'},
784 'results': ((1L, 'User 1', Decimal('110.000000')),
785 (2L, 'User 2', Decimal('215.636756')),
786 (3L, 'User 3', Decimal('0.040000'))),
787 'rows returned': 3L}
788
789 CLI Example:
790
791 .. code-block:: bash
792
793 salt '*' mysql.query mydb 'INSERT into users values (null,"user 4", 5)'
794
795 Return data:
796
797 .. code-block:: python
798
799 {'query time': {'human': '25.6ms', 'raw': '0.02563'}, 'rows affected': 1L}
800
801 CLI Example:
802
803 .. code-block:: bash
804
805 salt '*' mysql.query mydb 'DELETE from users where id = 4 limit 1'
806
807 Return data:
808
809 .. code-block:: python
810
811 {'query time': {'human': '39.0ms', 'raw': '0.03899'}, 'rows affected': 1L}
812

Callers 1

file_queryFunction · 0.70

Calls 10

cursorMethod · 0.80
timeMethod · 0.80
debugMethod · 0.80
formatMethod · 0.80
fetchallMethod · 0.80
_connectFunction · 0.70
_executeFunction · 0.70
getMethod · 0.45
updateMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected