pub fn convert_mysql_placeholders_to_postgresql(sql: &str) -> StringExpand description
Convert MySQL placeholder (?) to PostgreSQL placeholders ($1, $2, $3, …)
This function efficiently converts MySQL-style question mark placeholders to PostgreSQL-style numbered placeholders while respecting SQL string literals and comments.
§Examples
use senax_pgsql_parser::convert_mysql_placeholders_to_postgresql;
let mysql_sql = "SELECT * FROM users WHERE id = ? AND name = ?";
let postgresql_sql = convert_mysql_placeholders_to_postgresql(mysql_sql);
assert_eq!(postgresql_sql, "SELECT * FROM users WHERE id = $1 AND name = $2");
// String literals are preserved
let mysql_sql = "SELECT * FROM users WHERE name = 'user?' AND id = ?";
let postgresql_sql = convert_mysql_placeholders_to_postgresql(mysql_sql);
assert_eq!(postgresql_sql, "SELECT * FROM users WHERE name = 'user?' AND id = $1");