MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / visit_insert

Method visit_insert

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

Source from the content-addressed store, hash-verified

6114 batchnum += 1
6115
6116 def visit_insert(
6117 self, insert_stmt, visited_bindparam=None, visiting_cte=None, **kw
6118 ):
6119 compile_state = insert_stmt._compile_state_factory(
6120 insert_stmt, self, **kw
6121 )
6122 insert_stmt = compile_state.statement
6123
6124 if visiting_cte is not None:
6125 kw["visiting_cte"] = visiting_cte
6126 toplevel = False
6127 else:
6128 toplevel = not self.stack
6129
6130 if toplevel:
6131 self.isinsert = True
6132 if not self.dml_compile_state:
6133 self.dml_compile_state = compile_state
6134 if not self.compile_state:
6135 self.compile_state = compile_state
6136
6137 self.stack.append(
6138 {
6139 "correlate_froms": set(),
6140 "asfrom_froms": set(),
6141 "selectable": insert_stmt,
6142 }
6143 )
6144
6145 counted_bindparam = 0
6146
6147 # reset any incoming "visited_bindparam" collection
6148 visited_bindparam = None
6149
6150 # for positional, insertmanyvalues needs to know how many
6151 # bound parameters are in the VALUES sequence; there's no simple
6152 # rule because default expressions etc. can have zero or more
6153 # params inside them. After multiple attempts to figure this out,
6154 # this very simplistic "count after" works and is
6155 # likely the least amount of callcounts, though looks clumsy
6156 if self.positional and visiting_cte is None:
6157 # if we are inside a CTE, don't count parameters
6158 # here since they won't be for insertmanyvalues. keep
6159 # visited_bindparam at None so no counting happens.
6160 # see #9173
6161 visited_bindparam = []
6162
6163 crud_params_struct = crud._get_crud_params(
6164 self,
6165 insert_stmt,
6166 compile_state,
6167 toplevel,
6168 visited_bindparam=visited_bindparam,
6169 **kw,
6170 )
6171
6172 if self.positional and visited_bindparam is not None:
6173 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