L iIrddlmZddlZddlmZddlmZddlmZddlm 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 dlmZGddej4ZGddej4ZGddej4ZdZy))DecimalN)testing)fixtures)eq_) requirements)Column)Table)Double)Float)Identity)Integer)literal)literal_column)Numeric)select)String) LargeBinary)UUID)Uuidc^eZdZdZdZdZedZdZdZ dZ e jdZ y ) LastrowidTesteachT)implements_get_lastrowidautoincrement_insertc td|tdtddtdtddtd |tdtdd tdtddy) N autoinc_pkidT primary_keytest_needs_autoincrementdata2Fimplicit_returning manual_pkr" autoincrementr r rrclsmetadatas j/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/testing/suite/test_insert.py define_tableszLastrowidTest.define_tables'sc   g4$  66": &$     4d% H 66": &$  c|j|jj}t||jj dfyN some dataexecuterfirstrdialectdefault_sequence_baseselftableconnrows r/_assert_round_tripz LastrowidTest._assert_round_trip;?ll5<<>*002  22  r1c|j|jjjt d|j |jj|yNr4r$r6tablesrinsertdictr?r; connections r/test_autoincrement_on_insertz*LastrowidTest.test_autoincrement_on_insertEI KK " " ) ) +T{-C   6 6 Cr1c2|j|jjjt d}|j t |jjjj}t|j|fyrB r6rErrFrGscalarrcr rinserted_primary_keyr;rIrpks r/test_last_inserted_idz#LastrowidTest.test_last_inserted_idKn    KK " " ) ) +T{-C   vdkk&<&<&>&>&A&AB C A " "RE*r1c4|j|jjjt d}|j }|j t|jjjj}t||yrB) r6rErrFrG lastrowidrNrrOr r)r;rIrRrWrSs r/test_native_lastrowid_autoincz+LastrowidTest.test_native_lastrowid_autoincRso    KK " " ) ) +T{-C KK   vdkk&<&<&>&>&A&AB C Irr1N)__name__ __module__ __qualname__ run_deletes __backend__ __requires__ classmethodr0r?rJrTr dbapi_lastrowidrXr1r/rr sMKKEL  & D +!!"r1rceZdZdZdZedZejdddgejdddgd Z e jd Z e jd Ze jd Ze j"d Ze j&dZe j&dZe j&dZe j&dZy)InsertBehaviorTestrTctd|tdtddtdtdtd|tdtdd tdtdtd |tdtddtdtdd td |tdtddtdtdtd tdtdtt dtt dzy)Nrr Tr!r$r%r(Fr)no_implicit_returningr&includes_defaultsx)defaulty2)type_r)r r rrrrr,s r/r0z InsertBehaviorTest.define_tables`s   g4$  66": &      4d% H 66": &   #  g4$  66": &$     g4$  66": & 3 + &s':WQZG  r1styleplainreturn_defaults executemanyFc|jj}|j}|jr|j}|rddiddiddiddiddig}nddi}|j ||}|j rJy)z-test another INSERT issue found during #10453r$d1d2d3d4d5N)rErerFror6 returns_rows)r;rIrmrpr<stmtr$rRs r/(test_no_results_for_non_returning_insertz;InsertBehaviorTest.test_no_results_for_non_returning_inserts 11||~  '')D  DD>D   tT *>>!!>r1c|j|jjjt d}|j sJ|j rJ|jsJ|jr|jJyyrB) r6rErrFrG _soft_closedclosed is_insertrwfetchoner;rIrRs r/test_autoclose_on_insertz+InsertBehaviorTest.test_autoclose_on_insertst    KK " " ) ) +T{-C ~~~88|{{{>>QZZ\%999%9>r1cv|j|jjjj t d}|j sJ|jrJ|jsJ|jsJt|jdt|jdgy)Nr4rCr ) r6rErrFrorGr{r|r}rwrr~keysrs r/+test_autoclose_on_insert_implicit_returningz>InsertBehaviorTest.test_autoclose_on_insert_implicit_returnings    KK " " ) ) + ; ; = k "  ~~~88|{{{ ~~~ AJJL$ AFFHtfr1c|j|jjj}|jsJ|j rJ|j|jjj j|jjjjdk7}tt|jdy)Nr r6rErrFr{r|rwhererOr rlenallrs r/test_empty_insertz$InsertBehaviorTest.test_empty_inserts   t{{55<<> ?~~~88|    KK " " ) ) + 1 1 &&((++t3   CL!r1c|j|jjjiiig}|jsJ|j rJ|j|jjj j|jjjjdk7}tt|jdy)Nr rrs r/test_empty_insert_multiplez-InsertBehaviorTest.test_empty_insert_multiples   t{{55<<>R M~~~88|    KK " " ) ) + 1 1 &&((++t3   CL!r1c |jj}|jj}|j|j t ddt ddt ddg|j|j j dt|jjj|jjjddg}t|jd |jt|jjj|jj}t|jd d gy) Nrdata1r r$rdata2r data3rCNrr)rEr(rr6rFrG from_selectrrOr$rin_rrPorder_byfetchallr;rI src_table dest_tableresults r/test_insert_from_select_autoincz2InsertBehaviorTest.test_insert_from_select_autoincs$KK)) [[++     (((  ##     + +y{{''(..KK$$(('7);<   F ' '1## :<<$$ % . .z||/@/@ A  FOO  J78r1c ^|jj}|jj}|j|j j dt |jjj|jjjddg}t|jd|jt |jjj|jj}t|jgy)NrCrrr)rEr(rr6rFrrrOr$rrrrPrrrs r/'test_insert_from_select_autoinc_no_rowsz:InsertBehaviorTest.test_insert_from_select_autoinc_no_rowssKK)) [[++ ##     + +y{{''(..KK$$(('7);<   F ' '1## :<<$$ % . .z||/@/@ A  FOO r"r1c |jj}|j|jt ddt ddt ddg|j|jj j dt|jjdz|jjj|jjjddgt|jt|jjj|jjjgd y) Nrrrrrr rrh))rrrrr)rEr(r6rFrGinlinerrrOr r$rrrrrr;rIr<s r/test_insert_from_selectz*InsertBehaviorTest.test_insert_from_selects %% LLN(((    LLN VX [uwwzzA~uww||4::GGLL$$gw%78    uww||$--eggll; hj H  r1c |jj}|j|jt ddt ddt ddg|j|jj j dt|jjdz|jjj|jjjddgt|jt|j|jj|jjjgd y) Nrrrrrr rrh))rrrh)rrrhr)rrhr)r rrhr)rrhr)rErfr6rFrGrrrrOr r$rrrrrrs r/%test_insert_from_select_with_defaultsz8InsertBehaviorTest.test_insert_from_select_with_defaults:s -- LLN(((    LLN VX [uwwzzA~uww||4::GGLL$$gw%78    u &&uww||UWWZZ@ hj  r1N)rYrZr[r\r]r_r0r variationryr rrinsert_returningr empty_insertsrempty_inserts_executemanyrinsert_from_selectrrrrrar1r/rcrc\s3KK% % NWw*; <=W}tUm4"5>"2&& :' :""#6   ++ , $$9%98$$#%#($$ % :$$! %! r1rcc eZdZdZdZdZdZedZe jdZ dZ dZ d Ze jd Zej$ed dfed d dej(j*fed dfedd dej(j*fedddd dej(j0fedddeddfdej4dddgej4dddgdZej$dedej<fdeddeej<fdedej<ej(j@fdeddeej<ej(j@fde!ej<ej(j@fd e"d!fd"e"d#fd$d%& ej4dddgej4dddgej(jFd'Z$y()) ReturningTestr)rrTc|j|jj}t||jj dfyr3r5r:s r/r?z ReturningTest._assert_round_tripdr@r1c htd|tdtddtdtdy)Nrr Tr!r$r%r+r,s r/r0zReturningTest.define_tablesns1   g4$  66": &  r1cd|jj}|j|jj |j j td}|jd}|jt|j j }t||yNr4rCr rErr6rF returningrOr rGr7rNrrr;rIr<rRrS fetched_pks r/%test_explicit_returning_pk_autocommitz3ReturningTest.test_explicit_returning_pk_autocommitys| &&    LLN $ $UWWZZ 0$K2H WWYq\&&veggjj'9:  Jr1cd|jj}|j|jj |j j td}|jd}|jt|j j }t||yrrrs r/(test_explicit_returning_pk_no_autocommitz6ReturningTest.test_explicit_returning_pk_no_autocommits| &&    LLN $ $UWWZZ 0$K2H WWYq\&&veggjj'9:  Jr1c|j|jjjt d|j |jj|yrBrDrHs r//test_autoincrement_on_insert_implicit_returningz=ReturningTest.test_autoincrement_on_insert_implicit_returningrKr1c2|j|jjjt d}|j t |jjjj}t|j|fyrBrMrQs r/(test_last_inserted_id_implicit_returningz6ReturningTest.test_last_inserted_id_implicit_returningrUr1c |j|jjjj |jjj j ddiddiddiddiddig}|j}|jt|jjj j }t||jy)Nr$rrrsrtrurv) r6rErrFrrOr rrr)r;rIrRrallpkss r/test_insertmanyvalues_returningz-ReturningTest.test_insertmanyvalues_returnings    KK " " ) ) + 5 5 &&((++    uuw   (>(>(@(@(C(C!DE D#'')r1gxXM|Z!@5g_Q!@r F) precisionscale asdecimalz 8.5514716ztype_,value,do_rounding)argnamessort_by_parameter_order multiple_rowsc  td|tdttdtd|}|j ||j |j j|jj|jjt||rtdD cgc]} d|ic} nd|i} |r tdd } n tdd } |rt| D chc]\} } | t| d fc} } | D chc]} | t|d fc} t|jt!|jjD chc]} t| d c} t|d hy tt#| | D chc]} | |fc} tt#|jt!|jj|hy cc} wcc} } wcc} wcc} wcc} w) zvtest #9701. this tests insertmanyvalues as well as decimal / floating point RETURNING types f_tr Tr"valuer r rrhN)r r rrcreater6rFrrOr rboolrangerroundscalarsrset)r;rIr.rrlr do_roundingrtiri_rangeid_val_s r/test_insert_w_floatsz"ReturningTest.test_insert_w_floatss^    4(*$ ? 7E "  ## HHJ  (,-D(E ! !,195a'5!5u%   ArlGAqkG  8>?93#uT1~&?3:;C#uUA';  !+ 2 26!##))3D E$Nua!   F )01##u1  J&&vaccii'89: M6*@;2s/ G+ ,G0 G6 G; H non_native_uuid) native_uuidnon_native_uuid_str)as_uuidrgeneric_native_uuidgeneric_native_uuid_strr LargeBinary1sthis is binary LargeBinary2s7z type_,valueiaa)rrc td|tdttdtd|}|j ||j |j j|jj|jjt||rtdDcgc]}d|ic}nd|i} |r tdd } n tdd } tt| | D chc]} | |fc} tt|jt!|jj|hy cc}wcc} w) 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 d_tr TrrrrrrrN)r r rrrr6rFrrOr rrrrrrr) r;rIr.rrlrrrrrrrs r/test_imv_returning_datatypesz*ReturningTest.test_imv_returning_datatypess j    4(*$ ? 7E "   ## HHJ  (,-D(E ! !,195a'5!5u%   ArlGAqkG K%, -cc5\ -  ""6!##))#45 6 G !6 .s / E 3 E N)%rYrZr[run_create_tablesr^r]r?r_r0r fetch_rows_post_commitrrrrinsert_executemany_returningrr combinationsr requires-float_or_double_precision_behaves_genericallyrrliteral_float_coercionrrrruuiduuid4struuid_data_typerrrrrar1r/rr_s=LK   (()D +../&W 9d# 2J      J J  &$ !H      J J   be <      3 3   bd ; K  +58W04-@Wu 6M7A9rs ! 9H''9x@ ,,@ FT H''T n Cr1