U kfI@s*ddlmZddlZddlmZddlmZddlmZddlm Z dd l m Z dd l m Z d d lm Z d d lmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZd dlmZGdddejZGdddejZGdddejZdZdS))DecimalN)testing)fixtures)eq_) requirements)Column)Table)Double)Float)Identity)Integer)literal)literal_column)Numeric)select)String) LargeBinary)UUID)Uuidc@sJeZdZdZdZdZeddZddZdd Z d d Z e j d d Z dS) LastrowidTesteachT)Zimplements_get_lastrowidautoincrement_insertc CsTtd|tdtdddtdtdddtd |tdtddd tdtddddS) N autoinc_pkidT primary_keyZtest_needs_autoincrementdata2FZimplicit_returning manual_pkrZ autoincrementr r rrclsmetadatar(T/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/testing/suite/test_insert.py define_tables's&   zLastrowidTest.define_tablescCs(||}t||jjdfdSN some dataexecuterfirstrdialectZdefault_sequence_baseselftableconnrowr(r(r)_assert_round_trip;sz LastrowidTest._assert_round_tripcCs.||jjtdd||jj|dSNr,rr.tablesrinsertdictr6r2 connectionr(r(r)test_autoincrement_on_insertEs  z*LastrowidTest.test_autoincrement_on_insertcCsB||jjtdd}|t|jjjj}t |j |fdSr7 r.r:rr;r<scalarrcrrinserted_primary_keyr2r>rpkr(r(r)test_last_inserted_idKs  z#LastrowidTest.test_last_inserted_idcCsD||jjtdd}|j}|t|jjjj }t ||dSr7) r.r:rr;r< lastrowidrArrBrr)r2r>rErHrFr(r(r)test_native_lastrowid_autoincRs z+LastrowidTest.test_native_lastrowid_autoincN)__name__ __module__ __qualname__ run_deletes __backend__ __requires__ classmethodr*r6r?rGrZdbapi_lastrowidrIr(r(r(r)r s  rc@seZdZdZdZeddZedddgeddd gd d Z e j d d Z e j ddZe jddZe jddZe jddZe jddZe jddZe jddZdS)InsertBehaviorTestrTc Cstd|tdtdddtdtdtd|tdtddd tdtdtd |tdtdddtdtddd td |tdtdddtdtdtd tddtdttdtdtdddS)NrrTrrr r"Fr#no_implicit_returningr!includes_defaultsx)defaulty2)type_r)r r rrrrr%r(r(r)r*`s\      z InsertBehaviorTest.define_tablesstyleplainreturn_defaults executemanyFcCsh|jj}|}|jr|}|rFddiddiddiddiddig}nddi}|||}|jrdtdS)z-test another INSERT issue found during #10453rd1d2d3d4d5N)r:rRr;r\r. returns_rowsAssertionError)r2r>rZr]r3stmtrrEr(r(r)(test_no_results_for_non_returning_inserts z;InsertBehaviorTest.test_no_results_for_non_returning_insertcCsR||jjtdd}|js$t|jr.t|js8t|j rN| dksNtdSr7) r.r:rr;r< _soft_closedrdclosed is_insertrcfetchoner2r>rEr(r(r)test_autoclose_on_inserts    z+InsertBehaviorTest.test_autoclose_on_insertcCsh||jjtdd}|js(t|jr2t|j sInsertBehaviorTest.test_autoclose_on_insert_implicit_returningcCs`||jj}|jst|jr&t||jj|jjj j dk}t t | ddS)Nrr.r:rr;rgrdrhrwhererBrrlenallrkr(r(r)test_empty_inserts   z$InsertBehaviorTest.test_empty_insertcCsh||jjiiig}|js$t|jr.t||jj|jjj j dk}t t | ddS)Nr rorkr(r(r)test_empty_insert_multiples   z-InsertBehaviorTest.test_empty_insert_multiplec Cs|jj}|jj}||tdddtdddtdddg||dt|jj  |jj ddg}t |j d |t|jj |jj }t |d d gdS) Nrdata1rrrdata2r data3r8Nrwrx)r:r"rr.r;r< from_selectrrBrrpin_rrCorder_byfetchallr2r>Z src_tableZ dest_tableresultr(r(r)test_insert_from_select_autoincs,      z2InsertBehaviorTest.test_insert_from_select_autoincc Cs||jj}|jj}||dt|jj |jj ddg}t |j d|t|jj |jj}t |gdS)Nr8rwrxry)r:r"rr.r;r|rrBrrpr}rrCr~rrr(r(r)'test_insert_from_select_autoinc_no_rowss  z:InsertBehaviorTest.test_insert_from_select_autoinc_no_rowsc Cs|jj}||tdddtdddtdddg||dt|jj d|jj  |jj ddgt |t|jj |jj d d d d d gdS) Nrrurvrrwr rxrU)rurzr{)r:r"r.r;r<inliner|rrBrrrpr}rr~rr2r>r3r(r(r)test_insert_from_selects,       z*InsertBehaviorTest.test_insert_from_selectc Cs|jj}||tdddtdddtdddg||dt|jj d|jj  |jj ddgt |t||jj |jj d d d d d gdS)Nrrurvrrwr rxrU)rrurU)rrwrUr)rwrUr)r rxrUr)rxrUr)r:rSr.r;r<rr|rrBrrrpr}rr~rrr(r(r)%test_insert_from_select_with_defaults:s6      z8InsertBehaviorTest.test_insert_from_select_with_defaultsN)rJrKrLrMrNrPr*r variationrfrrrlinsert_returningrnZ empty_insertsrsZempty_inserts_executemanyrtZinsert_from_selectrrrrr(r(r(r)rQ\s. '        rQc @seZdZdZdZdZddZeddZe j dd Z d d Z d d Z ddZe jddZejeddfedddejjfeddfedddejjfeddddddejjfeddddeddfddedddgedddgdd Zejd!edd"efd#eddd$eefd%edd"eejj fd&eddd$eeejj fd'e!eejj fd(e"d)fd*e"d+fd,d-d. edddgedddgejj#d/d0Z$d1S)2 ReturningTestr)rrTcCs(||}t||jjdfdSr+r-r1r(r(r)r6dsz ReturningTest._assert_round_tripc Cs(td|tdtdddtdtddS)NrrTrrr r$r%r(r(r)r*ns zReturningTest.define_tablescCsT|jj}|||jjtdd}|d}| t |jj}t ||dSNr,r8r r:rr.r; returningrBrr<r/rArrr2r>r3rErFZ fetched_pkr(r(r)%test_explicit_returning_pk_autocommitys z3ReturningTest.test_explicit_returning_pk_autocommitcCsT|jj}|||jjtdd}|d}| t |jj}t ||dSrrrr(r(r)(test_explicit_returning_pk_no_autocommits z6ReturningTest.test_explicit_returning_pk_no_autocommitcCs.||jjtdd||jj|dSr7r9r=r(r(r)/test_autoincrement_on_insert_implicit_returnings  z=ReturningTest.test_autoincrement_on_insert_implicit_returningcCsB||jjtdd}|t|jjjj}t |j |fdSr7r@rDr(r(r)(test_last_inserted_id_implicit_returnings  z6ReturningTest.test_last_inserted_id_implicit_returningc Csp||jj|jjjjddiddiddiddiddig}|}|t|jjjj}t ||dS)Nrr^r_r`rarb) r.r:rr;rrBrrrrr)r2r>rEZrallZpksr(r(r)test_insertmanyvalues_returnings   z-ReturningTest.test_insertmanyvalues_returninggxXM|Z!@5g_Q!@r F) precisionscaleZ asdecimalz 8.5514716ztype_,value,do_rounding)argnamessort_by_parameter_order multiple_rowsc std|tdttddtd|}||||j|jj |jj t |d|rhfddt d Dndi} |rt d d } n t d d } |rt d d| Dfdd| Dt dd|t|jj Dtdhn:t t| fdd| Dt t|t|jj hdS)zvtest #9701. this tests insertmanyvalues as well as decimal / floating point RETURNING types Zf_trTrvaluercsg|] }diqSrr(.0irr(r) sz6ReturningTest.test_insert_w_floats.. r rcSsh|]\}}|t|dfqSrUround)rid_val_r(r(r) sz5ReturningTest.test_insert_w_floats..csh|]}|tdfqSrrrrrr(r)rscSsh|]}t|dqSrr)rrr(r(r)r srUcsh|] }|fqSr(r(rrr(r)rsN)r r rrcreater.r;rrBrrboolrangerscalarsrrset) r2r>r'rrYrZ do_roundingrtri_ranger(rr)test_insert_w_floatssN/      z"ReturningTest.test_insert_w_floatsZnon_native_uuid) native_uuidZnon_native_uuid_str)Zas_uuidrZgeneric_native_uuidZgeneric_native_uuid_strrZ LargeBinary1sthis is binaryZ LargeBinary2s7z type_,valueZiaa)rrc std|tdttddtd|}||||j|jj |jj t |d|rhfddt d Dndi}|rt d d } n t d d } t t|fd d| Dt t|t|jj hdS)atest #9739, #9808 (similar to #9701). this tests insertmanyvalues in conjunction with various datatypes. These tests are particularly for the asyncpg driver which needs most types to be explicitly cast for the new IMV format Zd_trTrrrcsg|] }diqSrr(rrr(r)r`sz>ReturningTest.test_imv_returning_datatypes..rrrrcsh|] }|fqSr(r(rrr(r)rmsz=ReturningTest.test_imv_returning_datatypes..N)r r rrrr.r;rrBrrrrrrrr) r2r>r'rrYrrrrrr(rr)test_imv_returning_datatypess85    z*ReturningTest.test_imv_returning_datatypesN)%rJrKrLZrun_create_tablesrOrNr6rPr*rZfetch_rows_post_commitrrrrZinsert_executemany_returningrr combinationsr requiresZ-float_or_double_precision_behaves_genericallyr rZliteral_float_coercionrrrruuiduuid4strZuuid_data_typerrrrr(r(r(r)r_s         O     !r)rrQr)decimalrrrrZ assertionsrconfigrZschemar r r r rrrrrrrtypesrrrZ TablesTestrrQr__all__r(r(r(r) s6                   <