Repository navigation
MySQL_ExecuteBatch
Send the rows of a batch after the queries sent before it, and forget it, also when it is refused.
Inside the public, MySQL_GetAffectedRows reads the rows of all of them. A batch with no rows is not sent to the server. Its public is still called, in order with the rest, and without one it is only forgotten.
native bool:MySQL_ExecuteBatch(Batch:batch, const callback[] = "", context = 0);| Parameter | Description | Default |
|---|---|---|
Batch:batch |
The batch. | |
const callback[] |
Public to call when it is done, or none. | "" |
context |
Value the public receives. | 0 |
-
truewhen it was sent. -
falsewhen the batch or its statement does not exist, or a limit of the connection refused it, and the public is not called.
On MariaDB 10.2 or later the rows go to the server as arrays in one command, which skips building and parsing a long query. Rows that do not fit in max_allowed_packet are split into several commands, run in a transaction so the batch applies all its rows or none, unless the script opened a transaction of its own. On other servers each row runs in turn, in a transaction too.
A batch with no rows and no public is only forgotten. One with a public calls it in order with the rest. See Prepared statements.
new Statement:gSaveScore;
forward OnScoresSaved(rows);
stock SaveScores(const ids[]) {
new const
Batch:batch = MySQL_CreateBatch(gSaveScore)
;
for (new i; i != MAX_PLAYERS; ++i) {
if (IsPlayerConnected(i)) {
MySQL_AddRow(batch, GetPlayerScore(i), ids[i]);
}
}
MySQL_ExecuteBatch(batch, "OnScoresSaved", MySQL_GetBatchRows(batch));
}
public OnScoresSaved(rows) {
if (MySQL_GetErrno() != 0) {
printf("%i scores were not saved: error %i.", rows, MySQL_GetErrno());
}
return 1;
}- MySQL_AddRow: Add a row of values to a batch. The values are copied at once.
-
MySQL_RunBatch: Send the rows of a batch and wait for them, as
MySQL_Rundoes, and forget it. - MySQL_Prepare: Prepare a statement, with a specifier for each value.
MySQL 0.2.0 · Repository · Releases · MIT License
Guides
- Installation
- Configuration
- Queries
- Results
- JSON cells
- Prepared statements
- Passwords
- Errors
- TLS
- Coming from R41
- Performance
Reference
Functions