1mysql_autocommit(3)           MariaDB Connector/C          mysql_autocommit(3)
2
3
4
5   Name
6       mysql_autocommit - Toggles autocommit mode
7
8   Synopsis
9              #include <mysql.h>
10
11              my_bool mysql_autocommit(MYSQL * mysql, my_bool auto_mode);
12
13   Description
14       Toggles  autocommit mode on or off for the current database connection.
15       Autocommit mode will be set if mode=1 or unset if mode=0.
16
17   Parameters:
18       • mysql is a connection identifier, which was previously  allocated  by
19         mysql_init(3) and connected by mysql_real_connect(3).
20
21       • auto_mode - whether to turn autocommit on or not.
22
23   Notes
24       • Autocommit mode only affects operations on transactional table types.
25         To determine the current state of autocommit mode use the SQL command
26         SELECT @@autocommit or check the server status (see example below).
27
28       • Be  aware:  the [mysql_rollback()}(mysql_rollback() function will not
29         work if autocommit mode is switched on.
30
31   Examples
32   SQL
33              # Turn of autocmmit
34              SET AUTOCOMMIT=0;
35
36              # Retrieve autocommit
37              SELECT @@autocommit;
38              +--------------+
39              | @@autocommit |
40              +--------------+
41              |            0 |
42              +--------------+
43
44   MariaDB Connector/C
45              static int test_autocommit(MYSQL *mysql)
46              {
47                int rc;
48                unsigned int server_status;
49
50                /* Turn autocommit off */
51                rc= mysql_autocommit(mysql, 0);
52                if (rc)
53                  return rc; /* Error */
54
55                /* If autocommit = 0 succeeded, the last OK packet updated the server status */
56                rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status);
57                if (rc)
58                  return rc; /* Error */
59
60                if (server_status & SERVER_STATUS_AUTOCOMMIT)
61                {
62                  printf("Error: autocommit is on\n");
63                  return 1;
64                }
65                printf("OK: autocommit is off\n");
66                return 0;
67              }
68
69
70
71Version 3.3.1                                              mysql_autocommit(3)
Impressum