
                         J   S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  SS	KJr  SS
KJr  SrSr\\S.r\	R&                  " \	R(                  R*                  \	R(                  R,                  5      \	R.                   " S S\	R0                  5      5       5       rg)-Executes a statement on a Cloud SQL instance.    )absolute_import)division)unicode_literals)api_util)validate)base)flags)
properties)filesa      Executes a statement on a Cloud SQL instance. It will use the
    credentials of the specified Google Cloud account to connect to the
    instance, so an IAM user with the same name must exist in the instance.
    It doesn't support DQL or DML statements yet.
    WARNING: The requests and responses might transit through intermediate
    locations between your client and the location of the target instance.
    z    To execute a statement on a Cloud SQL instance, run:

    $ {command} instance-foo --sql="ALTER TABLE employees RENAME TO personnel;" --database=db1
    )DESCRIPTIONEXAMPLESc                   2    \ rS rSrSr\r\S 5       rS r	Sr
g)
ExecuteSql1   r   c                     U R                  S[        R                  SS9  U R                  SSSS9  U R                  S[        S	S
S9  U R                  SSSSS.S	SSS9  [        R                  " U S5        g)zArgs is called by calliope to gather arguments for this command.

Args:
  parser: An argparse parser that you can use to add arguments that go on
    the command line after this command. Positional arguments are allowed.
instancezCloud SQL instance ID.)	completerhelpz--sqlTzSQL statement(s) to execute. It supports multiple statements as well. When it starts with the character '@', the rest should be a filepath to read the SQL statement(s) from.)requiredr   z--row_limitFz;Maximum number of rows to return. The default is unlimited.)typer   r   z--partial_result_modez@Unspecified mode, effectively the same as `FAIL_PARTIAL_RESULT`.zYThrow an error if the complete result can't be returned. Don't return the partial result.zReturn the partial result and mark the field partial_result to true if the complete result can't be returned. Don't throw an error.)PARTIAL_RESULT_MODE_UNSPECIFIEDFAIL_PARTIAL_RESULTALLOW_PARTIAL_RESULTNzControls how the API should respond when the SQL execution result is incomplete due to size limit or other reasons. The default mode is to throw an error instead of returning the partial result.)choicesr   defaultr   z,Database on which the statement is executed.)add_argumentr
   InstanceCompleterintAddDatabase)parsers    (lib/surface/sql/instances/execute_sql.pyArgsExecuteSql.Args8   s     ))%  
 ;	   J	   *4
 )  4 
6    c                 P   [         R                  " [         R                  5      nUR                  nUR                  n[
        R                  " UR                  5        UR                  R                  UR                  S[        R                  R                  R                  R                  0SS9nUR                  R!                  S5      (       a$  ["        R$                  " UR                  SS 5      nOUR                  nUR&                  (       a0  UR(                  R*                  R-                  UR&                  5      nOSnUR)                  UUR.                  UR0                  USS9nUR2                  R5                  UR7                  UR                  UR                  US	95      $ )
zExecutes a statement on a Cloud SQL instance.

Args:
  args: argparse.Namespace, The arguments that this command was invoked
    with.

Returns:
  A dict object representing the execution result.
projectzsql.instances)params
collection@   NT)sqlStatementdatabaserowLimitpartialResultModeautoIamAuthn)r   r'   executeSqlPayload)r   	SqlClientAPI_VERSION_DEFAULT
sql_clientsql_messagesr   ValidateInstanceNamer   resource_parserParser   VALUEScorer'   	GetOrFailsql
startswithr   ReadFileContentspartial_result_modeExecuteSqlPayload PartialResultModeValueValuesEnumlookup_by_namer-   	row_limit	instancesr   SqlInstancesExecuteSqlRequest)	selfargsclientr4   r5   instance_refr<   r?   req_bodys	            r"   RunExecuteSql.Runs   sg     < <=F""J&&L!!$--0))//:,,1199CCD" 0 L
 xx3""488AB<0cHHc(::[[jj

"
" !--- . H **22!** ((& 	3 	
 r%    N)__name__
__module____qualname____firstlineno____doc__DETAILED_HELPdetailed_helpstaticmethodr#   rK   __static_attributes__rM   r%   r"   r   r   1   s$     6-8 8t+r%   r   N)rR   
__future__r   r   r   googlecloudsdk.api_lib.sqlr   r   googlecloudsdk.callioper	   googlecloudsdk.command_lib.sqlr
   googlecloudsdk.corer   googlecloudsdk.core.utilr   r   r   rS   ReleaseTracksReleaseTrackALPHABETADefaultUniverseOnlyCommandr   rM   r%   r"   <module>rc      s    4 &  ' / / ( 0 * *  D%%++T->->-C-CDk k  Ekr%   