mysql_autocommit(3)
β¨ Name β¨
mysql_autocommit β the little function that toggles autocommit mode on and off, and honestly? it's giving "small but mighty" π
. This is the MariaDB Connector/C page, bestie, so pull up a chair.
π Synopsis π
#include <mysql.h>
my_bool mysql_autocommit(MYSQL * mysql, my_bool auto_mode);
π¦ Description π¦
Okay so literally what this does: it toggles autocommit mode on or off for the current database connection. That's it, that's the whole vibe.
Autocommit mode gets set if mode=1, and unset if mode=0. No in-between, no maybe, it's a binary situation and we respect that. π«Ά
π Parameters π
mysqlβ your connection identifier, the main character here. It was previously allocated bymysql_init(3)and connected bymysql_real_connect(3), so don't just roll up with a random pointer, bestie, it needs to be a real one. π₯auto_modeβ whether to turn autocommit on or not. That's literally the whole job description.
πΈ Notes πΈ
- Autocommit mode only affects operations on transactional table types. If you wanna know the current state of autocommit mode, use the SQL command
SELECT @@autocommit, or check the server status (there's an example below, iykyk π). - > Be aware: the
[mysql_rollback()}(mysql_rollback()function will not work if autocommit mode is switched on. Not a drill. Not a vibe. It just won't work. π
π Examples π
π SQL
# Turn off autocommit
SET AUTOCOMMIT=0;
# Retrieve autocommit
SELECT @@autocommit;
+--------------+
| @@autocommit |
+--------------+
| 0 |
+--------------+
Look at that 0. Immaculate. β¨
π MariaDB Connector/C
static int test_autocommit(MYSQL *mysql)
{
int rc;
unsigned int server_status;
/* Turn autocommit off */
rc= mysql_autocommit(mysql, 0);
if (rc)
return rc; /* Error */
/* If autocommit = 0 succeeded, the last OK packet updated the server status */
rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status);
if (rc)
return rc; /* Error */
if (server_status & SERVER_STATUS_AUTOCOMMIT)
{
printf("Error: autocommit is on\n");
return 1;
}
printf("OK: autocommit is off\n");
return 0;
}
Not us reading the code and being like "the way this checks server_status & SERVER_STATUS_AUTOCOMMIT and prints OK: autocommit is off"... we love a function that actually verifies its own work. ππ
Fr fr: keep every flag, every parameter and every caveat in your head, because the manpage said it once and we are not repeating ourselves. Periodt.
Version 3.4 of the MariaDB Connector/C manual, bestie β that's the source and the version, and this page is mysql_autocommit(3), so go forth and toggle responsibly. Mwah, love u, bye! ππ
π¦ππ
π¦ where this page comes from
- alpine 3.22: mariadb-doc 11.4.13-r0 Β· GPL-2.0-or-later
- alpine 3.23: mariadb-doc 11.4.13-r0 Β· GPL-2.0-or-later
- alpine 3.24: mariadb-doc 11.8.9-r0 Β· GPL-2.0-only
- arch rolling: mariadb 13.0.2-2 Β· GPL-2.0-only
- arch rolling: mariadb-lts 12.3.3-2 Β· GPL-2.0-only
- centos-stream 10: mariadb-connector-c-doc 3.4.4-2.el10 Β· LGPL-2.1-or-later
- debian trixie: libmariadb-dev 1:11.8.6-0+deb13u1 Β· GPL-2.0-only
- fedora 43: mariadb-connector-c-doc 3.4.5-2.fc43 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01
- fedora 43: mariadb-connector-c-doc 3.4.9-2.fc43 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01 AND LicenseRef-Fedora-Public-Domain
- fedora 44: mariadb-connector-c-doc 3.4.8-3.fc44 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01
- fedora 44: mariadb-connector-c-doc 3.4.9-2.fc44 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01 AND LicenseRef-Fedora-Public-Domain
- nixpkgs unstable: mariadb-server 11.8.8
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- ubuntu questing: libmariadb-dev 1:11.8.3-1build1
- ubuntu resolute: libmariadb-dev 1:11.8.6-5 Β· GPL-2.0-only
- ubuntu resolute: libmariadb-dev 1:11.8.6-5ubuntu0.1 Β· GPL-2.0-only
- ubuntu stonking: libmariadb-dev 1:11.8.9+ds-4ubuntu2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms