Skip to content

Commit

Permalink
Merge pull request #52 from mlazdans/lock_timeout
Browse files Browse the repository at this point in the history
Add IBASE_LOCK_TIMEOUT transaction option
  • Loading branch information
Martin Köditz authored Oct 8, 2024
2 parents 7dc34ae + bd21129 commit d7300db
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
.deps
.libs
.php-version
Expand Down
20 changes: 20 additions & 0 deletions interbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ PHP_MINIT_FUNCTION(ibase)
REGISTER_LONG_CONSTANT("IBASE_REC_NO_VERSION", PHP_IBASE_REC_NO_VERSION, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("IBASE_NOWAIT", PHP_IBASE_NOWAIT, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("IBASE_WAIT", PHP_IBASE_WAIT, CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("IBASE_LOCK_TIMEOUT", PHP_IBASE_LOCK_TIMEOUT, CONST_PERSISTENT);

php_ibase_query_minit(INIT_FUNC_ARGS_PASSTHRU);
php_ibase_blobs_minit(INIT_FUNC_ARGS_PASSTHRU);
Expand Down Expand Up @@ -1146,6 +1147,7 @@ PHP_FUNCTION(ibase_trans)

if (argn > 0) {
zend_long trans_argl = 0;
zend_long trans_timeout = 0;
char *tpb;
ISC_TEB *teb;
zval *args = NULL;
Expand Down Expand Up @@ -1217,6 +1219,24 @@ PHP_FUNCTION(ibase_trans)
last_tpb[tpb_len++] = isc_tpb_nowait;
} else if (PHP_IBASE_WAIT == (trans_argl & PHP_IBASE_WAIT)) {
last_tpb[tpb_len++] = isc_tpb_wait;
if (PHP_IBASE_LOCK_TIMEOUT == (trans_argl & PHP_IBASE_LOCK_TIMEOUT)) {
if((i + 1 < argn) && (Z_TYPE(args[i + 1]) == IS_LONG)){
i++;
convert_to_long_ex(&args[i]);
trans_timeout = Z_LVAL(args[i]);

if (trans_timeout <= 0 || trans_timeout > 0x7FFF) {
php_error_docref(NULL, E_WARNING, "Invalid timeout parameter");
} else {
last_tpb[tpb_len++] = isc_tpb_lock_timeout;
last_tpb[tpb_len++] = sizeof(ISC_SHORT);
last_tpb[tpb_len] = (ISC_SHORT)trans_timeout;
tpb_len += sizeof(ISC_SHORT);
}
} else {
php_error_docref(NULL, E_WARNING, "IBASE_LOCK_TIMEOUT expects next argument to be timeout value");
}
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion php_ibase_includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ enum php_interbase_option {
PHP_IBASE_CONSISTENCY = 16,
/* transaction lock resolution */
PHP_IBASE_WAIT = 128,
PHP_IBASE_NOWAIT = 256
PHP_IBASE_NOWAIT = 256,
PHP_IBASE_LOCK_TIMEOUT = 512,
};

#define IBG(v) ZEND_MODULE_GLOBALS_ACCESSOR(ibase, v)
Expand Down

0 comments on commit d7300db

Please sign in to comment.