MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / visit_insert

Method visit_insert

lib/sqlalchemy/sql/compiler.py:5908–6297  ·  view source on GitHub ↗
(
        self, insert_stmt, visited_bindparam=None, visiting_cte=None, **kw
    )

Source from the content-addressed store, hash-verified

5906 batchnum += 1
5907
5908 def visit_insert(
5909 self, insert_stmt, visited_bindparam=None, visiting_cte=None, **kw
5910 ):
5911 compile_state = insert_stmt._compile_state_factory(
5912 insert_stmt, self, **kw
5913 )
5914 insert_stmt = compile_state.statement
5915
5916 if visiting_cte is not None:
5917 kw["visiting_cte"] = visiting_cte
5918 toplevel = False
5919 else:
5920 toplevel = not self.stack
5921
5922 if toplevel:
5923 self.isinsert = True
5924 if not self.dml_compile_state:
5925 self.dml_compile_state = compile_state
5926 if not self.compile_state:
5927 self.compile_state = compile_state
5928
5929 self.stack.append(
5930 {
5931 "correlate_froms": set(),
5932 "asfrom_froms": set(),
5933 "selectable": insert_stmt,
5934 }
5935 )
5936
5937 counted_bindparam = 0
5938
5939 # reset any incoming "visited_bindparam" collection
5940 visited_bindparam = None
5941
5942 # for positional, insertmanyvalues needs to know how many
5943 # bound parameters are in the VALUES sequence; there's no simple
5944 # rule because default expressions etc. can have zero or more
5945 # params inside them. After multiple attempts to figure this out,
5946 # this very simplistic "count after" works and is
5947 # likely the least amount of callcounts, though looks clumsy
5948 if self.positional and visiting_cte is None:
5949 # if we are inside a CTE, don't count parameters
5950 # here since they won't be for insertmanyvalues. keep
5951 # visited_bindparam at None so no counting happens.
5952 # see #9173
5953 visited_bindparam = []
5954
5955 crud_params_struct = crud._get_crud_params(
5956 self,
5957 insert_stmt,
5958 compile_state,
5959 toplevel,
5960 visited_bindparam=visited_bindparam,
5961 **kw,
5962 )
5963
5964 if self.positional and visited_bindparam is not None:
5965 counted_bindparam = len(visited_bindparam)

Callers

nothing calls this directly

Calls 14

_generate_prefixesMethod · 0.95
_setup_crud_hintsMethod · 0.95
returning_clauseMethod · 0.95
_render_cte_clauseMethod · 0.95
render_bind_castMethod · 0.95
_InsertManyValuesClass · 0.85
format_tableMethod · 0.80
appendMethod · 0.45
joinMethod · 0.45
processMethod · 0.45

Tested by

no test coverage detected