Convert mSQL C Source Safely with msql2mysql
You will finish with a converted copy of an mSQL C program, a preserved original, and a quick way to review the API-name changes. The command rewrites the file you give it, so the backup is part of the procedure, not an optional precaution.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about ten minutes for a small source file, plus however long you need to review and compile the result. You need a shell, a C source file using the mSQL API, and the mariadb-client package. The examples below use the installed MariaDB 10.11.14 client utilities on Ubuntu 24.04. Check your own package version before relying on exact implementation details.
1. Check the installed command
First confirm that the command comes from the expected package. This is an ordinary read-only check and does not need sudo:
$ command -v msql2mysql
/usr/bin/msql2mysql
$ dpkg-query -W -f='${Package} ${Version}\n' mariadb-client
mariadb-client 1:10.11.14-0ubuntu0.24.04.1
The local manpage shows the syntax as msql2mysql C-source-file .... It documents file operands, not a dry-run or output-file option. Treat an invocation as a change to every named source file.
Checkpoint: you have confirmed the executable path and package version, and you have not changed any source yet.
2. Make a recoverable copy
Choose the source file you intend to convert. Replace /path/to/client-prog.c with a real path, then create a separate original beside it:
$ cp -- /path/to/client-prog.c /path/to/client-prog.c.orig
$ cmp -- /path/to/client-prog.c /path/to/client-prog.c.orig
A successful cmp prints nothing and returns status 0. If it reports a difference, stop and decide which file is the trusted original before continuing.
This is the destructive boundary: the next command edits the working source in place. Do not run it against the only copy of a valuable program. If conversion goes wrong, restore the backup with:
$ cp -- /path/to/client-prog.c.orig /path/to/client-prog.c
That restore overwrites the converted working file. Check the two paths carefully before pressing Enter.
3. Convert the source file
Run the command with the source path as its operand. Do not add --: this installed command passes its operands to the underlying replacement utility, and a literal -- is treated as a file name rather than as a documented option separator.
$ msql2mysql /path/to/client-prog.c
/path/to/client-prog.c converted
The message identifies the file that was changed. The utility converts mSQL C API function calls to their MySQL equivalents and also changes the mSQL header name in the tested MariaDB 10.11 installation. For example, a small test containing msql_query, msqlFetchRow and msqlStoreResult was rewritten to use mysql_query, mysql_fetch_row and mysql_store_result, with m_result changed to MYSQL_RES.
The documented synopsis accepts one or more C source files, so several files can be supplied, but each named file is still changed in place. Keep the backup step for every file:
$ cp -- client-a.c client-a.c.orig
$ cp -- client-b.c client-b.c.orig
$ msql2mysql client-a.c client-b.c
client-a.c converted
client-b.c converted
4. Review the rewrite before compiling
Do not treat a conversion message as proof that the program is ready. Compare the converted file with its backup and inspect the full diff:
$ diff -u -- client-prog.c.orig client-prog.c
--- client-prog.c.orig
+++ client-prog.c
@@
-#include <msql.h>
+#include <mysql.h>
@@
- msqlFetchRow(result);
+ mysql_fetch_row(result);
Your diff will differ. Look for calls whose surrounding logic needs more than a name change, including result handling, connection setup, error handling and header or library choices. The utility performs substitutions; it does not understand your program's control flow or prove that the two APIs have identical semantics for every call.
Checkpoint: the diff contains only changes you understand, and the original file remains available at client-prog.c.orig.
5. Compile or run the project's checks
Use the project's normal build command after reviewing the diff. A generic compile command is only an example because include paths, libraries and compiler flags belong to the project:
$ cc -Wall -Wextra -I/path/to/mysql/include -c client-prog.c -o client-prog.o
Do not copy that command unchanged unless those paths match your installation and the source is otherwise ready to compile. A compiler error is useful feedback about remaining API or build changes; it is not a reason to edit the backup.
6. Recover or repeat safely
If the review or build shows that the rewrite is unsuitable, restore the original and verify the recovery:
$ cp -- client-prog.c.orig client-prog.c
$ cmp -- client-prog.c client-prog.c.orig
To try again, make a fresh backup of the restored source, then run msql2mysql once more. Do not use a converted file as the only input for repeated experiments, because the substitutions are not a replacement for a source-control history or a clean baseline.
For a cleaner workflow, perform the conversion in a temporary working tree or a new branch, review the diff there, and copy only reviewed changes into the real project. No elevated privileges are required unless your source directory itself is protected. If a command asks for sudo merely because conversion failed, stop and diagnose the file path and permissions first.
Done means
- The installed
msql2mysqlpath andmariadb-clientversion are known. - Every source file passed to the command has a separate original copy.
- The conversion message and a file diff confirm what changed.
- The converted code has passed the project's compiler or test checks.
- You know how to restore the original without touching unrelated files.