MCPcopy Index your code
hub / github.com/dbcli/mycli / format_sqlresult

Method format_sqlresult

mycli/output.py:190–279  ·  view source on GitHub ↗
(
        self,
        result,
        is_expanded: bool = False,
        is_redirected: bool = False,
        null_string: str | None = None,
        numeric_alignment: str = 'right',
        binary_display: str | None = None,
        max_width: int | None = None,
        is_warnings_style: bool = False,
    )

Source from the content-addressed store, hash-verified

188 special.disable_pager()
189
190 def format_sqlresult(
191 self,
192 result,
193 is_expanded: bool = False,
194 is_redirected: bool = False,
195 null_string: str | None = None,
196 numeric_alignment: str = 'right',
197 binary_display: str | None = None,
198 max_width: int | None = None,
199 is_warnings_style: bool = False,
200 ) -> itertools.chain[str]:
201 if is_redirected:
202 use_formatter = self.redirect_formatter
203 else:
204 use_formatter = self.main_formatter
205
206 is_expanded = is_expanded or use_formatter.format_name == "vertical"
207 output: itertools.chain[str] = itertools.chain()
208
209 output_kwargs = {
210 "dialect": "unix",
211 "disable_numparse": True,
212 "preserve_whitespace": True,
213 "style": self.helpers_warnings_style if is_warnings_style else self.helpers_style,
214 }
215 default_kwargs = use_formatter._output_formats[use_formatter.format_name].formatter_args
216
217 if null_string is not None and default_kwargs.get('missing_value') == DEFAULT_MISSING_VALUE:
218 output_kwargs['missing_value'] = null_string
219
220 if use_formatter.format_name not in sql_format.supported_formats and binary_display != 'utf8':
221 output_kwargs["preprocessors"] = (preprocessors.convert_to_undecoded_string,)
222
223 if result.preamble:
224 output = itertools.chain(output, [result.preamble])
225
226 if result.header or (result.rows and result.preamble):
227 column_types = None
228 colalign = None
229 if isinstance(result.rows, Cursor):
230
231 def get_col_type(col) -> type:
232 col_type = FIELD_TYPES.get(col[1], str)
233 return col_type if type(col_type) is type else str
234
235 if result.rows.rowcount > 0:
236 column_types = [get_col_type(tup) for tup in result.rows.description]
237 colalign = [numeric_alignment if x in (int, float, Decimal) else 'left' for x in column_types]
238 else:
239 column_types, colalign = [], []
240
241 if max_width is not None and isinstance(result.rows, Cursor):
242 result_rows = list(result.rows)
243 else:
244 result_rows = result.rows
245
246 formatted = use_formatter.format_output(
247 result_rows,

Calls 2

format_outputMethod · 0.80
getMethod · 0.45