Skip to content

Commit d7300db

Browse files
author
Martin Köditz
authored
Merge pull request #52 from mlazdans/lock_timeout
Add IBASE_LOCK_TIMEOUT transaction option
2 parents 7dc34ae + bd21129 commit d7300db

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.vscode
12
.deps
23
.libs
34
.php-version

interbase.c

+20
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ PHP_MINIT_FUNCTION(ibase)
753753
REGISTER_LONG_CONSTANT("IBASE_REC_NO_VERSION", PHP_IBASE_REC_NO_VERSION, CONST_PERSISTENT);
754754
REGISTER_LONG_CONSTANT("IBASE_NOWAIT", PHP_IBASE_NOWAIT, CONST_PERSISTENT);
755755
REGISTER_LONG_CONSTANT("IBASE_WAIT", PHP_IBASE_WAIT, CONST_PERSISTENT);
756+
REGISTER_LONG_CONSTANT("IBASE_LOCK_TIMEOUT", PHP_IBASE_LOCK_TIMEOUT, CONST_PERSISTENT);
756757

757758
php_ibase_query_minit(INIT_FUNC_ARGS_PASSTHRU);
758759
php_ibase_blobs_minit(INIT_FUNC_ARGS_PASSTHRU);
@@ -1146,6 +1147,7 @@ PHP_FUNCTION(ibase_trans)
11461147

11471148
if (argn > 0) {
11481149
zend_long trans_argl = 0;
1150+
zend_long trans_timeout = 0;
11491151
char *tpb;
11501152
ISC_TEB *teb;
11511153
zval *args = NULL;
@@ -1217,6 +1219,24 @@ PHP_FUNCTION(ibase_trans)
12171219
last_tpb[tpb_len++] = isc_tpb_nowait;
12181220
} else if (PHP_IBASE_WAIT == (trans_argl & PHP_IBASE_WAIT)) {
12191221
last_tpb[tpb_len++] = isc_tpb_wait;
1222+
if (PHP_IBASE_LOCK_TIMEOUT == (trans_argl & PHP_IBASE_LOCK_TIMEOUT)) {
1223+
if((i + 1 < argn) && (Z_TYPE(args[i + 1]) == IS_LONG)){
1224+
i++;
1225+
convert_to_long_ex(&args[i]);
1226+
trans_timeout = Z_LVAL(args[i]);
1227+
1228+
if (trans_timeout <= 0 || trans_timeout > 0x7FFF) {
1229+
php_error_docref(NULL, E_WARNING, "Invalid timeout parameter");
1230+
} else {
1231+
last_tpb[tpb_len++] = isc_tpb_lock_timeout;
1232+
last_tpb[tpb_len++] = sizeof(ISC_SHORT);
1233+
last_tpb[tpb_len] = (ISC_SHORT)trans_timeout;
1234+
tpb_len += sizeof(ISC_SHORT);
1235+
}
1236+
} else {
1237+
php_error_docref(NULL, E_WARNING, "IBASE_LOCK_TIMEOUT expects next argument to be timeout value");
1238+
}
1239+
}
12201240
}
12211241
}
12221242
}

php_ibase_includes.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ enum php_interbase_option {
129129
PHP_IBASE_CONSISTENCY = 16,
130130
/* transaction lock resolution */
131131
PHP_IBASE_WAIT = 128,
132-
PHP_IBASE_NOWAIT = 256
132+
PHP_IBASE_NOWAIT = 256,
133+
PHP_IBASE_LOCK_TIMEOUT = 512,
133134
};
134135

135136
#define IBG(v) ZEND_MODULE_GLOBALS_ACCESSOR(ibase, v)

0 commit comments

Comments
 (0)