| Home | Libraries | People | FAQ | More

##### format_sql (1 of 2 overloads)

(EXPERIMENTAL) Composes a SQL query client-side.

###### Synopsis

Defined in header `<boost/mysql/format_sql.hpp>`

    template<
        class... Formattable>
    std::string
    format_sql(
        const format_options& opts,
        constant_string_view format_str,
        const Formattable&... args);

###### Description

Parses `format_str` as a format string, substituting replacement fields (like `{}`, `{1}` or `{name}`) by formatted arguments, extracted from `args`. `opts` is using to parse the string and format string arguments.

Formatting is performed as if `format_context::append_raw` and `format_context::append_value` were called on a context created by this function.

###### Exception safety

Strong guarantee. Memory allocations may throw. `boost::system::system_error` is thrown if an error is found while formatting. See below for more info.

###### Errors

- `client_errc::invalid_encoding` if `args` contains a string with byte sequences that can't be decoded with the current character set.
- `client_errc::unformattable_value` if `args` contains a floating-point value that is NaN or infinity.
- Any other error generated by user-defined `formatter` specializations.
- `client_errc::format_string_invalid_syntax` if `format_str` can't be parsed as a format string.
- `client_errc::format_string_invalid_encoding` if `format_str` contains byte byte sequences that can't be decoded with the current character set.
- `client_errc::format_string_manual_auto_mix` if `format_str` contains a mix of automatic (`{}`) and manual indexed (`{1}`) replacement fields.
- `client_errc::format_arg_not_found` if an argument referenced by `format_str` isn't present in `args` (there aren't enough arguments or a named argument is not found).

Convenience header `<boost/mysql.hpp>`